gustavodemorais commented on code in PR #29987: URL: https://github.com/apache/flink/pull/29987#discussion_r4599713141
########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/InputPropertyTest.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.nodes.exec; + +import org.apache.flink.table.annotation.ArgumentHint; +import org.apache.flink.table.annotation.ArgumentTrait; +import org.apache.flink.table.api.EnvironmentSettings; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.api.TableDescriptor; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.table.functions.ProcessTableFunction; +import org.apache.flink.table.planner.utils.JsonTestUtils; +import org.apache.flink.types.Row; + +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests that physical nodes declare the input distribution requested by their physical rule in + * their {@link InputProperty}s. Covers nodes that request a distribution only conditionally. + */ +class InputPropertyTest { + + private static final String SINGLETON = "SINGLETON"; + private static final String UNKNOWN = "UNKNOWN"; + + static Stream<Arguments> testCases() { + return Stream.of( + // window table functions request a distribution only for session windows + Arguments.of( + "SELECT * FROM SESSION(TABLE T, DESCRIPTOR(ts), INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of(SINGLETON)), + Arguments.of( + "SELECT * FROM SESSION(TABLE T PARTITION BY k, DESCRIPTOR(ts), " + + "INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of("HASH[1]")), + Arguments.of( + "SELECT * FROM TUMBLE(TABLE T, DESCRIPTOR(ts), INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of(UNKNOWN)), + // lookup joins request a distribution only for the hash shuffle of the LOOKUP hint + Arguments.of( + "SELECT /*+ LOOKUP('table'='D', 'shuffle'='true') */ T.i FROM T " + + "JOIN D FOR SYSTEM_TIME AS OF T.proc ON T.k = D.k", + "stream-exec-lookup-join", + List.of("HASH[1]")), + Arguments.of( + "SELECT T.i FROM T JOIN D FOR SYSTEM_TIME AS OF T.proc ON T.k = D.k", + "stream-exec-lookup-join", + List.of(UNKNOWN)), + // PTFs request a distribution for table arguments with set semantics + Arguments.of( + "SELECT * FROM SetSemanticFunction(input => TABLE U)", + "stream-exec-process-table-function", + List.of(SINGLETON)), + Arguments.of( + "SELECT * FROM SetSemanticFunction(input => TABLE U PARTITION BY k)", + "stream-exec-process-table-function", + List.of("HASH[0]")), + // nodes that always request a distribution + Arguments.of( + "SELECT a.i, b.i AS j FROM T a JOIN T b ON a.k = b.k", + "stream-exec-join", + List.of("HASH[1]", "HASH[1]")), + // batch nodes with a strictly requested distribution + Arguments.of( + "SELECT * FROM T MATCH_RECOGNIZE (ORDER BY ts MEASURES A.i AS ai " + + "PATTERN (A) DEFINE A AS A.i > 0)", + "batch-exec-match", + List.of(SINGLETON)), + Arguments.of( + "SELECT * FROM T MATCH_RECOGNIZE (PARTITION BY k ORDER BY ts " + + "MEASURES A.i AS ai PATTERN (A) DEFINE A AS A.i > 0)", + "batch-exec-match", + List.of("HASH[1]")), + Arguments.of( + "SELECT /*+ LOOKUP('table'='D', 'shuffle'='true') */ T.i FROM T " + + "JOIN D FOR SYSTEM_TIME AS OF T.proc ON T.k = D.k", + "batch-exec-lookup-join", + List.of("HASH[1]")), + // batch sorts only declare a singleton distribution + Arguments.of("SELECT * FROM T ORDER BY i", "batch-exec-sort", List.of(SINGLETON)), + Arguments.of( Review Comment: nit: the "batch sort on a hash input" case seems to check the wrong Sort (the helper returns a single node), so it can't fail. ########## flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/nodes/physical/common/CommonPhysicalLookupJoin.scala: ########## @@ -155,6 +156,16 @@ abstract class CommonPhysicalLookupJoin( Collections.emptyList[RelDataTypeField]) } + /** Only the hash shuffle of the LOOKUP hint requests a distribution of the input. */ + protected def deriveInputProperty(): InputProperty = { Review Comment: nit: could `deriveInputProperty` also require a non-empty join key condition, like the rule does, so the declaration matches the rule's request exactly? ########## flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/InputPropertyTest.java: ########## @@ -0,0 +1,189 @@ +/* + * 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.nodes.exec; + +import org.apache.flink.table.annotation.ArgumentHint; +import org.apache.flink.table.annotation.ArgumentTrait; +import org.apache.flink.table.api.EnvironmentSettings; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.api.TableDescriptor; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.table.functions.ProcessTableFunction; +import org.apache.flink.table.planner.utils.JsonTestUtils; +import org.apache.flink.types.Row; + +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests that physical nodes declare the input distribution requested by their physical rule in + * their {@link InputProperty}s. Covers nodes that request a distribution only conditionally. + */ +class InputPropertyTest { + + private static final String SINGLETON = "SINGLETON"; + private static final String UNKNOWN = "UNKNOWN"; + + static Stream<Arguments> testCases() { + return Stream.of( + // window table functions request a distribution only for session windows + Arguments.of( + "SELECT * FROM SESSION(TABLE T, DESCRIPTOR(ts), INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of(SINGLETON)), + Arguments.of( + "SELECT * FROM SESSION(TABLE T PARTITION BY k, DESCRIPTOR(ts), " + + "INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of("HASH[1]")), + Arguments.of( + "SELECT * FROM TUMBLE(TABLE T, DESCRIPTOR(ts), INTERVAL '1' MINUTE)", + "stream-exec-window-table-function", + List.of(UNKNOWN)), + // lookup joins request a distribution only for the hash shuffle of the LOOKUP hint + Arguments.of( + "SELECT /*+ LOOKUP('table'='D', 'shuffle'='true') */ T.i FROM T " + + "JOIN D FOR SYSTEM_TIME AS OF T.proc ON T.k = D.k", + "stream-exec-lookup-join", + List.of("HASH[1]")), + Arguments.of( + "SELECT T.i FROM T JOIN D FOR SYSTEM_TIME AS OF T.proc ON T.k = D.k", + "stream-exec-lookup-join", + List.of(UNKNOWN)), + // PTFs request a distribution for table arguments with set semantics + Arguments.of( + "SELECT * FROM SetSemanticFunction(input => TABLE U)", + "stream-exec-process-table-function", + List.of(SINGLETON)), + Arguments.of( + "SELECT * FROM SetSemanticFunction(input => TABLE U PARTITION BY k)", + "stream-exec-process-table-function", + List.of("HASH[0]")), + // nodes that always request a distribution + Arguments.of( Review Comment: Most of the unconditional stream declarations (aggregates, window aggregate, over, rank/deduplicate, sort limit, window join/rank/deduplicate, temporal join) have no test that fails if they revert to `InputProperty.DEFAULT`. Since these cases are cheap, would it make sense to add one per declaring node type, with a SINGLETON and a HASH variant where the rule distinguishes them? That way the bug can't sneak back in by accident. -- 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]
