mihaibudiu commented on code in PR #4892:
URL: https://github.com/apache/calcite/pull/4892#discussion_r3127430122


##########
core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveDuplicateKeysRule.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.calcite.rel.rules;
+
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelRule;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.logical.LogicalAggregate;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+
+import org.immutables.value.Value;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Planner rule that removes redundant grouping keys from an
+ * {@link Aggregate} when the later keys are functionally determined by the
+ * earlier retained keys.
+ *
+ * <p>The original output schema is preserved by adding {@code ANY_VALUE}
+ * aggregate calls for removed grouping keys and then projecting the row back
+ * into the original field order.
+ *
+ * <p>{@code ANY_VALUE} is chosen over {@code SINGLE_VALUE} because functional
+ * dependence only guarantees that a removed key maps to a single 
<em>value</em>
+ * per group, not that the group contains a single <em>row</em>.
+ * {@code SINGLE_VALUE} enforces the stricter, row-count constraint at runtime

Review Comment:
   Yes, that's fine.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to