Skip to content

Commit 46a7003

Browse files
wypbtdcmeehan
authored andcommitted
Fix equality delete with DistinctLimit
1 parent 965626d commit 46a7003

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

presto-iceberg/src/main/java/com/facebook/presto/iceberg/optimizer/IcebergEqualityDeleteAsJoin.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
import com.facebook.presto.spi.VariableAllocator;
3636
import com.facebook.presto.spi.function.FunctionHandle;
3737
import com.facebook.presto.spi.function.StandardFunctionResolution;
38+
import com.facebook.presto.spi.plan.Assignments;
3839
import com.facebook.presto.spi.plan.ConnectorJoinNode;
3940
import com.facebook.presto.spi.plan.EquiJoinClause;
4041
import com.facebook.presto.spi.plan.FilterNode;
4142
import com.facebook.presto.spi.plan.JoinType;
4243
import com.facebook.presto.spi.plan.PlanNode;
4344
import com.facebook.presto.spi.plan.PlanNodeIdAllocator;
45+
import com.facebook.presto.spi.plan.ProjectNode;
4446
import com.facebook.presto.spi.plan.TableScanNode;
4547
import com.facebook.presto.spi.relation.CallExpression;
4648
import com.facebook.presto.spi.relation.RowExpression;
@@ -251,7 +253,11 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext<Void> context)
251253
new SpecialFormExpression(SpecialFormExpression.Form.IS_NULL, BooleanType.BOOLEAN,
252254
new SpecialFormExpression(SpecialFormExpression.Form.COALESCE, BigintType.BIGINT, deleteVersionColumns)));
253255

254-
return filter;
256+
Assignments.Builder assignmentsBuilder = Assignments.builder();
257+
filter.getOutputVariables().stream()
258+
.filter(variableReferenceExpression -> !variableReferenceExpression.getName().startsWith(DATA_SEQUENCE_NUMBER_COLUMN_HANDLE.getName()))
259+
.forEach(variableReferenceExpression -> assignmentsBuilder.put(variableReferenceExpression, variableReferenceExpression));
260+
return new ProjectNode(Optional.empty(), idAllocator.getNextId(), filter, assignmentsBuilder.build(), ProjectNode.Locality.LOCAL);
255261
}
256262

257263
private static ImmutableMap<Set<Integer>, DeleteSetInfo> collectDeleteInformation(Table icebergTable,

presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,42 @@ public void testTableWithEqualityDelete(String fileFormat, boolean joinRewriteEn
900900
assertQuery(session, "SELECT nationkey FROM " + tableName, "SELECT nationkey FROM nation WHERE regionkey != 1");
901901
}
902902

903+
@Test(dataProvider = "equalityDeleteOptions")
904+
public void testTableWithEqualityDeleteDifferentColumnOrder(String fileFormat, boolean joinRewriteEnabled)
905+
throws Exception
906+
{
907+
Session session = deleteAsJoinEnabled(joinRewriteEnabled);
908+
// Specify equality delete filter with different column order from table definition
909+
String tableName = "test_v2_equality_delete_different_order" + randomTableSuffix();
910+
assertUpdate(session, "CREATE TABLE " + tableName + " with (format = '" + fileFormat + "') AS SELECT * FROM tpch.tiny.nation", 25);
911+
Table icebergTable = updateTable(tableName);
912+
913+
writeEqualityDeleteToNationTable(icebergTable, ImmutableMap.of("regionkey", 1L, "name", "ARGENTINA"));
914+
assertQuery(session, "SELECT * FROM " + tableName, "SELECT * FROM nation WHERE name != 'ARGENTINA'");
915+
// natiokey is before the equality delete column in the table schema, comment is after
916+
assertQuery(session, "SELECT nationkey, comment FROM " + tableName, "SELECT nationkey, comment FROM nation WHERE name != 'ARGENTINA'");
917+
}
918+
919+
@Test(dataProvider = "equalityDeleteOptions")
920+
public void testTableWithEqualityDeleteAndGroupByAndLimit(String fileFormat, boolean joinRewriteEnabled)
921+
throws Exception
922+
{
923+
Session session = deleteAsJoinEnabled(joinRewriteEnabled);
924+
Session disable = deleteAsJoinEnabled(false);
925+
// Specify equality delete filter with different column order from table definition
926+
String tableName = "test_v2_equality_delete_different_order" + randomTableSuffix();
927+
assertUpdate(session, "CREATE TABLE " + tableName + " with (format = '" + fileFormat + "') AS SELECT * FROM tpch.tiny.nation", 25);
928+
Table icebergTable = updateTable(tableName);
929+
930+
writeEqualityDeleteToNationTable(icebergTable, ImmutableMap.of("regionkey", 1L, "name", "ARGENTINA"));
931+
assertQuery(session, "SELECT * FROM " + tableName, "SELECT * FROM nation WHERE name != 'ARGENTINA'");
932+
933+
// Test group by
934+
assertQuery(session, "SELECT nationkey FROM " + tableName + " group by nationkey", "VALUES(0),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24)");
935+
// Test group by with limit
936+
assertQueryWithSameQueryRunner(session, "SELECT nationkey FROM " + tableName + " group by nationkey limit 100", disable);
937+
}
938+
903939
@Test(dataProvider = "equalityDeleteOptions")
904940
public void testTableWithPositionDeleteAndEqualityDelete(String fileFormat, boolean joinRewriteEnabled)
905941
throws Exception

0 commit comments

Comments
 (0)