cshuo commented on code in PR #19392: URL: https://github.com/apache/hudi/pull/19392#discussion_r3670680200
########## hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/streamer/TestFlinkStreamerConfig.java: ########## @@ -0,0 +1,145 @@ +/* + * 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.hudi.streamer; + +import org.apache.hudi.common.model.WriteOperationType; +import org.apache.hudi.configuration.FlinkOptions; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.ParameterException; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for {@link FlinkStreamerConfig}. + */ +class TestFlinkStreamerConfig { + + @TempDir + Path tempDir; + + @Test + void testParseAndDeriveFlinkConfiguration() { + FlinkStreamerConfig config = parse( + "--kafka-topic", "orders", + "--kafka-group-id", "flink-writers", + "--kafka-bootstrap-servers", "broker:9092", + "--target-base-path", tempDir.toString(), + "--target-table", "orders_hudi", + "--table-type", "merge_on_read", + "--op", "INSERT", + "--record-key-field", "order_id", + "--partition-path-field", "order_date", + "--source-ordering-fields", "event_ts,seq_no", + "--instant-retry-times", "7", + "--instant-retry-interval", "250", + "--filter-dupes", + "--commit-on-errors", + "--metadata-enabled", + "--write-rate-limit", "500", + "--write-task-num", "6", + "--bucket-assign-num", "5", + "--index-bootstrap-num", "4", + "--source-avro-schema-path", "file:///tmp/source.avsc", + "--source-avro-schema", "{\"type\":\"record\",\"name\":\"order\",\"fields\":[]}", + "--compaction-tasks", "3", + "--clustering-tasks", "2", + "--hive-sync-enable", + "--hive-sync-db", "analytics", + "--hive-sync-table", "orders", + "--hoodie-conf", "hoodie.datasource.write.drop.partition.columns=true"); + + Configuration conf = FlinkStreamerConfig.toFlinkConfig(config); + + assertEquals(tempDir.toString(), conf.get(FlinkOptions.PATH)); + assertEquals("orders_hudi", conf.get(FlinkOptions.TABLE_NAME)); + assertEquals("MERGE_ON_READ", conf.get(FlinkOptions.TABLE_TYPE)); + assertEquals(WriteOperationType.INSERT.value(), conf.get(FlinkOptions.OPERATION)); + assertEquals("order_id", conf.get(FlinkOptions.RECORD_KEY_FIELD)); + assertEquals("order_date", conf.get(FlinkOptions.PARTITION_PATH_FIELD)); + assertEquals("event_ts,seq_no", conf.get(FlinkOptions.ORDERING_FIELDS)); + assertEquals(7, conf.get(FlinkOptions.RETRY_TIMES)); + assertEquals(250L, conf.get(FlinkOptions.RETRY_INTERVAL_MS)); Review Comment: This codifies a unit mismatch: the CLI option is documented in seconds, but `RETRY_INTERVAL_MS` is milliseconds. Please clarify the contract and convert or rename the option accordingly. ########## hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/streamer/TestFlinkStreamerConfig.java: ########## @@ -0,0 +1,145 @@ +/* + * 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.hudi.streamer; + +import org.apache.hudi.common.model.WriteOperationType; +import org.apache.hudi.configuration.FlinkOptions; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.ParameterException; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for {@link FlinkStreamerConfig}. + */ +class TestFlinkStreamerConfig { + + @TempDir + Path tempDir; + + @Test + void testParseAndDeriveFlinkConfiguration() { + FlinkStreamerConfig config = parse( + "--kafka-topic", "orders", + "--kafka-group-id", "flink-writers", + "--kafka-bootstrap-servers", "broker:9092", + "--target-base-path", tempDir.toString(), + "--target-table", "orders_hudi", + "--table-type", "merge_on_read", + "--op", "INSERT", + "--record-key-field", "order_id", + "--partition-path-field", "order_date", + "--source-ordering-fields", "event_ts,seq_no", + "--instant-retry-times", "7", + "--instant-retry-interval", "250", + "--filter-dupes", + "--commit-on-errors", + "--metadata-enabled", + "--write-rate-limit", "500", + "--write-task-num", "6", + "--bucket-assign-num", "5", + "--index-bootstrap-num", "4", + "--source-avro-schema-path", "file:///tmp/source.avsc", + "--source-avro-schema", "{\"type\":\"record\",\"name\":\"order\",\"fields\":[]}", + "--compaction-tasks", "3", + "--clustering-tasks", "2", + "--hive-sync-enable", + "--hive-sync-db", "analytics", + "--hive-sync-table", "orders", + "--hoodie-conf", "hoodie.datasource.write.drop.partition.columns=true"); + + Configuration conf = FlinkStreamerConfig.toFlinkConfig(config); + + assertEquals(tempDir.toString(), conf.get(FlinkOptions.PATH)); + assertEquals("orders_hudi", conf.get(FlinkOptions.TABLE_NAME)); + assertEquals("MERGE_ON_READ", conf.get(FlinkOptions.TABLE_TYPE)); + assertEquals(WriteOperationType.INSERT.value(), conf.get(FlinkOptions.OPERATION)); + assertEquals("order_id", conf.get(FlinkOptions.RECORD_KEY_FIELD)); + assertEquals("order_date", conf.get(FlinkOptions.PARTITION_PATH_FIELD)); + assertEquals("event_ts,seq_no", conf.get(FlinkOptions.ORDERING_FIELDS)); + assertEquals(7, conf.get(FlinkOptions.RETRY_TIMES)); + assertEquals(250L, conf.get(FlinkOptions.RETRY_INTERVAL_MS)); + assertTrue(conf.get(FlinkOptions.PRE_COMBINE)); + assertTrue(conf.get(FlinkOptions.IGNORE_FAILED)); + assertTrue(conf.get(FlinkOptions.METADATA_ENABLED)); + assertEquals(500L, conf.get(FlinkOptions.WRITE_RATE_LIMIT)); + assertEquals(6, conf.get(FlinkOptions.WRITE_TASKS)); + assertEquals(5, conf.get(FlinkOptions.BUCKET_ASSIGN_TASKS)); + assertEquals(4, conf.get(FlinkOptions.INDEX_BOOTSTRAP_TASKS)); + assertEquals("file:///tmp/source.avsc", conf.get(FlinkOptions.SOURCE_AVRO_SCHEMA_PATH)); + assertEquals(3, conf.get(FlinkOptions.COMPACTION_TASKS)); + assertEquals(2, conf.get(FlinkOptions.CLUSTERING_TASKS)); + assertTrue(conf.get(FlinkOptions.HIVE_SYNC_ENABLED)); + assertEquals("analytics", conf.get(FlinkOptions.HIVE_SYNC_DB)); + assertEquals("orders", conf.get(FlinkOptions.HIVE_SYNC_TABLE)); + assertEquals("hoodie.datasource.write.drop.partition.columns=true", config.configs.get(0)); Review Comment: Could this assert that `--hoodie-conf` reaches the derived `Configuration`? Without `--props`, `StreamerUtil.getProps(FlinkStreamerConfig)` currently returns empty properties and drops `config.configs`. Please fix that path and assert the resulting `drop.partition.columns` value here. ########## hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/clustering/TestFlinkClusteringConfig.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.hudi.sink.clustering; + +import org.apache.hudi.configuration.FlinkOptions; +import org.apache.hudi.util.StreamerUtil; +import org.apache.hudi.utils.TestConfigurations; + +import com.beust.jcommander.JCommander; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for {@link FlinkClusteringConfig}. + */ +class TestFlinkClusteringConfig { + + @TempDir + Path tempDir; + + @Test + void testParseAndDeriveFlinkConfiguration() throws Exception { + Configuration tableConf = TestConfigurations.getDefaultConf(tempDir.toString()); + tableConf.set(FlinkOptions.URL_ENCODE_PARTITIONING, true); + tableConf.set(FlinkOptions.HIVE_STYLE_PARTITIONING, true); + StreamerUtil.initTableIfNotExists(tableConf); + + FlinkClusteringConfig config = new FlinkClusteringConfig(); + JCommander.newBuilder().addObject(config).build().parse( + "--path", tempDir.toString(), + "--clustering-delta-commits", "6", + "--clustering-tasks", "4", + "--clean-retain-commits", "12", + "--clean-retain-hours", "36", + "--clean-retain-file-versions", "7", + "--archive-min-commits", "25", + "--archive-max-commits", "40", + "--schedule", + "--clean-async-enabled", + "--plan-partition-filter-mode", "RECENT_DAYS", + "--target-file-max-bytes", "1048576", + "--small-file-limit", "524288", + "--skip-from-latest-partitions", "2", + "--sort-columns", "event_ts,order_id", + "--sort-memory", "256", + "--max-num-groups", "10", + "--target-partitions", "5", + "--cluster-begin-partition", "2026-01-01", Review Comment: Please assert the derived begin/end partition, regex, and selected-partition values. These arguments are supplied but never verified, so broken mappings would still pass. -- 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]
