Skip to content

Commit

Permalink
Another fix, which is not yet the most efficient way.
Browse files Browse the repository at this point in the history
  • Loading branch information
joka921 committed Sep 16, 2021
1 parent 2d6eb3e commit a393a81
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
49 changes: 27 additions & 22 deletions src/engine/Bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ void Bind::computeExpressionBind(
ResultTable* outResult, ResultTable::ResultType* resultType,
const ResultTable& inResult,
sparqlExpression::SparqlExpression* expression) const {
sparqlExpression::VariableColumnMapWithResultTypes
columnMap;
sparqlExpression::VariableColumnMapWithResultTypes columnMap;
for (const auto& [variable, columnIndex] : getVariableColumns()) {
if (columnIndex < inResult.width()) {
columnMap[variable] =
Expand Down Expand Up @@ -173,18 +172,19 @@ void Bind::computeExpressionBind(
if (ptr->size() == 1) {
auto tmpF = static_cast<float>(resultVector[0]);
for (size_t i = 0; i < inSize; ++i) {
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
} else {
for (size_t i = 0; i < inSize; ++i) {
auto tmpF = static_cast<float>(resultVector[i]);
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
Expand All @@ -197,26 +197,29 @@ void Bind::computeExpressionBind(
if (ptr->size() == 1) {
auto tmpF = static_cast<float>(resultVector[0]);
for (size_t i = 0; i < inSize; ++i) {
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
} else {
for (size_t i = 0; i < inSize; ++i) {
auto tmpF = static_cast<float>(resultVector[i]);
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
} else {
for (size_t i = 0; i < inSize; ++i) {
auto tmpF = static_cast<float>(resultVector[i]);
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
}
*resultType = ResultTable::ResultType::FLOAT;
} else if (auto ptr =
std::get_if<sparqlExpression::Variable>(
&expressionResult)) {
std::get_if<sparqlExpression::Variable>(&expressionResult)) {
auto column = getVariableColumns().at(ptr->_variable);
for (size_t i = 0; i < inSize; ++i) {
res(i, inCols) = res(i, column);
Expand All @@ -226,7 +229,8 @@ void Bind::computeExpressionBind(
auto vector = setOfIntervals::expandSet(*ptr, inSize);
for (size_t i = 0; i < inSize; ++i) {
auto tmpF = static_cast<float>(vector[i]);
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
res(i, inCols) = 0ul;
std::memcpy(&res(i, inCols), &tmpF, sizeof(float));
}
Expand All @@ -237,7 +241,8 @@ void Bind::computeExpressionBind(
res(i, inCols) = ptr->_id._value;
}
*resultType = ptr->_type;
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<string>>(&expressionResult)) {
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<string>>(
&expressionResult)) {
auto id = outResult->_localVocab->size();
auto& resultVector = *ptr;
AD_CHECK(ptr->size() == 1 || ptr->size() == inSize);
Expand Down
24 changes: 13 additions & 11 deletions src/engine/GroupBy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ struct resizeIfVec<vector<C>, C> {
template <int IN_WIDTH, int OUT_WIDTH>
void GroupBy::processGroup(
const GroupBy::Aggregate& aggregate,
const sparqlExpression::EvaluationContext*
evaluationContextIn,
const sparqlExpression::EvaluationContext* evaluationContextIn,
size_t blockStart, size_t blockEnd, const IdTableView<IN_WIDTH>& input,
IdTableStatic<OUT_WIDTH>* result, size_t resultRow, size_t resultColumn,
ResultTable* outTable, ResultTable::ResultType* resultType) const {
Expand All @@ -169,31 +168,35 @@ void GroupBy::processGroup(

auto& resultEntry = result->operator()(resultRow, resultColumn);

if (auto ptr = std::get_if<sparqlExpression::Variable>(
&expressionResult)) {
if (auto ptr = std::get_if<sparqlExpression::Variable>(&expressionResult)) {
auto [column, type] =
evaluationContext._variableColumnMap.at(ptr->_variable);
resultEntry = input(blockStart, column);
*resultType = type;
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<double>>(&expressionResult)) {
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<double>>(
&expressionResult)) {
AD_CHECK(ptr->size() == 1);
auto tmpF = static_cast<float>((*ptr)[0]);
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
resultEntry = 0ul;
std::memcpy(&resultEntry, &tmpF, sizeof(float));
*resultType = ResultTable::ResultType::FLOAT;
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<int64_t>>(&expressionResult)) {
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<int64_t>>(
&expressionResult)) {
AD_CHECK(ptr->size() == 1);
auto tmpF = static_cast<float>((*ptr)[0]);
// TODO<joka921> This is needed to make the sorting of positive numbers work, until the ORDER BY module is fixed.
// TODO<joka921> This is needed to make the sorting of positive numbers
// work, until the ORDER BY module is fixed.
resultEntry = 0ul;
std::memcpy(&resultEntry, &tmpF, sizeof(float));
*resultType = ResultTable::ResultType::FLOAT;
} else if (auto ptr = std::get_if<sparqlExpression::StrongIdAndDatatype>(
&expressionResult)) {
resultEntry = ptr->_id._value;
*resultType = ptr->_type;
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<string>>(&expressionResult)) {
} else if (auto ptr = std::get_if<sparqlExpression::LimitedVector<string>>(
&expressionResult)) {
AD_CHECK(ptr->size() == 1);
auto id = outTable->_localVocab->size();
outTable->_localVocab->push_back((*ptr)[0]);
Expand Down Expand Up @@ -237,8 +240,7 @@ void GroupBy::doGroupBy(const IdTable& dynInput,
const IdTableView<IN_WIDTH> input = dynInput.asStaticView<IN_WIDTH>();
IdTableStatic<OUT_WIDTH> result = dynResult->moveToStatic<OUT_WIDTH>();

sparqlExpression::VariableColumnMapWithResultTypes
columnMap;
sparqlExpression::VariableColumnMapWithResultTypes columnMap;
for (const auto& [variable, columnIndex] : _subtree->getVariableColumns()) {
columnMap[variable] =
std::pair(columnIndex, inTable->getResultType(columnIndex));
Expand Down
4 changes: 4 additions & 0 deletions src/parser/SparqlExpressionHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ auto makeExtractor(T&& expandedResult) {
if constexpr (ad_utility::isSimilar<T, StrongIdsAndDatatype>) {
return StrongIdAndDatatype{expanded._ids[index], expanded._type};
} else if constexpr (ad_utility::isVector<T>) {
// TODO<joka921>:: move this somewhere else, where it is cheaper.
if (expanded.size() == 1) {
index = 0;
}
if constexpr (ad_utility::isSimilar<LimitedVector<bool>, T>) {
// special case because of the strange bit-references
return bool{expanded[index]};
Expand Down
6 changes: 3 additions & 3 deletions src/parser/SparqlExpressionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ concept SingleExpressionResult =
ad_utility::isTypeContainedIn<T, ExpressionResult>;

/// We will use the string representation of various functions (e.g. '+' '*')
/// directly as template parameters. Currently 15 characters are enough for this,
/// but if we need longer names in the future, we can still change this at the
/// cost of a recompilation.
/// directly as template parameters. Currently 15 characters are enough for
/// this, but if we need longer names in the future, we can still change this at
/// the cost of a recompilation.
using TagString = ad_utility::ConstexprSmallString<16>;

/// Annotate an arbitrary type (we will use this for callables) with a
Expand Down
3 changes: 1 addition & 2 deletions test/SparqlExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ auto testOr = [](auto&& left, auto&& right, const ExpressionResult& expected) {
ad_utility::makeAllocationMemoryLeftThreadsafeObject(1000)};
sparqlExpression::VariableColumnMapWithResultTypes map;
IdTable table{alloc};
sparqlExpression::EvaluationContext context{*ctxt, map, table,
alloc};
sparqlExpression::EvaluationContext context{*ctxt, map, table, alloc};
std::vector<SparqlExpression::Ptr> children;
children.push_back(
std::make_unique<DummyExpression>(ExpressionResult{std::move(left)}));
Expand Down

0 comments on commit a393a81

Please sign in to comment.