From c22cd3f2ae9f1ee51ca0e382235ae101d8e9c063 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:40:24 +0900 Subject: [PATCH 1/6] Remove unused method from CassandraCqlUtils --- .../cassandra/util/CassandraCqlUtils.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/util/CassandraCqlUtils.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/util/CassandraCqlUtils.java index c79fa957052f..beb55fbfd0ee 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/util/CassandraCqlUtils.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/util/CassandraCqlUtils.java @@ -21,7 +21,6 @@ import io.trino.plugin.cassandra.CassandraColumnHandle; import io.trino.plugin.cassandra.CassandraNamedRelationHandle; import io.trino.plugin.cassandra.CassandraPartition; -import io.trino.spi.connector.ColumnHandle; import java.util.ArrayList; import java.util.List; @@ -67,24 +66,6 @@ public static String quoteStringLiteralForJson(String string) return '"' + new String(JsonStringEncoder.getInstance().quoteAsUTF8(string), UTF_8) + '"'; } - public static void appendSelectColumns(StringBuilder stringBuilder, List columns) - { - appendSelectColumns(stringBuilder, columns, true); - } - - private static void appendSelectColumns(StringBuilder stringBuilder, List columns, boolean first) - { - for (ColumnHandle column : columns) { - if (first) { - first = false; - } - else { - stringBuilder.append(","); - } - stringBuilder.append(validColumnName(((CassandraColumnHandle) column).name())); - } - } - public static String cqlNameToSqlName(String name) { if (name.isEmpty()) { @@ -93,14 +74,6 @@ public static String cqlNameToSqlName(String name) return name; } - public static String sqlNameToCqlName(String name) - { - if (name.equals(EMPTY_COLUMN_NAME)) { - return ""; - } - return name; - } - public static List selection(List columns) { return columns.stream() From fd0c4d887dfbfbd6d23937f045d71faf14032d82 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:41:07 +0900 Subject: [PATCH 2/6] Convert ClusteringPushDownResult to record --- ...CassandraClusteringPredicatesExtractor.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraClusteringPredicatesExtractor.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraClusteringPredicatesExtractor.java index c1651e6193b3..f46a502b4731 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraClusteringPredicatesExtractor.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraClusteringPredicatesExtractor.java @@ -46,7 +46,7 @@ public CassandraClusteringPredicatesExtractor(CassandraTypeManager cassandraType public String getClusteringKeyPredicates() { - return clusteringPushDownResult.getDomainQuery(); + return clusteringPushDownResult.domainQuery(); } public TupleDomain getUnenforcedConstraints() @@ -182,25 +182,17 @@ private String translateRangeIntoCql(CassandraColumnHandle columnHandle, Range r return upperBoundPredicate; } - private static class ClusteringPushDownResult + private record ClusteringPushDownResult(Set fullyPushedColumnPredicates, String domainQuery) { - private final Set fullyPushedColumnPredicates; - private final String domainQuery; - - public ClusteringPushDownResult(Set fullyPushedColumnPredicates, String domainQuery) + private ClusteringPushDownResult { - this.fullyPushedColumnPredicates = ImmutableSet.copyOf(requireNonNull(fullyPushedColumnPredicates, "fullyPushedColumnPredicates is null")); - this.domainQuery = requireNonNull(domainQuery); + fullyPushedColumnPredicates = ImmutableSet.copyOf(requireNonNull(fullyPushedColumnPredicates, "fullyPushedColumnPredicates is null")); + requireNonNull(domainQuery); } public boolean hasBeenFullyPushed(ColumnHandle column) { return fullyPushedColumnPredicates.contains(column); } - - public String getDomainQuery() - { - return domainQuery; - } } } From 3395005bb8c238e1f0d0113414db8a75a2fff892 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:41:49 +0900 Subject: [PATCH 3/6] Convert CassandraTable to record --- .../plugin/cassandra/CassandraMetadata.java | 10 ++-- .../cassandra/CassandraPartitionManager.java | 2 +- .../plugin/cassandra/CassandraSession.java | 12 ++-- .../cassandra/CassandraSplitManager.java | 8 +-- .../plugin/cassandra/CassandraTable.java | 57 +++---------------- ...assandraClusteringPredicatesExtractor.java | 4 +- 6 files changed, 26 insertions(+), 67 deletions(-) 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 9854e3174dc0..d7cfec5ddbb9 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 @@ -114,7 +114,7 @@ public CassandraTableHandle getTableHandle(ConnectorSession session, SchemaTable { requireNonNull(tableName, "tableName is null"); try { - return new CassandraTableHandle(cassandraSession.getTable(tableName).getTableHandle()); + return new CassandraTableHandle(cassandraSession.getTable(tableName).tableHandle()); } catch (TableNotFoundException | SchemaNotFoundException e) { // table was not found @@ -153,7 +153,7 @@ private static SchemaTableName getSchemaTableName(CassandraTableHandle handle) private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName) { CassandraTable table = cassandraSession.getTable(tableName); - List columns = table.getColumns().stream() + List columns = table.columns().stream() .map(CassandraColumnHandle::getColumnMetadata) .collect(toList()); return new ConnectorTableMetadata(tableName, columns); @@ -190,7 +190,7 @@ public Map getColumnHandles(ConnectorSession session, Conn requireNonNull(tableHandle, "tableHandle is null"); CassandraTable table = cassandraSession.getTable(getTableName(tableHandle)); ImmutableMap.Builder columnHandles = ImmutableMap.builder(); - for (CassandraColumnHandle columnHandle : table.getColumns()) { + for (CassandraColumnHandle columnHandle : table.columns()) { columnHandles.put(cqlNameToSqlName(columnHandle.name()).toLowerCase(ENGLISH), columnHandle); } return columnHandles.buildOrThrow(); @@ -252,7 +252,7 @@ public Optional> applyFilter(C else { CassandraClusteringPredicatesExtractor clusteringPredicatesExtractor = new CassandraClusteringPredicatesExtractor( cassandraTypeManager, - cassandraSession.getTable(handle.getSchemaTableName()).getClusteringKeyColumns(), + cassandraSession.getTable(handle.getSchemaTableName()).clusteringKeyColumns(), partitionResult.getUnenforcedConstraint(), cassandraSession.getCassandraVersion()); clusteringKeyPredicates = clusteringPredicatesExtractor.getClusteringKeyPredicates(); @@ -385,7 +385,7 @@ public ConnectorInsertTableHandle beginInsert(ConnectorSession session, Connecto } SchemaTableName schemaTableName = new SchemaTableName(table.getSchemaName(), table.getTableName()); - List columns = cassandraSession.getTable(schemaTableName).getColumns(); + List columns = cassandraSession.getTable(schemaTableName).columns(); List columnNames = columns.stream() .filter(columnHandle -> !isHiddenIdColumn(columnHandle)) .map(CassandraColumnHandle::name) 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 a0bede834d3d..24e69b96b23a 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 @@ -136,7 +136,7 @@ private List getCassandraPartitions(CassandraTable table, Tu private List> getPartitionKeysList(CassandraTable table, TupleDomain tupleDomain) { ImmutableList.Builder> partitionColumnValues = ImmutableList.builder(); - for (CassandraColumnHandle columnHandle : table.getPartitionKeyColumns()) { + for (CassandraColumnHandle columnHandle : table.partitionKeyColumns()) { Domain domain = tupleDomain.getDomains().get().get(columnHandle); // if there is no constraint on a partition key, return an empty set diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java index e59e9d8d6ffe..8503fd6509e8 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java @@ -379,12 +379,12 @@ private Optional buildColumnHandle(RelationMetadata table * * @param table the table to get partitions from * @param filterPrefixes the list of possible values for each partition key. - * Order of values should match {@link CassandraTable#getPartitionKeyColumns()} + * Order of values should match {@link CassandraTable#partitionKeyColumns()} * @return list of {@link CassandraPartition} */ public List getPartitions(CassandraTable table, List> filterPrefixes) { - List partitionKeyColumns = table.getPartitionKeyColumns(); + List partitionKeyColumns = table.partitionKeyColumns(); if (filterPrefixes.size() != partitionKeyColumns.size()) { return ImmutableList.of(CassandraPartition.UNPARTITIONED); @@ -465,8 +465,8 @@ public ResultSet execute(Statement statement) private Iterable queryPartitionKeysWithInClauses(CassandraTable table, List> filterPrefixes) { - CassandraNamedRelationHandle tableHandle = table.getTableHandle(); - List partitionKeyColumns = table.getPartitionKeyColumns(); + CassandraNamedRelationHandle tableHandle = table.tableHandle(); + List partitionKeyColumns = table.partitionKeyColumns(); Select partitionKeys = selectDistinctFrom(tableHandle, partitionKeyColumns) .where(getInRelations(partitionKeyColumns, filterPrefixes)); @@ -477,8 +477,8 @@ private Iterable queryPartitionKeysWithInClauses(CassandraTable table, List private Iterable queryPartitionKeysLegacyWithMultipleQueries(CassandraTable table, List> filterPrefixes) { - CassandraNamedRelationHandle tableHandle = table.getTableHandle(); - List partitionKeyColumns = table.getPartitionKeyColumns(); + CassandraNamedRelationHandle tableHandle = table.tableHandle(); + List partitionKeyColumns = table.partitionKeyColumns(); Set> filterCombinations = Sets.cartesianProduct(filterPrefixes); diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java index 8400fa8f88eb..c51c4cf84ffe 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java @@ -130,7 +130,7 @@ private String extractClusteringKeyPredicates(CassandraPartitionResult partition CassandraClusteringPredicatesExtractor clusteringPredicatesExtractor = new CassandraClusteringPredicatesExtractor( cassandraTypeManager, - session.getTable(tableHandle.getSchemaTableName()).getClusteringKeyColumns(), + session.getTable(tableHandle.getSchemaTableName()).clusteringKeyColumns(), partitionResult.getUnenforcedConstraint(), session.getCassandraVersion()); return clusteringPredicatesExtractor.getClusteringKeyPredicates(); @@ -138,9 +138,9 @@ private String extractClusteringKeyPredicates(CassandraPartitionResult partition private List getSplitsByTokenRange(CassandraTable table, String partitionId, Optional sessionSplitsPerNode) { - String schema = table.getTableHandle().getSchemaName(); - String tableName = table.getTableHandle().getTableName(); - String tokenExpression = table.getTokenExpression(); + String schema = table.tableHandle().getSchemaName(); + String tableName = table.tableHandle().getTableName(); + String tokenExpression = table.tokenExpression(); ImmutableList.Builder builder = ImmutableList.builder(); List tokenSplits = tokenSplitMgr.getSplits(schema, tableName, sessionSplitsPerNode); diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTable.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTable.java index 6dd6423e4e26..d2c09757318a 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTable.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTable.java @@ -18,49 +18,35 @@ import java.util.List; -import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.collect.ImmutableList.toImmutableList; import static java.util.Objects.requireNonNull; -public class CassandraTable +public record CassandraTable(CassandraNamedRelationHandle tableHandle, List columns) { - private final CassandraNamedRelationHandle tableHandle; - private final List columns; - - public CassandraTable(CassandraNamedRelationHandle tableHandle, List columns) + public CassandraTable { - this.tableHandle = requireNonNull(tableHandle, "tableHandle is null"); - this.columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null")); + requireNonNull(tableHandle, "tableHandle is null"); + columns = ImmutableList.copyOf(requireNonNull(columns, "columns is null")); } - public List getColumns() - { - return columns; - } - - public CassandraNamedRelationHandle getTableHandle() - { - return tableHandle; - } - - public List getPartitionKeyColumns() + public List partitionKeyColumns() { return columns.stream() .filter(CassandraColumnHandle::partitionKey) .collect(toImmutableList()); } - public List getClusteringKeyColumns() + public List clusteringKeyColumns() { return columns.stream() .filter(CassandraColumnHandle::clusteringKey) .collect(toImmutableList()); } - public String getTokenExpression() + public String tokenExpression() { StringBuilder sb = new StringBuilder(); - for (CassandraColumnHandle column : getPartitionKeyColumns()) { + for (CassandraColumnHandle column : partitionKeyColumns()) { if (sb.length() == 0) { sb.append("token("); } @@ -72,31 +58,4 @@ public String getTokenExpression() sb.append(")"); return sb.toString(); } - - @Override - public int hashCode() - { - return tableHandle.hashCode(); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) { - return true; - } - if (!(obj instanceof CassandraTable)) { - return false; - } - CassandraTable that = (CassandraTable) obj; - return this.tableHandle.equals(that.tableHandle); - } - - @Override - public String toString() - { - return toStringHelper(this) - .add("tableHandle", tableHandle) - .toString(); - } } diff --git a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/util/TestCassandraClusteringPredicatesExtractor.java b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/util/TestCassandraClusteringPredicatesExtractor.java index fd59960ef7e1..66d66edc6df1 100644 --- a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/util/TestCassandraClusteringPredicatesExtractor.java +++ b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/util/TestCassandraClusteringPredicatesExtractor.java @@ -59,7 +59,7 @@ public void testBuildClusteringPredicate() col1, Domain.singleValue(BIGINT, 23L), col2, Domain.singleValue(BIGINT, 34L), col4, Domain.singleValue(BIGINT, 26L))); - CassandraClusteringPredicatesExtractor predicatesExtractor = new CassandraClusteringPredicatesExtractor(CASSANDRA_TYPE_MANAGER, cassandraTable.getClusteringKeyColumns(), tupleDomain, cassandraVersion); + CassandraClusteringPredicatesExtractor predicatesExtractor = new CassandraClusteringPredicatesExtractor(CASSANDRA_TYPE_MANAGER, cassandraTable.clusteringKeyColumns(), tupleDomain, cassandraVersion); String predicate = predicatesExtractor.getClusteringKeyPredicates(); assertThat(predicate).isEqualTo("\"clusteringKey1\" = 34"); } @@ -71,7 +71,7 @@ public void testGetUnenforcedPredicates() ImmutableMap.of( col2, Domain.singleValue(BIGINT, 34L), col4, Domain.singleValue(BIGINT, 26L))); - CassandraClusteringPredicatesExtractor predicatesExtractor = new CassandraClusteringPredicatesExtractor(CASSANDRA_TYPE_MANAGER, cassandraTable.getClusteringKeyColumns(), tupleDomain, cassandraVersion); + CassandraClusteringPredicatesExtractor predicatesExtractor = new CassandraClusteringPredicatesExtractor(CASSANDRA_TYPE_MANAGER, cassandraTable.clusteringKeyColumns(), tupleDomain, cassandraVersion); TupleDomain unenforcedPredicates = TupleDomain.withColumnDomains(ImmutableMap.of(col4, Domain.singleValue(BIGINT, 26L))); assertThat(predicatesExtractor.getUnenforcedConstraints()).isEqualTo(unenforcedPredicates); } From 5b030c084056a72a6bb2a65e69718572526376a4 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:42:29 +0900 Subject: [PATCH 4/6] Convert ExtraColumnMetadata to record --- .../plugin/cassandra/CassandraSession.java | 6 +-- .../plugin/cassandra/ExtraColumnMetadata.java | 39 ++----------------- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java index 8503fd6509e8..420c404a1a13 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSession.java @@ -222,10 +222,10 @@ public CassandraTable getTable(SchemaTableName schemaTableName) // column ordering List extras = extraColumnMetadataCodec.fromJson(columnOrderingString); - List explicitColumnOrder = new ArrayList<>(ImmutableList.copyOf(transform(extras, ExtraColumnMetadata::getName))); + List explicitColumnOrder = new ArrayList<>(ImmutableList.copyOf(transform(extras, ExtraColumnMetadata::name))); hiddenColumns = extras.stream() - .filter(ExtraColumnMetadata::isHidden) - .map(ExtraColumnMetadata::getName) + .filter(ExtraColumnMetadata::hidden) + .map(ExtraColumnMetadata::name) .collect(toImmutableSet()); // add columns not in the comment to the ordering diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/ExtraColumnMetadata.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/ExtraColumnMetadata.java index 139f20bf2e0f..36614e6b2f1f 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/ExtraColumnMetadata.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/ExtraColumnMetadata.java @@ -13,43 +13,12 @@ */ package io.trino.plugin.cassandra; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import static java.util.Objects.requireNonNull; -import static com.google.common.base.MoreObjects.toStringHelper; - -public class ExtraColumnMetadata +public record ExtraColumnMetadata(String name, boolean hidden) { - private final String name; - private final boolean hidden; - - @JsonCreator - public ExtraColumnMetadata( - @JsonProperty("name") String name, - @JsonProperty("hidden") boolean hidden) - { - this.name = name; - this.hidden = hidden; - } - - @JsonProperty - public String getName() - { - return name; - } - - @JsonProperty - public boolean isHidden() - { - return hidden; - } - - @Override - public String toString() + public ExtraColumnMetadata { - return toStringHelper(this) - .add("name", name) - .add("hidden", hidden) - .toString(); + requireNonNull(name, "name is null"); } } From cec75843d308a8e47010390f573a539eb749cf6b Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:42:49 +0900 Subject: [PATCH 5/6] Convert SizeEstimate to record --- .../cassandra/CassandraTokenSplitManager.java | 2 +- .../trino/plugin/cassandra/SizeEstimate.java | 46 +------------------ 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTokenSplitManager.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTokenSplitManager.java index b0b24f1d727a..bd884513d5b7 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTokenSplitManager.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraTokenSplitManager.java @@ -128,7 +128,7 @@ public long getTotalPartitionsCount(String keyspace, String table, Optional estimates = session.getSizeEstimates(keyspace, table); return estimates.stream() - .mapToLong(SizeEstimate::getPartitionsCount) + .mapToLong(SizeEstimate::partitionsCount) .sum(); } diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/SizeEstimate.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/SizeEstimate.java index 8bdd45c99657..72b2612d4b79 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/SizeEstimate.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/SizeEstimate.java @@ -13,48 +13,4 @@ */ package io.trino.plugin.cassandra; -import java.util.Objects; - -import static com.google.common.base.MoreObjects.toStringHelper; - -public class SizeEstimate -{ - private final long partitionsCount; - - public SizeEstimate(long partitionsCount) - { - this.partitionsCount = partitionsCount; - } - - public long getPartitionsCount() - { - return partitionsCount; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - SizeEstimate that = (SizeEstimate) o; - return partitionsCount == that.partitionsCount; - } - - @Override - public int hashCode() - { - return Objects.hash(partitionsCount); - } - - @Override - public String toString() - { - return toStringHelper(this) - .add("partitionsCount", partitionsCount) - .toString(); - } -} +public record SizeEstimate(long partitionsCount) {} From e76eb2ea317bad942a2295e3f110231dbc468d1c Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Mon, 22 Apr 2024 14:44:45 +0900 Subject: [PATCH 6/6] Convert CassandraPartitionResult to record --- .../plugin/cassandra/CassandraMetadata.java | 10 +++---- .../cassandra/CassandraPartitionResult.java | 26 +++++-------------- .../cassandra/CassandraSplitManager.java | 6 ++--- 3 files changed, 15 insertions(+), 27 deletions(-) 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 d7cfec5ddbb9..7de92389127c 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 @@ -244,16 +244,16 @@ public Optional> applyFilter(C String clusteringKeyPredicates = ""; TupleDomain unenforcedConstraint; - if (partitionResult.isUnpartitioned() || partitionResult.isIndexedColumnPredicatePushdown()) { + if (partitionResult.unpartitioned() || partitionResult.indexedColumnPredicatePushdown()) { // When the filter is missing at least one of the partition keys or when the table is not partitioned, // use the raw unenforced constraint of the partitionResult - unenforcedConstraint = partitionResult.getUnenforcedConstraint(); + unenforcedConstraint = partitionResult.unenforcedConstraint(); } else { CassandraClusteringPredicatesExtractor clusteringPredicatesExtractor = new CassandraClusteringPredicatesExtractor( cassandraTypeManager, cassandraSession.getTable(handle.getSchemaTableName()).clusteringKeyColumns(), - partitionResult.getUnenforcedConstraint(), + partitionResult.unenforcedConstraint(), cassandraSession.getCassandraVersion()); clusteringKeyPredicates = clusteringPredicatesExtractor.getClusteringKeyPredicates(); unenforcedConstraint = clusteringPredicatesExtractor.getUnenforcedConstraints(); @@ -262,7 +262,7 @@ public Optional> applyFilter(C Optional> currentPartitions = handle.getPartitions(); if (currentPartitions.isPresent() && // TODO: we should skip only when new table handle does not narrow down enforced predicate - currentPartitions.get().containsAll(partitionResult.getPartitions()) && + currentPartitions.get().containsAll(partitionResult.partitions()) && handle.getClusteringKeyPredicates().equals(clusteringKeyPredicates)) { return Optional.empty(); } @@ -271,7 +271,7 @@ public Optional> applyFilter(C new ConstraintApplicationResult<>(new CassandraTableHandle(new CassandraNamedRelationHandle( handle.getSchemaName(), handle.getTableName(), - Optional.of(partitionResult.getPartitions()), + Optional.of(partitionResult.partitions()), // TODO this should probably be AND-ed with handle.getClusteringKeyPredicates() clusteringKeyPredicates)), unenforcedConstraint, diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionResult.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionResult.java index bd1c874bea75..56f9bb6abf83 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionResult.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraPartitionResult.java @@ -13,6 +13,7 @@ */ package io.trino.plugin.cassandra; +import com.google.common.collect.ImmutableList; import io.trino.spi.connector.ColumnHandle; import io.trino.spi.predicate.TupleDomain; @@ -21,33 +22,20 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static java.util.Objects.requireNonNull; -public class CassandraPartitionResult +public record CassandraPartitionResult(List partitions, TupleDomain unenforcedConstraint) { - private final List partitions; - private final TupleDomain unenforcedConstraint; - - public CassandraPartitionResult(List partitions, TupleDomain unenforcedConstraint) - { - this.partitions = requireNonNull(partitions, "partitions is null"); - this.unenforcedConstraint = requireNonNull(unenforcedConstraint, "unenforcedConstraint is null"); - } - - public List getPartitions() - { - return partitions; - } - - public TupleDomain getUnenforcedConstraint() + public CassandraPartitionResult { - return unenforcedConstraint; + partitions = ImmutableList.copyOf(requireNonNull(partitions, "partitions is null")); + requireNonNull(unenforcedConstraint, "unenforcedConstraint is null"); } - public boolean isUnpartitioned() + public boolean unpartitioned() { return partitions.size() == 1 && getOnlyElement(partitions).isUnpartitioned(); } - public boolean isIndexedColumnPredicatePushdown() + public boolean indexedColumnPredicatePushdown() { return partitions.size() == 1 && getOnlyElement(partitions).isIndexedColumnPredicatePushdown(); } diff --git a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java index c51c4cf84ffe..6c216abd539f 100644 --- a/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java +++ b/plugin/trino-cassandra/src/main/java/io/trino/plugin/cassandra/CassandraSplitManager.java @@ -97,7 +97,7 @@ public ConnectorSplitSource getSplits( } else { CassandraPartitionResult partitionResult = partitionManager.getPartitions(cassandraTableHandle, TupleDomain.all()); - partitions = partitionResult.getPartitions(); + partitions = partitionResult.partitions(); clusteringKeyPredicates = extractClusteringKeyPredicates(partitionResult, cassandraTableHandle, cassandraSession); } @@ -124,14 +124,14 @@ public ConnectorSplitSource getSplits( private String extractClusteringKeyPredicates(CassandraPartitionResult partitionResult, CassandraNamedRelationHandle tableHandle, CassandraSession session) { - if (partitionResult.isUnpartitioned()) { + if (partitionResult.unpartitioned()) { return ""; } CassandraClusteringPredicatesExtractor clusteringPredicatesExtractor = new CassandraClusteringPredicatesExtractor( cassandraTypeManager, session.getTable(tableHandle.getSchemaTableName()).clusteringKeyColumns(), - partitionResult.getUnenforcedConstraint(), + partitionResult.unenforcedConstraint(), session.getCassandraVersion()); return clusteringPredicatesExtractor.getClusteringKeyPredicates(); }