You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "liuyongvs (via GitHub)" <gi...@apache.org> on 2025/01/06 07:42:03 UTC

[PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

liuyongvs opened a new pull request, #25900:
URL: https://github.com/apache/flink/pull/25900

   ## What is the purpose of the change
   
   The PR migrates PruneAggregateCallRule to java
   
   ## Verifying this change
   
   This change is already covered by existing tests
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not applicable)
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #25900: [FLINK-37009][table] Migrate PruneAggregateCallRule to java
URL: https://github.com/apache/flink/pull/25900


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2948233371

   This PR has been closed since it has not had any activity in 120 days. 
   If you feel like this was a mistake, or you would like to continue working on it, 
   please feel free to re-open the PR and ask for a review.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "liuyongvs (via GitHub)" <gi...@apache.org>.
liuyongvs commented on code in PR #25900:
URL: https://github.com/apache/flink/pull/25900#discussion_r1903784779


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/PruneAggregateCallRule.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.flink.table.planner.plan.rules.logical;
+
+import org.apache.flink.util.Preconditions;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.Aggregate.Group;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.core.Calc;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.core.RelFactories;
+import org.apache.calcite.rex.RexInputRef;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexProgram;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.runtime.Utilities;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.mapping.Mappings;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/** Planner rule that removes unreferenced AggregateCall from Aggregate. */
+public abstract class PruneAggregateCallRule<T extends RelNode> extends RelOptRule {
+
+    public static final ProjectPruneAggregateCallRule PROJECT_ON_AGGREGATE =
+            new ProjectPruneAggregateCallRule();
+    public static final CalcPruneAggregateCallRule CALC_ON_AGGREGATE =
+            new CalcPruneAggregateCallRule();
+
+    protected PruneAggregateCallRule(Class<T> topClass) {
+        super(
+                operand(topClass, operand(Aggregate.class, any())),
+                RelFactories.LOGICAL_BUILDER,
+                "PruneAggregateCallRule_" + topClass.getCanonicalName());
+    }
+
+    protected abstract ImmutableBitSet getInputRefs(T relOnAgg);
+
+    @Override
+    public boolean matches(RelOptRuleCall call) {
+        T relOnAgg = call.rel(0);
+        Aggregate agg = call.rel(1);
+        if (agg.getGroupType() != Group.SIMPLE
+                || agg.getAggCallList().isEmpty()
+                ||
+                // at least output one column
+                (agg.getGroupCount() == 0 && agg.getAggCallList().size() == 1)) {
+            return false;
+        }
+        ImmutableBitSet inputRefs = getInputRefs(relOnAgg);
+        int[] unrefAggCallIndices = getUnrefAggCallIndices(inputRefs, agg);
+        return unrefAggCallIndices.length > 0;
+    }
+
+    private int[] getUnrefAggCallIndices(ImmutableBitSet inputRefs, Aggregate agg) {
+        int groupCount = agg.getGroupCount();
+        return IntStream.range(0, agg.getAggCallList().size())
+                .filter(index -> !inputRefs.get(groupCount + index))
+                .toArray();
+    }
+
+    @Override
+    public void onMatch(RelOptRuleCall call) {
+        T relOnAgg = call.rel(0);
+        Aggregate agg = call.rel(1);
+        ImmutableBitSet inputRefs = getInputRefs(relOnAgg);
+        int[] unrefAggCallIndices = getUnrefAggCallIndices(inputRefs, agg);
+        Preconditions.checkArgument(unrefAggCallIndices.length > 0, "requirement failed");
+
+        List<AggregateCall> newAggCalls = new ArrayList<>(agg.getAggCallList());
+        // remove unreferenced AggCall from original aggCalls
+        Arrays.stream(unrefAggCallIndices)
+                .boxed()
+                .sorted(Comparator.reverseOrder())
+                .forEach(index -> newAggCalls.remove((int) index));
+

Review Comment:
   comments: newAggCalls.remove((int) index) , we need this int cast here. because it will remove the value instead of   removing index when doesn't have int cast 



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2583159607

   Reviewed by Chi on 09/01/2025 Need a committer to review


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "liuyongvs (via GitHub)" <gi...@apache.org>.
liuyongvs commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2635562074

   hi @snuyanzin will you help review this pr?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "liuyongvs (via GitHub)" <gi...@apache.org>.
liuyongvs commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2574241563

   @flinkbot  run azure


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "liuyongvs (via GitHub)" <gi...@apache.org>.
liuyongvs commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2579017451

   @snuyanzin will you help review this pr?


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2853418728

   This PR is being marked as stale since it has not had any activity in the last 90 days. 
   If you would like to keep this PR alive, please leave a comment asking for a review. 
   If the PR has merge conflicts, update it with the latest from the base branch.
   
   If you are having difficulty finding a reviewer, please reach out to the 
   community, contact details can be found here: https://flink.apache.org/what-is-flink/community/
   
   If this PR is no longer valid or desired, please feel free to close it. 
   If no activity occurs in the next 30 days, it will be automatically closed.


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-37009][table] Migrate PruneAggregateCallRule to java [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25900:
URL: https://github.com/apache/flink/pull/25900#issuecomment-2572515828

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "c218aaf3f779ae155b965e43fa812f302f71a3f6",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c218aaf3f779ae155b965e43fa812f302f71a3f6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c218aaf3f779ae155b965e43fa812f302f71a3f6 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org