From a8f1d675807788cd2468fb5d7a3ddc1108a6e084 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 9 Mar 2022 15:17:46 +0100 Subject: [PATCH] Fix Cassandra incorrect query results when applyFilter repeated --- .../java/io/trino/plugin/cassandra/CassandraMetadata.java | 5 +++++ .../io/trino/plugin/cassandra/CassandraPartitionManager.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java index 2882592795ce..fa5eed7608bb 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraMetadata.java @@ -202,6 +202,10 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable public Optional> applyFilter(ConnectorSession session, ConnectorTableHandle tableHandle, Constraint constraint) { CassandraTableHandle handle = (CassandraTableHandle) tableHandle; + if (handle.getPartitions().isPresent() || !handle.getClusteringKeyPredicates().isEmpty()) { + // TODO support repeated applyFilter + return Optional.empty(); + } CassandraPartitionResult partitionResult = partitionManager.getPartitions(handle, constraint.getSummary()); @@ -232,6 +236,7 @@ public Optional> applyFilter(C handle.getSchemaName(), handle.getTableName(), Optional.of(partitionResult.getPartitions()), + // TODO this should probably be AND-ed with handle.getClusteringKeyPredicates() clusteringKeyPredicates), unenforcedConstraint, false)); diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionManager.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionManager.java index 1886a0727423..f5cb0164a62a 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionManager.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionManager.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.stream.Stream; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.not; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -53,6 +54,9 @@ public CassandraPartitionManager(CassandraSession cassandraSession) public CassandraPartitionResult getPartitions(CassandraTableHandle cassandraTableHandle, TupleDomain tupleDomain) { + // TODO support repeated applyFilter + checkArgument(cassandraTableHandle.getPartitions().isEmpty(), "getPartitions() currently does not take into account table handle's partitions"); + CassandraTable table = cassandraSession.getTable(cassandraTableHandle.getSchemaTableName()); // fetch the partitions