MartijnVisser commented on code in PR #29003: URL: https://github.com/apache/flink/pull/29003#discussion_r3841640457
########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/SortValidationTest.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.TableException; +import org.apache.flink.table.planner.utils.InternalConfigOptions; +import org.apache.flink.table.planner.utils.JavaStreamTableTestUtil; +import org.apache.flink.table.planner.utils.TableTestBase; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Plan-time validation tests for streaming sort. A non-time-attribute sort is unsupported and must + * be rejected during optimization (so it surfaces at {@code COMPILE PLAN} / planning time), not + * deferred to execution-plan translation. Valid temporal sorts are covered by {@code SortTest}. + */ +class SortValidationTest extends TableTestBase { Review Comment: Good question — I looked into migrating this to the semantic test framework (`SemanticTestBase` / `TableTestProgram`), but it does not fit this particular test: * `runFailingSql` only accepts `ValidationException` or `TableRuntimeException` (hard `Preconditions` check in `FailingSqlTestStep`), while this check throws `TableException` — the same type the previous execution-time check threw, so I would rather not change the user-facing exception type in this PR. * Three of the assertions here have no equivalent test step: the `table.exec.non-temporal-sort.enabled` escape hatch (asserting *no* exception), the `COMPILE PLAN` check via `compilePlanSql`, and asserting the message names the column and its type. Since `*ValidationTest` classes extending `TableTestBase` are still the established pattern for planning-time rejections (e.g. the batch `SortValidationTest`, `AggregateValidationTest`), I would prefer to keep this as-is. Happy to revisit in a follow-up if we relax the exception-type restriction in `FailingSqlTestStep`. ########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/SortValidationTest.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.TableException; +import org.apache.flink.table.planner.utils.InternalConfigOptions; +import org.apache.flink.table.planner.utils.JavaStreamTableTestUtil; +import org.apache.flink.table.planner.utils.TableTestBase; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Plan-time validation tests for streaming sort. A non-time-attribute sort is unsupported and must + * be rejected during optimization (so it surfaces at {@code COMPILE PLAN} / planning time), not + * deferred to execution-plan translation. Valid temporal sorts are covered by {@code SortTest}. + */ +class SortValidationTest extends TableTestBase { + + private static final String MESSAGE = + "requires the primary sort key to be a time attribute in ascending order"; + private static final String MESSAGE_DESC = + "must be sorted in ascending order; descending order is not supported"; + + private final JavaStreamTableTestUtil util = javaStreamTestUtil(); + + @BeforeEach + void setup() { + util.addTable( + "CREATE TABLE MyTable (\n" + + " a INT,\n" + + " b STRING,\n" + + " c BIGINT,\n" + + " proctime AS PROCTIME(),\n" + + " rowtime TIMESTAMP(3),\n" + + " WATERMARK FOR rowtime AS rowtime\n" + + ") WITH ('connector' = 'values')"); + } + + static Stream<Arguments> nonTemporalSorts() { + return Stream.of( + // primary sort key is not a time attribute -> message A + Arguments.of("SELECT a FROM MyTable ORDER BY c", MESSAGE), Review Comment: Good point. Ordinals and aliases are expanded by the SQL validator before optimization, so they hit the same rule — but explicit coverage is cheap. I have added negative cases for `ORDER BY <ordinal>`, `ORDER BY <alias>`, and `ORDER BY <time-attribute alias> DESC`, plus a positive case in `SortTest` showing that an alias of `rowtime` still routes to the temporal sort. -- 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]
