wombatu-kun commented on code in PR #17946:
URL: https://github.com/apache/iceberg/pull/17946#discussion_r3954790889


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkAggregates.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.iceberg.flink;
+
+import java.util.List;
+import org.apache.flink.table.expressions.AggregateExpression;
+import org.apache.flink.table.expressions.FieldReferenceExpression;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.planner.functions.aggfunctions.Count1AggFunction;
+import org.apache.flink.table.planner.functions.aggfunctions.CountAggFunction;
+import org.apache.flink.table.planner.functions.aggfunctions.MaxAggFunction;
+import org.apache.flink.table.planner.functions.aggfunctions.MinAggFunction;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.Expressions;
+
+/**
+ * Converts a Flink {@link AggregateExpression} to an Iceberg {@link 
Expression} that {@link
+ * org.apache.iceberg.expressions.AggregateEvaluator} can evaluate from 
file-level metrics alone,
+ * without reading any data files.
+ *
+ * <p>Only {@code COUNT(*)}, {@code COUNT(col)}, {@code MAX(col)} and {@code 
MIN(col)} can be
+ * derived from file metrics; {@code SUM} and {@code AVG} are not tracked by 
Iceberg manifests and
+ * are never converted.
+ */
+public class FlinkAggregates {
+  private FlinkAggregates() {}
+
+  public static Expression convert(AggregateExpression aggregate) {
+    if (aggregate.isDistinct()
+        || aggregate.isApproximate()
+        || aggregate.getFilterExpression().isPresent()) {
+      return null;
+    }
+
+    FunctionDefinition function = aggregate.getFunctionDefinition();
+    List<FieldReferenceExpression> args = aggregate.getArgs();
+
+    if (function instanceof Count1AggFunction) {

Review Comment:
   This dispatches on org.apache.flink.table.planner.functions.aggfunctions 
types, which a stock distribution keeps inside flink-table-planner-loader and 
does not expose to connector code, so enabling the flag there fails with 
NoClassDefFoundError instead of falling back to a normal scan. Is there a way 
to recognise these aggregates without planner internals, or should the docs 
state that flink-table-planner_2.12 has to replace the loader jar?



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkReadOptions.java:
##########
@@ -48,6 +48,8 @@ private FlinkReadOptions() {}
   public static final ConfigOption<Boolean> CASE_SENSITIVE_OPTION =
       ConfigOptions.key(PREFIX + 
CASE_SENSITIVE).booleanType().defaultValue(false);
 
+  public static final String AGGREGATE_PUSH_DOWN_ENABLED = 
"aggregate-push-down-enabled";

Review Comment:
   This is the only read option here declared without a 
connector.iceberg.<name> ConfigOption, so the Flink config spelling that works 
for every neighbouring read option does nothing for this one. Was the 
table.exec.iceberg namespace a deliberate choice here?



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/source/IcebergTableSource.java:
##########
@@ -82,6 +114,8 @@ private IcebergTableSource(IcebergTableSource toCopy) {
     this.limit = toCopy.limit;
     this.filters = toCopy.filters;
     this.readableConfig = toCopy.readableConfig;
+    this.pushedAggregate = toCopy.pushedAggregate;

Review Comment:
   Flink applies each push-down ability to a fresh copy(), and this constructor 
carries neither cachedTable nor readConf, so a filtered aggregate query still 
does two catalog loads. Copy both transient fields here.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to