Guosmilesmile commented on code in PR #17946: URL: https://github.com/apache/iceberg/pull/17946#discussion_r3950668590
########## flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/source/TestFlinkTableSourceAggregatePushDown.java: ########## @@ -0,0 +1,248 @@ +/* + * 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.source; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import org.apache.flink.configuration.CoreOptions; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.types.Row; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.Parameter; +import org.apache.iceberg.ParameterizedTestExtension; +import org.apache.iceberg.Parameters; +import org.apache.iceberg.flink.FlinkConfigOptions; +import org.apache.iceberg.flink.TestBase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(ParameterizedTestExtension.class) +public class TestFlinkTableSourceAggregatePushDown extends TestBase { + + @Parameters(name = "useFlip27Source = {0}") + private static Object[][] parameters() { + return new Object[][] { + {false}, {true}, + }; + } + + @Parameter(index = 0) + private boolean useFlip27Source; + + private static final String CATALOG_NAME = "test_catalog"; + private static final String DATABASE_NAME = "test_db"; + private static final String TABLE_NAME = "test_table"; + + @Override + protected TableEnvironment getTableEnv() { + super.getTableEnv().getConfig().getConfiguration().set(CoreOptions.DEFAULT_PARALLELISM, 1); + super.getTableEnv() + .getConfig() + .getConfiguration() + .set(FlinkConfigOptions.TABLE_EXEC_ICEBERG_USE_FLIP27_SOURCE, useFlip27Source); + return super.getTableEnv(); + } + + @BeforeEach + public void before() throws IOException { + getTableEnv() + .getConfig() + .getConfiguration() + .removeConfig(FlinkConfigOptions.TABLE_EXEC_ICEBERG_AGGREGATE_PUSH_DOWN_ENABLED); + File warehouseFile = File.createTempFile("junit", null, temporaryDirectory.toFile()); + assertThat(warehouseFile.delete()).isTrue(); + String warehouse = String.format("file:%s", warehouseFile); + + sql( + "CREATE CATALOG %s WITH ('type'='iceberg', 'catalog-type'='hadoop', 'warehouse'='%s')", + CATALOG_NAME, warehouse); + sql("USE CATALOG %s", CATALOG_NAME); + sql("CREATE DATABASE %s", DATABASE_NAME); + sql("USE %s", DATABASE_NAME); + sql( + "CREATE TABLE %s (id INT, data VARCHAR, d DOUBLE) WITH ('write.format.default'='%s')", + TABLE_NAME, FileFormat.PARQUET.name()); + sql( + "INSERT INTO %s VALUES (1,'iceberg',10),(2,'b',20),(3,CAST(NULL AS VARCHAR),30)", + TABLE_NAME); + } + + @AfterEach + public void clean() { + sql("DROP TABLE IF EXISTS %s.%s", DATABASE_NAME, TABLE_NAME); + dropDatabase(DATABASE_NAME, true); + dropCatalog(CATALOG_NAME, true); + } + + @TestTemplate + public void countStarPushDown() { + enableAggregatePushDown(); + + String query = String.format("SELECT COUNT(*) FROM %s", TABLE_NAME); + assertThat(explain(query)) + .as("Local aggregate should be pushed into the scan") + .contains("aggregates=["); + + List<Row> result = sql(query); + assertThat(result).hasSize(1).containsExactly(Row.of(3L)); + } + + @TestTemplate + public void countColumnPushDown() { + enableAggregatePushDown(); + + String query = String.format("SELECT COUNT(data) FROM %s", TABLE_NAME); + assertThat(explain(query)) + .as("Local aggregate should be pushed into the scan") + .contains("aggregates=["); + + List<Row> result = sql(query); + assertThat(result).hasSize(1).containsExactly(Row.of(2L)); + } + + @TestTemplate + public void maxMinPushDown() { Review Comment: Add aggregatePushDownSkippedForAvroTable 、 aggregatePushDownSkippedWithCountsMetricsMode 、 maxOnDoublePushDown、maxOnStringIsNotPushedDown for this part. -- 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]
