Au-Miner commented on code in PR #27117:
URL: https://github.com/apache/flink/pull/27117#discussion_r2480163890
##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/test/program/SinkTestStep.java:
##########
@@ -108,16 +116,40 @@ public List<String> getExpectedAfterRestoreAsStrings() {
}
public List<String> getExpectedAsStrings() {
- final List<String> data = new
ArrayList<>(getExpectedBeforeRestoreAsStrings());
- data.addAll(getExpectedAfterRestoreAsStrings());
- return data;
+ if (hasStringsSet() || deduplicatedFieldIndices == null) {
+ final List<String> data = new
ArrayList<>(getExpectedBeforeRestoreAsStrings());
+ data.addAll(getExpectedAfterRestoreAsStrings());
+ return data;
+ }
+ Preconditions.checkState(hasRowsSet());
+ final List<Row> data = new ArrayList<>();
+ if (expectedBeforeRestore != null) {
+ data.addAll(expectedBeforeRestore);
+ }
+ if (expectedAfterRestore != null) {
+ data.addAll(expectedAfterRestore);
+ }
+
+ Map<List<Object>, Row> deduplicatedMap = new HashMap<>();
Review Comment:
The logic in this section, which uses deduplicatedFieldIndices to modify
expectedBeforeRestore and expectedAfterRestore, can also be implemented by
calling a function in getExpectedBeforeRestoreAsStrings and
getExpectedAfterRestoreAsStrings. Of course, it's up to you, but I personally
find the latter easier to understand
##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/test/program/SinkTestStep.java:
##########
@@ -108,16 +116,40 @@ public List<String> getExpectedAfterRestoreAsStrings() {
}
public List<String> getExpectedAsStrings() {
- final List<String> data = new
ArrayList<>(getExpectedBeforeRestoreAsStrings());
- data.addAll(getExpectedAfterRestoreAsStrings());
- return data;
+ if (hasStringsSet() || deduplicatedFieldIndices == null) {
Review Comment:
Will there be a situation where hasStringsSet() is false, hasRowsSet() is
false, but deduplicatedFieldIndices is not null.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/DeltaJoinTestPrograms.java:
##########
@@ -0,0 +1,426 @@
+/*
+ * 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.stream;
+
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.api.config.OptimizerConfigOptions;
+import org.apache.flink.table.test.program.SinkTestStep;
+import org.apache.flink.table.test.program.SourceTestStep;
+import org.apache.flink.table.test.program.TableTestProgram;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/** {@link TableTestProgram} definitions for testing {@link
StreamExecDeltaJoin}. */
+public class DeltaJoinTestPrograms {
+
+ static final String[] LEFT_TABLE_BASE_SCHEMA =
+ new String[] {"a1 int", "a0 double", "a2 string"};
+
+ static final String[] RIGHT_TABLE_BASE_SCHEMA =
+ new String[] {"b0 double", "b2 string", "b1 int"};
+
+ static final String[] SINK_TABLE_BASE_SCHEMA =
+ Stream.concat(
+ Arrays.stream(LEFT_TABLE_BASE_SCHEMA),
+ Arrays.stream(RIGHT_TABLE_BASE_SCHEMA))
+ .toArray(String[]::new);
+
+ static final Map<String, String> TABLE_BASE_OPTIONS =
+ Map.of("async", "true", "sink-insert-only", "false");
+
+ public static final TableTestProgram DELTA_JOIN_WITH_JOIN_KEY_EQUALS_INDEX
=
+ TableTestProgram.of(
+ "delta-join-with-join-key-equals-index",
+ "validates delta join with join key equals index")
+ .setupConfig(
+
OptimizerConfigOptions.TABLE_OPTIMIZER_DELTA_JOIN_STRATEGY,
+ OptimizerConfigOptions.DeltaJoinStrategy.FORCE)
+ .setupTableSource(
+ SourceTestStep.newBuilder("leftSrc")
+ .addSchema(LEFT_TABLE_BASE_SCHEMA)
+ .addOptions(TABLE_BASE_OPTIONS)
+ .addIndex("a1")
+ .treatDataBeforeRestoreAsFullStageData()
+ .producedBeforeRestore(
+ Row.of(1, 1.0, "l-1-1"),
+ Row.of(1, 1.0, "l-1-2"),
+ Row.of(5, 5.0, "l-5-1"))
+ .producedAfterRestore(
+ Row.of(3, 3.0, "l-3-1"),
+ Row.of(3, 3.0, "l-3-2"),
+ Row.of(5, 5.0, "l-5-2"))
+ .build())
+ .setupTableSource(
+ SourceTestStep.newBuilder("rightSrc")
+ .addSchema(RIGHT_TABLE_BASE_SCHEMA)
+ .addOptions(TABLE_BASE_OPTIONS)
+ .addIndex("b1")
+ .treatDataBeforeRestoreAsFullStageData()
Review Comment:
ditto, the same goes for the following.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/TestValuesTableFactory.java:
##########
@@ -195,6 +195,10 @@ public final class TestValuesTableFactory
private static final AtomicInteger idCounter = new AtomicInteger(0);
private static final Map<String, Collection<Row>> registeredData = new
HashMap<>();
private static final Map<String, Collection<RowData>> registeredRowData =
new HashMap<>();
+ // The difference between registeredDataForFullStage and `registeredData`
is that
+ // `registeredData` is used for data delivered from the source to
downstream, while the rows in
+ // `registeredDataForFullStage` will not be sent to downstream and are
only used for lookup.
+ private static final Map<String, Collection<Row>>
registeredDataForFullStage = new HashMap<>();
Review Comment:
I'm curious why it's named `registeredDataForFullStage` instead of
`ForCurrentStage` or `ForCurrentTable`
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/DeltaJoinTestPrograms.java:
##########
@@ -0,0 +1,426 @@
+/*
+ * 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.stream;
+
+import org.apache.flink.table.api.config.ExecutionConfigOptions;
+import org.apache.flink.table.api.config.OptimizerConfigOptions;
+import org.apache.flink.table.test.program.SinkTestStep;
+import org.apache.flink.table.test.program.SourceTestStep;
+import org.apache.flink.table.test.program.TableTestProgram;
+import org.apache.flink.types.Row;
+import org.apache.flink.types.RowKind;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/** {@link TableTestProgram} definitions for testing {@link
StreamExecDeltaJoin}. */
+public class DeltaJoinTestPrograms {
+
+ static final String[] LEFT_TABLE_BASE_SCHEMA =
+ new String[] {"a1 int", "a0 double", "a2 string"};
+
+ static final String[] RIGHT_TABLE_BASE_SCHEMA =
+ new String[] {"b0 double", "b2 string", "b1 int"};
+
+ static final String[] SINK_TABLE_BASE_SCHEMA =
+ Stream.concat(
+ Arrays.stream(LEFT_TABLE_BASE_SCHEMA),
+ Arrays.stream(RIGHT_TABLE_BASE_SCHEMA))
+ .toArray(String[]::new);
+
+ static final Map<String, String> TABLE_BASE_OPTIONS =
+ Map.of("async", "true", "sink-insert-only", "false");
+
+ public static final TableTestProgram DELTA_JOIN_WITH_JOIN_KEY_EQUALS_INDEX
=
+ TableTestProgram.of(
+ "delta-join-with-join-key-equals-index",
+ "validates delta join with join key equals index")
+ .setupConfig(
+
OptimizerConfigOptions.TABLE_OPTIMIZER_DELTA_JOIN_STRATEGY,
+ OptimizerConfigOptions.DeltaJoinStrategy.FORCE)
+ .setupTableSource(
+ SourceTestStep.newBuilder("leftSrc")
+ .addSchema(LEFT_TABLE_BASE_SCHEMA)
+ .addOptions(TABLE_BASE_OPTIONS)
+ .addIndex("a1")
+ .treatDataBeforeRestoreAsFullStageData()
Review Comment:
We can follow the order below: either place
"treatDataBeforeRestoreAsFullStageData" after "producedAfterRestore", or modify
the parameter order of SourceTestStep
--
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]