github-actions[bot] commented on code in PR #67979:
URL: https://github.com/apache/doris/pull/67979#discussion_r4011312410


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java:
##########
@@ -693,6 +693,15 @@ private LogicalAggregate<? extends Plan> 
storageLayerAggregate(
             return canNotPush;
         }
 
+        // File MIN/MAX retains only source endpoints. A cast can turn both 
endpoints into NULL
+        // while an interior value remains valid. Ignore source nullability 
when checking the cast
+        // itself, so safe widening casts over nullable columns can still use 
metadata.
+        if (logicalScan instanceof LogicalFileScan && 
argumentsOfAggregateFunction.stream()
+                .anyMatch(argument -> argument instanceof Cast
+                        && Cast.castNullable(false, 
argument.child(0).getDataType(), argument.getDataType()))) {

Review Comment:
   [P1] Please reject floating-source casts here (or require a metadata-level 
no-NaN proof). For `DOUBLE -> FLOAT`, this predicate returns false and the cast 
preserves NaN, but Parquet footer min/max omits NaNs. Doris orders NaN above 
finite values for `MAX`, so rows `[0.0, NaN]` should produce NaN while 
FileScannerV2 materializes only the finite footer endpoints and returns `0.0`. 
The new guard therefore still permits a wrong-result case within the cast 
family it is meant to make safe.



##########
regression-test/suites/external_table_p0/paimon/test_paimon_minmax_cast.groovy:
##########
@@ -0,0 +1,97 @@
+// 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.
+
+suite("test_paimon_minmax_cast", 
"p0,external,paimon,external_docker,external_docker_paimon") {
+    String enabled = context.config.otherConfigs.get("enablePaimonTest")
+    if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+        logger.info("Paimon test is disabled")
+        return
+    }
+
+    String catalogName = "test_paimon_minmax_cast"
+    String dbName = "paimon_minmax_cast_db"
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String minioPort = context.config.otherConfigs.get("iceberg_minio_port")
+    def originalSettings = ["enable_file_scanner_v2", "force_jni_scanner",
+            "enable_strict_cast", 
"enable_push_down_no_group_agg"].collectEntries { name ->
+        [(name): sql("show variables like '${name}'")[0][1]]
+    }
+
+    try {
+        // A single writer and bucket keep both overflowing endpoints and the 
valid interior value
+        // in one file. Separate files could let metadata aggregation retain 
the interior value.
+        spark_paimon_multi """
+            create database if not exists paimon.${dbName};
+            drop table if exists paimon.${dbName}.minmax_cast;
+            create table paimon.${dbName}.minmax_cast (value bigint)
+                using paimon tblproperties (
+                    'bucket'='1',
+                    'bucket-key'='value',
+                    'file.format'='parquet'
+                );
+            insert into paimon.${dbName}.minmax_cast
+                select /*+ coalesce(1) */ value from values
+                    (cast(-2147483649 as bigint)),
+                    (cast(0 as bigint)),
+                    (cast(2147483648 as bigint)) as data(value);
+        """
+
+        sql """drop catalog if exists ${catalogName}"""
+        sql """create catalog ${catalogName} properties (
+            'type'='paimon',
+            'warehouse'='s3://warehouse/wh',
+            's3.endpoint'='http://${externalEnvIp}:${minioPort}',
+            's3.access_key'='admin',
+            's3.secret_key'='password',
+            's3.path.style.access'='true',
+            'meta.cache.paimon.table.ttl-second'='0'
+        )"""
+        sql """switch ${catalogName}"""
+        sql """use ${dbName}"""
+        sql "set enable_file_scanner_v2=true"
+        sql "set force_jni_scanner=false"
+        sql "set enable_strict_cast=false"
+
+        def queries = [
+            "select min(cast(value as int)) from minmax_cast",
+            "select max(cast(value as int)) from minmax_cast",
+            "select min(cast(value as int)), max(cast(value as int)) from 
minmax_cast"
+        ]
+        queries.each { query ->
+            sql "set enable_push_down_no_group_agg=false"
+            def fullScanResult = sql(query)
+            sql "set enable_push_down_no_group_agg=true"
+            // Compare with row-by-row evaluation so the reference cannot 
share the metadata bug.
+            assertEquals(fullScanResult, sql(query))
+            explain {
+                sql(query)
+                contains "pushdown agg=NONE"
+            }
+        }
+
+        // Keep a positive control: disabling all file MIN/MAX pushdown must 
not satisfy this test.
+        explain {
+            sql "select min(value), max(value) from minmax_cast"
+            contains "pushdown agg=MINMAX"
+            contains "inputSplitNum=1"

Review Comment:
   [P2] Please also assert `paimonNativeReadSplits=1/1`. `inputSplitNum=1` 
counts total connector ranges and is equally true for one JNI range; 
`force_jni_scanner=false` only permits native routing, because Paimon still 
falls back when `DataSplit.convertToRawFiles()` is unavailable. On that 
fallback the new `NONE` checks and result comparison can pass without 
exercising FileScannerV2's Parquet footer path, so this regression would not 
guard the reported end-to-end bug.



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