924060929 commented on code in PR #12583: URL: https://github.com/apache/doris/pull/12583#discussion_r1020218941
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalRepeat.java: ########## @@ -0,0 +1,151 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.plans.physical; + +import org.apache.doris.nereids.memo.GroupExpression; +import org.apache.doris.nereids.properties.LogicalProperties; +import org.apache.doris.nereids.properties.PhysicalProperties; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.VirtualSlotReference; +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.PlanType; +import org.apache.doris.nereids.trees.plans.algebra.Repeat; +import org.apache.doris.nereids.trees.plans.logical.GroupingSetIdSlot; +import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; +import org.apache.doris.nereids.util.Utils; +import org.apache.doris.statistics.StatsDeriveResult; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + +import java.util.BitSet; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * PhysicalRepeat. + */ +public abstract class PhysicalRepeat<CHILD_TYPE extends Plan> + extends PhysicalUnary<CHILD_TYPE> implements Repeat { + protected final List<Expression> groupByExpressions; + protected final List<NamedExpression> outputExpressions; + protected final List<GroupingSetIdSlot> groupingSetIdSlots; + + /** + * initial construction method. + */ + public PhysicalRepeat( + PlanType type, + List<Expression> groupByExpressions, + List<NamedExpression> outputExpressions, + List<GroupingSetIdSlot> groupingSetIdSlots, + Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties, + CHILD_TYPE child) { + super(type, groupExpression, logicalProperties, child); + this.groupByExpressions = ImmutableList.copyOf(groupByExpressions); + this.outputExpressions = ImmutableList.copyOf(outputExpressions); + this.groupingSetIdSlots = ImmutableList.copyOf(groupingSetIdSlots); + } + + /** + * Constructor with all parameters. + */ + public PhysicalRepeat( + PlanType type, + List<Expression> groupByExpressions, + List<NamedExpression> outputExpressions, + List<GroupingSetIdSlot> groupingSetIdSlots, + Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties, + PhysicalProperties physicalProperties, StatsDeriveResult statsDeriveResult, CHILD_TYPE child) { + super(type, groupExpression, logicalProperties, physicalProperties, statsDeriveResult, child); + this.groupByExpressions = ImmutableList.copyOf(groupByExpressions); + this.outputExpressions = ImmutableList.copyOf(outputExpressions); + this.groupingSetIdSlots = ImmutableList.copyOf(groupingSetIdSlots); + } + + public List<NamedExpression> getOutputExpressions() { + return outputExpressions; + } + + @Override + public List<Expression> getGroupByExpressions() { + return groupByExpressions; + } + + public List<Expression> getNonVirtualGroupByExpressions() { + return groupByExpressions.stream().filter(e -> !(e instanceof VirtualSlotReference)) + .collect(ImmutableList.toImmutableList()); + } + + public List<Expression> getVirtualGroupByExpressions() { + return groupByExpressions.stream().filter(VirtualSlotReference.class::isInstance) + .collect(ImmutableList.toImmutableList()); + } + + public List<GroupingSetIdSlot> getGroupingSetIdSlots() { + return groupingSetIdSlots; + } + + public List<List<Long>> getVirtualSlotValues() { + Builder<List<Long>> wholeVirtualSlotValues = ImmutableList.builder(); + groupingSetIdSlots.stream().forEach(e -> wholeVirtualSlotValues.add(e.toLongValue())); + return wholeVirtualSlotValues.build(); Review Comment: RepeatNode.groupingList consists of 1. the big endian bits to long by the GroupingSetShape, that is your `groupingSetIdSlots.toLongValue()` 2. the big endian bits to long by other GroupingScalaFunction.toLongValue Missing point 2? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/NormalizePlan.java: ########## @@ -0,0 +1,235 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.rules.rewrite.logical; + +import org.apache.doris.common.Pair; +import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.SlotReference; +import org.apache.doris.nereids.trees.expressions.VirtualSlotReference; +import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; +import org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction; +import org.apache.doris.nereids.trees.expressions.literal.Literal; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Normalize Plan. + */ +public interface NormalizePlan { + /** + * get AggFunc from outputExpressions + */ + default Set<AggregateFunction> getAggregateFunctions(List<NamedExpression> outputs) { + Map<Boolean, List<NamedExpression>> partitionedOutputs = outputs.stream() + .collect(Collectors.groupingBy(e -> e.anyMatch(AggregateFunction.class::isInstance) + || e.anyMatch(GroupingScalarFunction.class::isInstance))); + return partitionedOutputs.containsKey(true) + ? partitionedOutputs.get(true).stream() + .flatMap(e -> e.<Set<AggregateFunction>>collect( + AggregateFunction.class::isInstance).stream()) + .collect(Collectors.toSet()) + : Sets.newHashSet(); + } Review Comment: Contains AggregateFunction or GroupingScalarFunction, then collect AggregateFunction? What is the function of GroupingScalarFunction here? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownFilterThroughAggregation.java: ########## @@ -85,6 +91,9 @@ public Rule build() { } }); + if (hasRepeat) { + return filter; + } Review Comment: add comment to explain why not pushdown when there is Repeat exists? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org