001package gudusoft.gsqlparser.ir.logical.rel;
002
003import gudusoft.gsqlparser.ir.common.SourceAnchor;
004import gudusoft.gsqlparser.ir.logical.*;
005
006import java.util.Collections;
007import java.util.List;
008
009/**
010 * GROUP BY aggregation.
011 */
012public final class Aggregate extends RelNode {
013    private final RelNode input;
014    private final List<RexNode> groupByKeys;
015    private final List<RexNode> aggregations;
016
017    public Aggregate(RelNode input, List<RexNode> groupByKeys, List<RexNode> aggregations, SourceAnchor anchor) {
018        super(RelNodeKind.AGGREGATE, anchor);
019        this.input = input;
020        this.groupByKeys = groupByKeys != null ? Collections.unmodifiableList(groupByKeys) : Collections.<RexNode>emptyList();
021        this.aggregations = aggregations != null ? Collections.unmodifiableList(aggregations) : Collections.<RexNode>emptyList();
022    }
023
024    public RelNode getInput() { return input; }
025    public List<RexNode> getGroupByKeys() { return groupByKeys; }
026    public List<RexNode> getAggregations() { return aggregations; }
027
028    @Override
029    public List<RelNode> getInputs() { return Collections.singletonList(input); }
030
031    @Override
032    public <R> R accept(RelNodeVisitor<R> visitor) { return visitor.visitAggregate(this); }
033}