8000 fix some issues with sorted variant of COLLECT by jsteemann · Pull Request #6433 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

fix some issues with sorted variant of COLLECT #6433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the 8000 community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions arangod/Aql/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,16 @@ struct AggregatorMax final : public Aggregator {

struct AggregatorSum final : public Aggregator {
explicit AggregatorSum(transaction::Methods* trx)
: Aggregator(trx), sum(0.0), invalid(false) {}
: Aggregator(trx), sum(0.0), invalid(false), invoked(false) {}

void reset() override {
sum = 0.0;
invalid = false;
invoked = false;
}

void reduce(AqlValue const& cmpValue) override {
invoked = true;
if (!invalid) {
if (cmpValue.isNull(true)) {
// ignore `null` values here
Expand All @@ -253,7 +255,7 @@ struct AggregatorSum final : public Aggregator {
}

AqlValue stealValue() override {
if (invalid || std::isnan(sum) || sum == HUGE_VAL || sum == -HUGE_VAL) {
if (invalid || !invoked || std::isnan(sum) || sum == HUGE_VAL || sum == -HUGE_VAL) {
return AqlValue(AqlValueHintNull());
}

Expand All @@ -266,6 +268,7 @@ struct AggregatorSum final : public Aggregator {

double sum;
bool invalid;
bool invoked;
};

/// @brief the single-server variant of AVERAGE
Expand Down
5 changes: 1 addition & 4 deletions arangod/Aql/CollectBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,8 @@ void SortedCollectBlock::emitGroup(AqlItemBlock const* cur, AqlItemBlock* res,
++r) {
it->reduce(getValueForRegister(cur, r, reg));
}
res->setValue(row, _aggregateRegisters[j].first, it->stealValue());
} else {
res->emplaceValue(row, _aggregateRegisters[j].first,
AqlValueHintNull());
}
res->setValue(row, _aggregateRegisters[j].first, it->stealValue());
++j;
}

Expand Down
5 changes: 3 additions & 2 deletions arangod/Aql/OptimizerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2128,10 +2128,10 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {

IndexIteratorOptions opts;
opts.ascending = sortCondition.isAscending();
std::unique_ptr<ExecutionNode> newNode(new IndexNode(
auto newNode = std::make_unique<IndexNode>(
_plan, _plan->nextId(),
enumerateCollectionNode->collection(), outVariable, usedIndexes,
std::move(condition), opts));
std::move(condition), opts);

auto n = newNode.release();

Expand All @@ -2142,6 +2142,7 @@ struct SortToIndexNode final : public WalkerWorker<Exec 8000 utionNode> {
if (coveredAttributes == sortCondition.numAttributes()) {
// if the index covers the complete sort condition, we can also remove
// the sort node
n->needsGatherNodeSort(true);
_plan->unlinkNode(_plan->getNodeById(_sortNode->id()));
}
}
Expand Down
6 changes: 3 additions & 3 deletions js/common/modules/@arangodb/aql/explainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function printIndexes (indexes) {
var ranges;
if (indexes[i].hasOwnProperty('condition')) {
ranges = indexes[i].condition;
} else {
} else {
ranges = '[ ' + indexes[i].ranges + ' ]';
}

Expand Down Expand Up @@ -982,11 +982,11 @@ function processQuery (query, explain) {
if (node.hasOwnProperty('condition') && node.condition.type && node.condition.type === 'n-ary or') {
idx.condition = buildExpression(node.condition.subNodes[i]);
} else {
if (variable !== false) {
if (variable !== false && variable !== undefined) {
idx.condition = variable;
}
}
if (idx.condition === '') {
if (idx.condition === '' || idx.condition === undefined) {
idx.condition = '*'; // empty condition. this is likely an index used for sorting or scanning only
}
indexes.push(idx);
Expand Down
Loading
0