Skip to content
Merged
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 @@ -266,9 +266,10 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext<Void> context)
new SpecialFormExpression(SpecialFormExpression.Form.IS_NULL, BooleanType.BOOLEAN,
new SpecialFormExpression(SpecialFormExpression.Form.COALESCE, BigintType.BIGINT, deleteVersionColumns)));

boolean hasExplicitDataSequenceNumberCol = node.getAssignments().containsValue(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE);
Assignments.Builder assignmentsBuilder = Assignments.builder();
filter.getOutputVariables().stream()
.filter(variableReferenceExpression -> !variableReferenceExpression.getName().startsWith(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE.getName()))
.filter(variableReferenceExpression -> hasExplicitDataSequenceNumberCol || !variableReferenceExpression.getName().startsWith(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE.getName()))
.forEach(variableReferenceExpression -> assignmentsBuilder.put(variableReferenceExpression, variableReferenceExpression));
return new ProjectNode(Optional.empty(), idAllocator.getNextId(), filter, assignmentsBuilder.build(), ProjectNode.Locality.LOCAL);
}
Expand Down Expand Up @@ -368,12 +369,12 @@ private TableScanNode createNewRoot(TableScanNode node, IcebergTableHandle icebe

VariableReferenceExpression dataSequenceNumberVariableReference = toVariableReference(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE);
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignmentsBuilder = ImmutableMap.<VariableReferenceExpression, ColumnHandle>builder()
.put(dataSequenceNumberVariableReference, DATA_SEQUENCE_NUMBER_COLUMN_HANDLE)
.putAll(unselectedAssignments)
.putAll(node.getAssignments());
ImmutableList.Builder<VariableReferenceExpression> outputsBuilder = ImmutableList.builder();
outputsBuilder.addAll(node.getOutputVariables());
if (!node.getAssignments().containsKey(dataSequenceNumberVariableReference)) {
if (!node.getAssignments().containsValue(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE)) {
assignmentsBuilder.put(dataSequenceNumberVariableReference, DATA_SEQUENCE_NUMBER_COLUMN_HANDLE);
outputsBuilder.add(dataSequenceNumberVariableReference);
}
outputsBuilder.addAll(unselectedAssignments.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,36 @@ public void testEqualityDeletesWithHiddenPartitionsEvolution(String fileFormat,
assertQuery(session, "SELECT * FROM " + tableName, "VALUES (1, '1001', NULL, NULL), (3, '1003', NULL, NULL), (6, '1004', 1, NULL), (6, '1006', 2, 'th002')");
}

@Test(dataProvider = "equalityDeleteOptions")
public void testEqualityDeletesWithDataSequenceNumber(String fileFormat, boolean joinRewriteEnabled)
throws Exception
{
Session session = deleteAsJoinEnabled(joinRewriteEnabled);
String tableName = "test_v2_row_delete_" + randomTableSuffix();
String tableName2 = "test_v2_row_delete_2_" + randomTableSuffix();
assertUpdate("CREATE TABLE " + tableName + "(id int, data varchar) WITH (\"write.format.default\" = '" + fileFormat + "')");
assertUpdate("INSERT INTO " + tableName + " VALUES (1, 'a')", 1);

assertUpdate("CREATE TABLE " + tableName2 + "(id int, data varchar) WITH (\"write.format.default\" = '" + fileFormat + "')");
assertUpdate("INSERT INTO " + tableName2 + " VALUES (1, 'a')", 1);

Table icebergTable = updateTable(tableName);
writeEqualityDeleteToNationTable(icebergTable, ImmutableMap.of("id", 1));

Table icebergTable2 = updateTable(tableName2);
writeEqualityDeleteToNationTable(icebergTable2, ImmutableMap.of("id", 1));

assertUpdate("INSERT INTO " + tableName + " VALUES (1, 'b'), (2, 'a'), (3, 'a')", 3);
assertUpdate("INSERT INTO " + tableName2 + " VALUES (1, 'b'), (2, 'a'), (3, 'a')", 3);

assertQuery(session, "SELECT * FROM " + tableName, "VALUES (1, 'b'), (2, 'a'), (3, 'a')");

assertQuery(session, "SELECT \"$data_sequence_number\", * FROM " + tableName, "VALUES (3, 1, 'b'), (3, 2, 'a'), (3, 3, 'a')");

assertQuery(session, "SELECT a.\"$data_sequence_number\", b.\"$data_sequence_number\" from " + tableName + " as a, " + tableName2 + " as b where a.id = b.id",
"VALUES (3, 3), (3, 3), (3, 3)");
}

@Test
public void testPartShowStatsWithFilters()
{
Expand Down
Loading