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

Fix reading NDV using Iceberg metadata on table with NULL partitions #21844

Merged
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 @@ -640,7 +640,7 @@ public ConnectorTableProperties getTableProperties(ConnectorSession session, Con
partitionColumnValueStrings.get(columnId).orElse(null),
column.getName());

return NullableValue.of(column.getType(), prestoValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider calling the NullableValue constructor instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I don't have a preference. I don't quite understand why it has both constructor and static methods.
Which way do you think is better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they have different semantics -- NullableValue.of doesn't allow null value

(i with the difference was more obvious from the NullableValue class's api)

return new NullableValue(column.getType(), prestoValue);
}));

return TupleDomain.fromFixedValues(partitionValues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import io.trino.spi.type.UuidType;
import io.trino.spi.type.VarbinaryType;
import io.trino.spi.type.VarcharType;
import jakarta.annotation.Nullable;
import org.apache.iceberg.BaseTable;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.FileScanTask;
Expand Down Expand Up @@ -531,6 +532,7 @@ private static boolean yieldSamePartitioningValue(
}
}

@Nullable
public static Object deserializePartitionValue(Type type, String valueString, String name)
{
if (valueString == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ public void testOptimization()
values(ImmutableList.of("b", "c"), ImmutableList.of())));
}

@Test
public void testOptimizationWithNullPartitions()
{
String testTable = "test_metadata_optimization_with_null_partitions";

getPlanTester().executeStatement(format(
"CREATE TABLE %s (a, b, c) WITH (PARTITIONING = ARRAY['b', 'c'])" +
"AS VALUES (5, 6, CAST(NULL AS INTEGER)), (8, 9, CAST(NULL AS INTEGER))",
testTable));

Session session = Session.builder(getPlanTester().getDefaultSession())
.setSystemProperty("optimize_metadata_queries", "true")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raunaqmorarka we've been speaking already on optimize_metadata_queries session property for Iceberg/ Delta Lake offline.
We should figure out a way where it is not necessary for the user to specify explicitly this low level session property to make use of https://trino.io/docs/current/admin/properties-optimizer.html#optimizer-optimize-metadata-queries

.build();

assertPlan(
format("SELECT DISTINCT b, c FROM %s ORDER BY b", testTable),
session,
anyTree(values(
ImmutableList.of("b", "c"),
ImmutableList.of(
ImmutableList.of(new Constant(INTEGER, 6L), new Constant(INTEGER, null)),
ImmutableList.of(new Constant(INTEGER, 9L), new Constant(INTEGER, null))))));
}

@AfterAll
public void cleanup()
throws Exception
Expand Down