Empty Collect() returns nothing (#1482)
This commit is contained in:
@@ -3463,7 +3463,7 @@ class AggregateCursor : public Cursor {
|
||||
SCOPED_PROFILE_OP_BY_REF(self_);
|
||||
|
||||
if (!pulled_all_input_) {
|
||||
ProcessAll(&frame, &context);
|
||||
if (!ProcessAll(&frame, &context) && self_.AreAllAggregationsForCollecting()) return false;
|
||||
pulled_all_input_ = true;
|
||||
aggregation_it_ = aggregation_.begin();
|
||||
|
||||
@@ -3487,7 +3487,6 @@ class AggregateCursor : public Cursor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (aggregation_it_ == aggregation_.end()) return false;
|
||||
|
||||
// place aggregation values on the frame
|
||||
@@ -3567,12 +3566,16 @@ class AggregateCursor : public Cursor {
|
||||
* cache cardinality depends on number of
|
||||
* aggregation results, and not on the number of inputs.
|
||||
*/
|
||||
void ProcessAll(Frame *frame, ExecutionContext *context) {
|
||||
bool ProcessAll(Frame *frame, ExecutionContext *context) {
|
||||
ExpressionEvaluator evaluator(frame, context->symbol_table, context->evaluation_context, context->db_accessor,
|
||||
storage::View::NEW);
|
||||
|
||||
bool pulled = false;
|
||||
while (input_cursor_->Pull(*frame, *context)) {
|
||||
ProcessOne(*frame, &evaluator);
|
||||
pulled = true;
|
||||
}
|
||||
if (!pulled) return false;
|
||||
|
||||
// post processing
|
||||
for (size_t pos = 0; pos < self_.aggregations_.size(); ++pos) {
|
||||
@@ -3606,6 +3609,7 @@ class AggregateCursor : public Cursor {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3819,6 +3823,12 @@ UniqueCursorPtr Aggregate::MakeCursor(utils::MemoryResource *mem) const {
|
||||
return MakeUniqueCursorPtr<AggregateCursor>(mem, *this, mem);
|
||||
}
|
||||
|
||||
auto Aggregate::AreAllAggregationsForCollecting() const -> bool {
|
||||
return std::all_of(aggregations_.begin(), aggregations_.end(), [](const auto &agg) {
|
||||
return agg.op == Aggregation::Op::COLLECT_LIST || agg.op == Aggregation::Op::COLLECT_MAP;
|
||||
});
|
||||
}
|
||||
|
||||
Skip::Skip(const std::shared_ptr<LogicalOperator> &input, Expression *expression)
|
||||
: input_(input), expression_(expression) {}
|
||||
|
||||
|
||||
@@ -1758,6 +1758,9 @@ class Aggregate : public memgraph::query::plan::LogicalOperator {
|
||||
Aggregate() = default;
|
||||
Aggregate(const std::shared_ptr<LogicalOperator> &input, const std::vector<Element> &aggregations,
|
||||
const std::vector<Expression *> &group_by, const std::vector<Symbol> &remember);
|
||||
|
||||
auto AreAllAggregationsForCollecting() const -> bool;
|
||||
|
||||
bool Accept(HierarchicalLogicalOperatorVisitor &visitor) override;
|
||||
UniqueCursorPtr MakeCursor(utils::MemoryResource *) const override;
|
||||
std::vector<Symbol> ModifiedSymbols(const SymbolTable &) const override;
|
||||
|
||||
Reference in New Issue
Block a user