Skip to content

Commit f766700

Browse files
authored
fix apply on user-defined aggregate init (#2456)
The `init` expression of user-define aggregates was never handed-over to `apply`'s `mapper`. One visible issue is that the `TupleId` transformer would not update the tuple of the `init` expression while shuffling tuple identifiers. That would then result in the `init` expression peeking data in the wrong tuple during execution of the RAM program.
1 parent 2d20ade commit f766700

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/ast/UserDefinedAggregator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ Node::NodeVec UserDefinedAggregator::getChildren() const {
3434
}
3535

3636
void UserDefinedAggregator::print(std::ostream& os) const {
37-
os << "@" << name;
38-
os << " init: " << *initValue;
37+
os << "@@" << name << " " << *initValue;
3938
if (targetExpression) {
40-
os << " " << *targetExpression;
39+
os << ", " << *targetExpression;
4140
}
4241
os << " : { " << join(body) << " }";
4342
}

src/ram/Aggregate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Aggregate : public RelationOperation, public AbstractAggregate {
6363
RelationOperation::apply(map);
6464
condition = map(std::move(condition));
6565
expression = map(std::move(expression));
66+
function->apply(map);
6667
}
6768

6869
static bool classof(const Node* n) {

src/ram/Aggregator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class Aggregator {
4545
return {};
4646
}
4747

48+
virtual void apply(const NodeMapper&) {}
49+
4850
/**
4951
* @brief Create a cloning (i.e. deep copy) of this node
5052
*/

src/ram/IndexAggregate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class IndexAggregate : public IndexOperation, public AbstractAggregate {
6666
IndexOperation::apply(map);
6767
condition = map(std::move(condition));
6868
expression = map(std::move(expression));
69+
function->apply(map);
6970
}
7071

7172
static bool classof(const Node* n) {

src/ram/UserDefinedAggregator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class UserDefinedAggregator : public Aggregator {
7777
os << name << " INIT " << *initValue << " ";
7878
}
7979

80+
void apply(const NodeMapper& map) override {
81+
initValue = map(std::move(initValue));
82+
}
83+
8084
protected:
8185
/** Aggregation function */
8286
const std::string name;
@@ -92,4 +96,4 @@ class UserDefinedAggregator : public Aggregator {
9296
/** Stateful */
9397
const bool stateful;
9498
};
95-
} // namespace souffle::ram
99+
} // namespace souffle::ram

0 commit comments

Comments
 (0)