diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/ClientOptionsAugTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/ClientOptionsAugTest.java new file mode 100644 index 00000000000..a8d6a1b885d --- /dev/null +++ b/flink-clients/src/test/java/org/apache/flink/client/cli/ClientOptionsAugTest.java @@ -0,0 +1,46 @@ +/* + * 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.client.cli; + +import org.apache.flink.configuration.Configuration; + +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Additional regression coverage for unchanged client option configuration behavior. */ +class ClientOptionsAugTest { + + @Test + void testClientTimeoutCopyKeepsConfigurationsIndependent() { + final Configuration original = new Configuration(); + original.set(ClientOptions.CLIENT_TIMEOUT, Duration.ofSeconds(3)); + + final Configuration copy = new Configuration(original); + copy.set(ClientOptions.CLIENT_TIMEOUT, Duration.ofSeconds(7)); + + assertThat(original.get(ClientOptions.CLIENT_TIMEOUT)) + .isEqualTo(Duration.ofSeconds(3)); + assertThat(copy.get(ClientOptions.CLIENT_TIMEOUT)).isEqualTo(Duration.ofSeconds(7)); + assertThat(new Configuration().get(ClientOptions.CLIENT_TIMEOUT)) + .isEqualTo(ClientOptions.CLIENT_TIMEOUT.defaultValue()); + } +} diff --git a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/FromChangelogAugmentedValidationTest.java b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/FromChangelogAugmentedValidationTest.java new file mode 100644 index 00000000000..d8e4fa8dc0c --- /dev/null +++ b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/FromChangelogAugmentedValidationTest.java @@ -0,0 +1,118 @@ +/* + * 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.stream.sql; + +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.planner.plan.nodes.exec.stream.ProcessTableFunctionTestUtils.InvalidUpdatingSemanticsFunction; +import org.apache.flink.table.planner.utils.TableTestBase; +import org.apache.flink.table.planner.utils.TableTestUtil; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** Additional SQL validation tests for the FROM_CHANGELOG public process table function surface. */ +public class FromChangelogAugmentedValidationTest extends TableTestBase { + + private TableTestUtil util; + + @BeforeEach + void setup() { + util = streamTestUtil(TableConfig.getDefault()); + util.tableEnv() + .executeSql( + "CREATE VIEW t AS SELECT * FROM " + + "(VALUES ('Bob', 12), ('Alice', 42)) AS T(name, score)"); + } + + @Test + void testRejectsEmptyOpDescriptor() { + createCdcStream("op STRING"); + assertInvalidFromChangelog( + "SELECT * FROM FROM_CHANGELOG(" + + "input => TABLE cdc_stream, " + + "op => DESCRIPTOR())", + "The descriptor for argument 'op' must contain exactly one column name."); + } + + @Test + void testRejectsNonStringOpColumn() { + createCdcStream("op INT"); + assertInvalidFromChangelog( + "SELECT * FROM FROM_CHANGELOG(input => TABLE cdc_stream)", + "The op column 'op' must be of STRING type"); + } + + @Test + void testRejectsDynamicOpMapping() { + createCdcStream("op STRING"); + assertInvalidFromChangelog( + "SELECT * FROM FROM_CHANGELOG(" + + "input => TABLE cdc_stream, " + + "op_mapping => MAP[UPPER('c'), 'INSERT'])", + "The 'op_mapping' argument must be a constant MAP literal."); + } + + @Test + void testRejectsInvalidRowKindMapping() { + createCdcStream("op STRING"); + assertInvalidFromChangelog( + "SELECT * FROM FROM_CHANGELOG(" + + "input => TABLE cdc_stream, " + + "op_mapping => MAP['x', 'UPSERT'])", + "Unknown change operation: 'UPSERT'"); + } + + @Test + void testRejectsDuplicateRowKindMapping() { + createCdcStream("op STRING"); + assertInvalidFromChangelog( + "SELECT * FROM FROM_CHANGELOG(" + + "input => TABLE cdc_stream, " + + "op_mapping => MAP['c', 'INSERT', 'r', 'INSERT'])", + "Duplicate change operation: 'INSERT'"); + } + + @Test + void testRejectsUpsertOutputForRowSemanticTableArguments() { + util.addTemporarySystemFunction("f", InvalidUpdatingSemanticsFunction.class); + assertThatThrownBy(() -> util.verifyExecPlan("SELECT * FROM f(r => TABLE t)")) + .satisfies( + anyCauseMatches( + "PTFs that take table arguments with row semantics don't support upsert output. " + + "Table argument 'r' of function 'f' must use set semantics.")); + } + + private void createCdcStream(String opColumnDefinition) { + util.tableEnv() + .executeSql( + "CREATE TABLE cdc_stream (" + + " id INT," + + opColumnDefinition + + ", name STRING" + + ") WITH ('connector' = 'values')"); + } + + private void assertInvalidFromChangelog(String sql, String message) { + assertThatThrownBy(() -> util.tableEnv().explainSql(sql)) + .satisfies(anyCauseMatches(message)); + } +}