-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-38201] SinkUpsertMaterializer should not be inserted for retract sinks #26879
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...rc/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/SinkSemanticTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.planner.plan.nodes.exec.testutils.SemanticTestBase; | ||
import org.apache.flink.table.test.program.TableTestProgram; | ||
|
||
import java.util.List; | ||
|
||
/** Semantic tests for {@link StreamExecSink}. */ | ||
public class SinkSemanticTests extends SemanticTestBase { | ||
|
||
@Override | ||
public List<TableTestProgram> programs() { | ||
return List.of( | ||
SinkTestPrograms.INSERT_RETRACT_WITHOUT_PK, | ||
SinkTestPrograms.INSERT_RETRACT_WITH_PK); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...src/test/java/org/apache/flink/table/planner/plan/nodes/exec/stream/SinkTestPrograms.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* 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.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; | ||
|
||
/** Tests for verifying sink semantics. */ | ||
public class SinkTestPrograms { | ||
|
||
public static final TableTestProgram INSERT_RETRACT_WITHOUT_PK = | ||
TableTestProgram.of( | ||
"insert-retract-without-pk", | ||
"The sink accepts retract input. Retract is directly passed through.") | ||
.setupTableSource( | ||
SourceTestStep.newBuilder("source_t") | ||
.addSchema("name STRING", "score INT") | ||
.addOption("changelog-mode", "I") | ||
.producedValues( | ||
Row.ofKind(RowKind.INSERT, "Alice", 3), | ||
Row.ofKind(RowKind.INSERT, "Bob", 5), | ||
Row.ofKind(RowKind.INSERT, "Bob", 6), | ||
Row.ofKind(RowKind.INSERT, "Charly", 33)) | ||
.build()) | ||
.setupTableSink( | ||
SinkTestStep.newBuilder("sink_t") | ||
.addSchema("name STRING", "score BIGINT") | ||
.addOption("sink-changelog-mode-enforced", "I,UB,UA,D") | ||
.consumedValues( | ||
"+I[Alice, 3]", | ||
"+I[Bob, 5]", | ||
"-U[Bob, 5]", | ||
"+U[Bob, 11]", | ||
"+I[Charly, 33]") | ||
.build()) | ||
.runSql( | ||
"INSERT INTO sink_t SELECT name, SUM(score) FROM source_t GROUP BY name") | ||
.build(); | ||
|
||
public static final TableTestProgram INSERT_RETRACT_WITH_PK = | ||
TableTestProgram.of( | ||
"insert-retract-with-pk", | ||
"The sink accepts retract input. Although upsert keys (name) and primary keys (UPPER(name))" | ||
+ "don't match, the retract changelog is passed through.") | ||
.setupTableSource( | ||
SourceTestStep.newBuilder("source_t") | ||
.addSchema("name STRING", "score INT") | ||
.addOption("changelog-mode", "I") | ||
.producedValues( | ||
Row.ofKind(RowKind.INSERT, "Alice", 3), | ||
Row.ofKind(RowKind.INSERT, "Bob", 5), | ||
Row.ofKind(RowKind.INSERT, "Bob", 6), | ||
Row.ofKind(RowKind.INSERT, "Charly", 33)) | ||
.build()) | ||
.setupTableSink( | ||
SinkTestStep.newBuilder("sink_t") | ||
.addSchema( | ||
"name STRING PRIMARY KEY NOT ENFORCED", "score BIGINT") | ||
.addOption("sink-changelog-mode-enforced", "I,UB,UA,D") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably just have added a plan test to check that SUM is not added anymore. Do we usually prefer semantic tests over to plan tests or is it just a matter of preference? |
||
.consumedValues( | ||
"+I[ALICE, 3]", | ||
"+I[BOB, 5]", | ||
"-U[BOB, 5]", | ||
"+U[BOB, 11]", | ||
"+I[CHARLY, 33]") | ||
.build()) | ||
.runSql( | ||
"INSERT INTO sink_t SELECT UPPER(name), SUM(score) FROM source_t GROUP BY name") | ||
.build(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the two changes
UpsertMaterialize.FORCE
is used? Is it safe to "not respect" the force here?