Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flink] partial-update merge engine support batch deletion using flink sql #4273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,10 @@ public List<String> sequenceField() {
.orElse(Collections.emptyList());
}

public boolean partialUpdateRemoveRecordOnDelete() {
return options.get(PARTIAL_UPDATE_REMOVE_RECORD_ON_DELETE);
}

public Optional<String> rowkindField() {
return options.getOptional(ROWKIND_FIELD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,17 @@ private void validateDeletable() {
table.getClass().getName()));
}

MergeEngine mergeEngine = CoreOptions.fromMap(table.options()).mergeEngine();
if (mergeEngine != DEDUPLICATE) {
throw new UnsupportedOperationException(
String.format("Merge engine %s can not support batch delete.", mergeEngine));
CoreOptions coreOptions = CoreOptions.fromMap(table.options());
if (coreOptions.mergeEngine() == DEDUPLICATE
|| (coreOptions.mergeEngine() == PARTIAL_UPDATE
&& coreOptions.partialUpdateRemoveRecordOnDelete())) {
return;
}

throw new UnsupportedOperationException(
String.format(
"Merge engine %s can not support batch delete.",
coreOptions.mergeEngine()));
}

private boolean canPushDownDeleteFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,29 @@ public void testIgnoreDelete(boolean localMerge) throws Exception {
Row.ofKind(RowKind.UPDATE_AFTER, 1, "A", "apple"));
iterator.close();
}

@Test
public void testRemoveRecordOnDelete() {
sql(
"CREATE TABLE remove_record_on_delete (pk INT PRIMARY KEY NOT ENFORCED, a STRING, b STRING) WITH ("
+ " 'merge-engine' = 'partial-update',"
+ " 'partial-update.remove-record-on-delete' = 'true'"
+ ")");

sql("INSERT INTO remove_record_on_delete VALUES (1, CAST (NULL AS STRING), 'apple')");

// delete record
sql("DELETE FROM remove_record_on_delete WHERE pk = 1");

// batch read
assertThat(sql("SELECT * FROM remove_record_on_delete")).isEmpty();

// insert records
sql("INSERT INTO remove_record_on_delete VALUES (1, CAST (NULL AS STRING), 'apache')");
sql("INSERT INTO remove_record_on_delete VALUES (1, 'A', CAST (NULL AS STRING))");

// batch read
assertThat(sql("SELECT * FROM remove_record_on_delete"))
.containsExactlyInAnyOrder(Row.of(1, "A", "apache"));
}
}
Loading