From ddf0dd8715de890292bc7a48f41cc7764a33d9f6 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 13:58:43 +0200 Subject: [PATCH 01/21] Convert AnalyzeMetadata to record --- .../io/trino/metadata/AnalyzeMetadata.java | 21 ++++--------------- .../io/trino/sql/planner/LogicalPlanner.java | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/AnalyzeMetadata.java b/core/trino-main/src/main/java/io/trino/metadata/AnalyzeMetadata.java index c1edfe746638..4ddcad405c0b 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/AnalyzeMetadata.java +++ b/core/trino-main/src/main/java/io/trino/metadata/AnalyzeMetadata.java @@ -17,24 +17,11 @@ import static java.util.Objects.requireNonNull; -public class AnalyzeMetadata +public record AnalyzeMetadata(TableStatisticsMetadata statisticsMetadata, TableHandle tableHandle) { - private final TableStatisticsMetadata statisticsMetadata; - private final TableHandle tableHandle; - - public AnalyzeMetadata(TableStatisticsMetadata statisticsMetadata, TableHandle tableHandle) - { - this.statisticsMetadata = requireNonNull(statisticsMetadata, "statisticsMetadata is null"); - this.tableHandle = requireNonNull(tableHandle, "tableHandle is null"); - } - - public TableStatisticsMetadata getStatisticsMetadata() - { - return statisticsMetadata; - } - - public TableHandle getTableHandle() + public AnalyzeMetadata { - return tableHandle; + requireNonNull(statisticsMetadata, "statisticsMetadata is null"); + requireNonNull(tableHandle, "tableHandle is null"); } } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java b/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java index 998f1ddccc42..3f484499c1f7 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java @@ -405,8 +405,8 @@ private RelationPlan createExplainAnalyzePlan(Analysis analysis, ExplainAnalyze private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStatement) { AnalyzeMetadata analyzeMetadata = analysis.getAnalyzeMetadata().orElseThrow(); - TableHandle targetTable = analyzeMetadata.getTableHandle(); - TableStatisticsMetadata tableStatisticsMetadata = analyzeMetadata.getStatisticsMetadata(); + TableHandle targetTable = analyzeMetadata.tableHandle(); + TableStatisticsMetadata tableStatisticsMetadata = analyzeMetadata.statisticsMetadata(); // Plan table scan Map columnHandles = metadata.getColumnHandles(session, targetTable); From 7492d9c30400c1b43b6e2eca78128812ffe1222e Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:00:05 +0200 Subject: [PATCH 02/21] Convert AnalyzeTableHandle to record --- .../io/trino/metadata/AnalyzeTableHandle.java | 64 +++---------------- .../io/trino/metadata/MetadataManager.java | 4 +- .../planprinter/CounterBasedAnonymizer.java | 2 +- .../io/trino/tracing/TracingMetadata.java | 4 +- 4 files changed, 13 insertions(+), 61 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/AnalyzeTableHandle.java b/core/trino-main/src/main/java/io/trino/metadata/AnalyzeTableHandle.java index ef3fb61d09a6..05ce82d9b053 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/AnalyzeTableHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/AnalyzeTableHandle.java @@ -13,70 +13,22 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorTableHandle; import io.trino.spi.connector.ConnectorTransactionHandle; -import java.util.Objects; - import static java.util.Objects.requireNonNull; -public class AnalyzeTableHandle +public record AnalyzeTableHandle( + CatalogHandle catalogHandle, + ConnectorTransactionHandle transactionHandle, + ConnectorTableHandle connectorHandle) { - private final CatalogHandle catalogHandle; - private final ConnectorTransactionHandle transactionHandle; - private final ConnectorTableHandle connectorHandle; - - @JsonCreator - public AnalyzeTableHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle, - @JsonProperty("connectorHandle") ConnectorTableHandle connectorHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - @JsonProperty - public ConnectorTableHandle getConnectorHandle() - { - return connectorHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() - { - return transactionHandle; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - AnalyzeTableHandle that = (AnalyzeTableHandle) o; - return Objects.equals(catalogHandle, that.catalogHandle) && - Objects.equals(transactionHandle, that.transactionHandle) && - Objects.equals(connectorHandle, that.connectorHandle); - } - - @Override - public int hashCode() + public AnalyzeTableHandle { - return Objects.hash(catalogHandle, transactionHandle, connectorHandle); + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); } @Override diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index c04c8698d533..569e5eaeecda 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -1063,9 +1063,9 @@ public AnalyzeTableHandle beginStatisticsCollection(Session session, TableHandle @Override public void finishStatisticsCollection(Session session, AnalyzeTableHandle tableHandle, Collection computedStatistics) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); - catalogMetadata.getMetadata(session).finishStatisticsCollection(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), computedStatistics); + catalogMetadata.getMetadata(session).finishStatisticsCollection(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), computedStatistics); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index a9e4d846c08b..bcc9fa7224da 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -200,7 +200,7 @@ public String anonymize(WriteStatisticsTarget target) { if (target instanceof WriteStatisticsHandle) { return anonymize( - ((WriteStatisticsHandle) target).getHandle().getCatalogHandle().getCatalogName().toString(), + ((WriteStatisticsHandle) target).getHandle().catalogHandle().getCatalogName().toString(), ObjectType.CATALOG); } throw new UnsupportedOperationException("Anonymization is not supported for WriterTarget type: " + target.getClass().getSimpleName()); diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index a6d79e6385a1..5eb1c6021e7f 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -650,9 +650,9 @@ public AnalyzeTableHandle beginStatisticsCollection(Session session, TableHandle @Override public void finishStatisticsCollection(Session session, AnalyzeTableHandle tableHandle, Collection computedStatistics) { - Span span = startSpan("finishStatisticsCollection", tableHandle.getCatalogHandle().getCatalogName()); + Span span = startSpan("finishStatisticsCollection", tableHandle.catalogHandle().getCatalogName()); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.TABLE, tableHandle.getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.TABLE, tableHandle.connectorHandle().toString()); } try (var ignored = scopedSpan(span)) { delegate.finishStatisticsCollection(session, tableHandle, computedStatistics); From 693af9b35b8ceb16bca1cd17e443721301cbb8c0 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:00:43 +0200 Subject: [PATCH 03/21] Convert CatalogInfo to record --- .../system/AbstractPropertiesSystemTable.java | 6 +-- .../connector/system/CatalogSystemTable.java | 6 +-- .../java/io/trino/execution/TableInfo.java | 4 +- .../java/io/trino/metadata/CatalogInfo.java | 40 +++---------------- .../io/trino/metadata/MetadataListing.java | 6 +-- .../metadata/SessionPropertyManager.java | 4 +- .../io/trino/sql/planner/PlanFragmenter.java | 2 +- .../planprinter/TableInfoSupplier.java | 4 +- 8 files changed, 21 insertions(+), 51 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/connector/system/AbstractPropertiesSystemTable.java b/core/trino-main/src/main/java/io/trino/connector/system/AbstractPropertiesSystemTable.java index c4fec1df6b94..9e2f03a99ff3 100644 --- a/core/trino-main/src/main/java/io/trino/connector/system/AbstractPropertiesSystemTable.java +++ b/core/trino-main/src/main/java/io/trino/connector/system/AbstractPropertiesSystemTable.java @@ -83,15 +83,15 @@ public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, C InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata); List catalogInfos = listCatalogs(session, metadata, accessControl).stream() - .sorted(Comparator.comparing(CatalogInfo::getCatalogName)) + .sorted(Comparator.comparing(CatalogInfo::catalogName)) .collect(toImmutableList()); for (CatalogInfo catalogInfo : catalogInfos) { - catalogProperties.apply(catalogInfo.getCatalogHandle()).stream() + catalogProperties.apply(catalogInfo.catalogHandle()).stream() .sorted(Comparator.comparing(PropertyMetadata::getName)) .forEach(propertyMetadata -> table.addRow( - catalogInfo.getCatalogName(), + catalogInfo.catalogName(), propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), diff --git a/core/trino-main/src/main/java/io/trino/connector/system/CatalogSystemTable.java b/core/trino-main/src/main/java/io/trino/connector/system/CatalogSystemTable.java index 77406f8fbf47..69bcd6166913 100644 --- a/core/trino-main/src/main/java/io/trino/connector/system/CatalogSystemTable.java +++ b/core/trino-main/src/main/java/io/trino/connector/system/CatalogSystemTable.java @@ -74,9 +74,9 @@ public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, Connect Builder table = InMemoryRecordSet.builder(CATALOG_TABLE); for (CatalogInfo catalogInfo : listCatalogs(session, metadata, accessControl)) { table.addRow( - catalogInfo.getCatalogName(), - catalogInfo.getCatalogName(), - catalogInfo.getConnectorName().toString()); + catalogInfo.catalogName(), + catalogInfo.catalogName(), + catalogInfo.connectorName().toString()); } return table.build().cursor(); } diff --git a/core/trino-main/src/main/java/io/trino/execution/TableInfo.java b/core/trino-main/src/main/java/io/trino/execution/TableInfo.java index 1ff9278f02fc..edc4a61cd74a 100644 --- a/core/trino-main/src/main/java/io/trino/execution/TableInfo.java +++ b/core/trino-main/src/main/java/io/trino/execution/TableInfo.java @@ -88,8 +88,8 @@ private static TableInfo extract(Session session, Metadata metadata, TableScanNo CatalogSchemaTableName tableName = metadata.getTableName(session, node.getTable()); TableProperties tableProperties = metadata.getTableProperties(session, node.getTable()); Optional connectorName = metadata.listCatalogs(session).stream() - .filter(catalogInfo -> catalogInfo.getCatalogName().equals(tableName.getCatalogName())) - .map(CatalogInfo::getConnectorName) + .filter(catalogInfo -> catalogInfo.catalogName().equals(tableName.getCatalogName())) + .map(CatalogInfo::connectorName) .map(ConnectorName::toString) .findFirst(); QualifiedObjectName objectName = new QualifiedObjectName(tableName.getCatalogName(), tableName.getSchemaTableName().getSchemaName(), tableName.getSchemaTableName().getTableName()); diff --git a/core/trino-main/src/main/java/io/trino/metadata/CatalogInfo.java b/core/trino-main/src/main/java/io/trino/metadata/CatalogInfo.java index da2e1393e883..336d333bf8d0 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/CatalogInfo.java +++ b/core/trino-main/src/main/java/io/trino/metadata/CatalogInfo.java @@ -16,44 +16,14 @@ import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorName; -import static com.google.common.base.MoreObjects.toStringHelper; import static java.util.Objects.requireNonNull; -public class CatalogInfo +public record CatalogInfo(String catalogName, CatalogHandle catalogHandle, ConnectorName connectorName) { - private final String catalogName; - private final CatalogHandle catalogHandle; - private final ConnectorName connectorName; - - public CatalogInfo(String catalogName, CatalogHandle catalogHandle, ConnectorName connectorName) - { - this.catalogName = requireNonNull(catalogName, "catalogName is null"); - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.connectorName = requireNonNull(connectorName, "connectorName is null"); - } - - public String getCatalogName() - { - return catalogName; - } - - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - public ConnectorName getConnectorName() - { - return connectorName; - } - - @Override - public String toString() + public CatalogInfo { - return toStringHelper(this) - .add("catalogName", catalogName) - .add("catalogHandle", catalogHandle) - .add("connectorName", connectorName) - .toString(); + requireNonNull(catalogName, "catalogName is null"); + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(connectorName, "connectorName is null"); } } diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java index db9bb985a54e..c0a93f356601 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataListing.java @@ -66,7 +66,7 @@ public static SortedSet listCatalogNames(Session session, Metadata metad } else { catalogs = metadata.listCatalogs(session).stream() - .map(CatalogInfo::getCatalogName) + .map(CatalogInfo::catalogName) .filter(stringFilter(catalogDomain)) .collect(toImmutableSet()); } @@ -77,11 +77,11 @@ public static List listCatalogs(Session session, Metadata metadata, { List catalogs = metadata.listCatalogs(session); Set catalogNames = catalogs.stream() - .map(CatalogInfo::getCatalogName) + .map(CatalogInfo::catalogName) .collect(toImmutableSet()); Set allowedCatalogs = accessControl.filterCatalogs(session.toSecurityContext(), catalogNames); return catalogs.stream() - .filter(catalogInfo -> allowedCatalogs.contains(catalogInfo.getCatalogName())) + .filter(catalogInfo -> allowedCatalogs.contains(catalogInfo.catalogName())) .collect(toImmutableList()); } diff --git a/core/trino-main/src/main/java/io/trino/metadata/SessionPropertyManager.java b/core/trino-main/src/main/java/io/trino/metadata/SessionPropertyManager.java index 8c818d418a3a..f3f3afd4802d 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/SessionPropertyManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/SessionPropertyManager.java @@ -134,8 +134,8 @@ public List getAllSessionProperties(Session session, List< } for (CatalogInfo catalogInfo : catalogInfos) { - CatalogHandle catalogHandle = catalogInfo.getCatalogHandle(); - String catalogName = catalogInfo.getCatalogName(); + CatalogHandle catalogHandle = catalogInfo.catalogHandle(); + String catalogName = catalogInfo.catalogName(); Map connectorProperties = session.getCatalogProperties(catalogName); for (PropertyMetadata property : new TreeMap<>(connectorSessionProperties.getService(catalogHandle)).values()) { diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java b/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java index 85c83a7b0a37..d1f5ee107c93 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java @@ -143,7 +143,7 @@ public SubPlan createSubPlans( Map unchangedSubPlans) { List activeCatalogs = transactionManager.getActiveCatalogs(session.getTransactionId().orElseThrow()).stream() - .map(CatalogInfo::getCatalogHandle) + .map(CatalogInfo::catalogHandle) .flatMap(catalogHandle -> catalogManager.getCatalogProperties(catalogHandle).stream()) .collect(toImmutableList()); Map languageScalarFunctions = languageFunctionManager.serializeFunctionsForWorkers(session); diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/TableInfoSupplier.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/TableInfoSupplier.java index 36a8176704e3..92fbdbb4a16e 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/TableInfoSupplier.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/TableInfoSupplier.java @@ -46,8 +46,8 @@ public TableInfo apply(TableScanNode node) CatalogSchemaTableName tableName = metadata.getTableName(session, node.getTable()); TableProperties tableProperties = metadata.getTableProperties(session, node.getTable()); Optional connectorName = metadata.listCatalogs(session).stream() - .filter(catalogInfo -> catalogInfo.getCatalogName().equals(tableName.getCatalogName())) - .map(CatalogInfo::getConnectorName) + .filter(catalogInfo -> catalogInfo.catalogName().equals(tableName.getCatalogName())) + .map(CatalogInfo::connectorName) .map(ConnectorName::toString) .findFirst(); QualifiedObjectName objectName = new QualifiedObjectName(tableName.getCatalogName(), tableName.getSchemaTableName().getSchemaName(), tableName.getSchemaTableName().getTableName()); From cc23cb9fdd27fa7cc232fced2f7244a74dcb8848 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:01:11 +0200 Subject: [PATCH 04/21] Remove unused FunctionArgumentDefinition --- .../metadata/FunctionArgumentDefinition.java | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 core/trino-main/src/main/java/io/trino/metadata/FunctionArgumentDefinition.java diff --git a/core/trino-main/src/main/java/io/trino/metadata/FunctionArgumentDefinition.java b/core/trino-main/src/main/java/io/trino/metadata/FunctionArgumentDefinition.java deleted file mode 100644 index 354fccc4f681..000000000000 --- a/core/trino-main/src/main/java/io/trino/metadata/FunctionArgumentDefinition.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.metadata; - -import java.util.Objects; - -import static com.google.common.base.MoreObjects.toStringHelper; - -public class FunctionArgumentDefinition -{ - private final boolean nullable; - - public FunctionArgumentDefinition(boolean nullable) - { - this.nullable = nullable; - } - - public boolean isNullable() - { - return nullable; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FunctionArgumentDefinition that = (FunctionArgumentDefinition) o; - return nullable == that.nullable; - } - - @Override - public int hashCode() - { - return Objects.hash(nullable); - } - - @Override - public String toString() - { - return toStringHelper(this) - .add("nullable", nullable) - .toString(); - } -} From 4a4a4baaf9fb322463ed1fd0fcc20723bff5297a Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:02:07 +0200 Subject: [PATCH 05/21] Convert IndexHandle to record --- .../java/io/trino/metadata/IndexHandle.java | 64 +++---------------- .../io/trino/operator/index/IndexManager.java | 6 +- .../planprinter/CounterBasedAnonymizer.java | 4 +- 3 files changed, 13 insertions(+), 61 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/IndexHandle.java b/core/trino-main/src/main/java/io/trino/metadata/IndexHandle.java index 3b8c80c42bd0..ac225a49cf04 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/IndexHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/IndexHandle.java @@ -13,70 +13,22 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorIndexHandle; import io.trino.spi.connector.ConnectorTransactionHandle; -import java.util.Objects; - import static java.util.Objects.requireNonNull; -public final class IndexHandle +public record IndexHandle( + CatalogHandle catalogHandle, + ConnectorTransactionHandle transactionHandle, + ConnectorIndexHandle connectorHandle) { - private final CatalogHandle catalogHandle; - private final ConnectorTransactionHandle transactionHandle; - private final ConnectorIndexHandle connectorHandle; - - @JsonCreator - public IndexHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle, - @JsonProperty("connectorHandle") ConnectorIndexHandle connectorHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() - { - return transactionHandle; - } - - @JsonProperty - public ConnectorIndexHandle getConnectorHandle() - { - return connectorHandle; - } - - @Override - public int hashCode() - { - return Objects.hash(catalogHandle, transactionHandle, connectorHandle); - } - - @Override - public boolean equals(Object obj) + public IndexHandle { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - IndexHandle other = (IndexHandle) obj; - return Objects.equals(this.catalogHandle, other.catalogHandle) && - Objects.equals(this.transactionHandle, other.transactionHandle) && - Objects.equals(this.connectorHandle, other.connectorHandle); + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); } @Override diff --git a/core/trino-main/src/main/java/io/trino/operator/index/IndexManager.java b/core/trino-main/src/main/java/io/trino/operator/index/IndexManager.java index cd8b74ff7714..60f9a5ad87af 100644 --- a/core/trino-main/src/main/java/io/trino/operator/index/IndexManager.java +++ b/core/trino-main/src/main/java/io/trino/operator/index/IndexManager.java @@ -38,8 +38,8 @@ public IndexManager(CatalogServiceProvider indexProvider public ConnectorIndex getIndex(Session session, IndexHandle indexHandle, List lookupSchema, List outputSchema) { - ConnectorSession connectorSession = session.toConnectorSession(indexHandle.getCatalogHandle()); - ConnectorIndexProvider provider = indexProvider.getService(indexHandle.getCatalogHandle()); - return provider.getIndex(indexHandle.getTransactionHandle(), connectorSession, indexHandle.getConnectorHandle(), lookupSchema, outputSchema); + ConnectorSession connectorSession = session.toConnectorSession(indexHandle.catalogHandle()); + ConnectorIndexProvider provider = indexProvider.getService(indexHandle.catalogHandle()); + return provider.getIndex(indexHandle.transactionHandle(), connectorSession, indexHandle.connectorHandle(), lookupSchema, outputSchema); } } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index bcc9fa7224da..873f91b2b009 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -145,8 +145,8 @@ public String anonymize(ArgumentBinding argument) public String anonymize(IndexHandle indexHandle) { return formatMap(ImmutableMap.of( - "catalog", anonymize(indexHandle.getCatalogHandle().getCatalogName().toString(), ObjectType.CATALOG), - "connectorHandleType", indexHandle.getConnectorHandle().getClass().getSimpleName())); + "catalog", anonymize(indexHandle.catalogHandle().getCatalogName().toString(), ObjectType.CATALOG), + "connectorHandleType", indexHandle.connectorHandle().getClass().getSimpleName())); } @Override From 1d22e751ded0758676b897fcf2fa7f6d8f1ceadd Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:02:58 +0200 Subject: [PATCH 06/21] Convert InsertTableHandle to record --- .../io/trino/metadata/InsertTableHandle.java | 64 +++---------------- .../io/trino/metadata/MetadataManager.java | 8 +-- .../java/io/trino/split/PageSinkManager.java | 4 +- .../planprinter/CounterBasedAnonymizer.java | 4 +- .../planner/planprinter/IoPlanPrinter.java | 4 +- .../io/trino/tracing/TracingMetadata.java | 4 +- .../trino/execution/TestTableRedirection.java | 2 +- 7 files changed, 21 insertions(+), 69 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/InsertTableHandle.java b/core/trino-main/src/main/java/io/trino/metadata/InsertTableHandle.java index f21a0ac58c52..63f1ca63213d 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/InsertTableHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/InsertTableHandle.java @@ -13,70 +13,22 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorInsertTableHandle; import io.trino.spi.connector.ConnectorTransactionHandle; -import java.util.Objects; - import static java.util.Objects.requireNonNull; -public final class InsertTableHandle +public record InsertTableHandle( + CatalogHandle catalogHandle, + ConnectorTransactionHandle transactionHandle, + ConnectorInsertTableHandle connectorHandle) { - private final CatalogHandle catalogHandle; - private final ConnectorTransactionHandle transactionHandle; - private final ConnectorInsertTableHandle connectorHandle; - - @JsonCreator - public InsertTableHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle, - @JsonProperty("connectorHandle") ConnectorInsertTableHandle connectorHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() - { - return transactionHandle; - } - - @JsonProperty - public ConnectorInsertTableHandle getConnectorHandle() - { - return connectorHandle; - } - - @Override - public int hashCode() - { - return Objects.hash(catalogHandle, transactionHandle, connectorHandle); - } - - @Override - public boolean equals(Object obj) + public InsertTableHandle { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - InsertTableHandle o = (InsertTableHandle) obj; - return Objects.equals(this.catalogHandle, o.catalogHandle) && - Objects.equals(this.transactionHandle, o.transactionHandle) && - Objects.equals(this.connectorHandle, o.connectorHandle); + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); } @Override diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index 569e5eaeecda..1dcc6f9cb058 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -1160,13 +1160,13 @@ public boolean supportsMissingColumnsOnInsert(Session session, TableHandle table @Override public Optional finishInsert(Session session, InsertTableHandle tableHandle, List sourceTableHandles, Collection fragments, Collection computedStatistics) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); List sourceConnectorHandles = sourceTableHandles.stream() .filter(handle -> handle.getCatalogHandle().equals(catalogHandle)) .map(TableHandle::getConnectorHandle) .collect(toImmutableList()); - return metadata.finishInsert(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), sourceConnectorHandles, fragments, computedStatistics); + return metadata.finishInsert(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), sourceConnectorHandles, fragments, computedStatistics); } @Override @@ -1220,7 +1220,7 @@ public Optional finishRefreshMaterializedView( List sourceTableHandles, List sourceTableFunctions) { - CatalogHandle catalogHandle = insertHandle.getCatalogHandle(); + CatalogHandle catalogHandle = insertHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); List sourceConnectorHandles = sourceTableHandles.stream() @@ -1229,7 +1229,7 @@ public Optional finishRefreshMaterializedView( return metadata.finishRefreshMaterializedView( session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), - insertHandle.getConnectorHandle(), + insertHandle.connectorHandle(), fragments, computedStatistics, sourceConnectorHandles, diff --git a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java index 512aae433232..c2ffb28363e1 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java @@ -52,8 +52,8 @@ public ConnectorPageSink createPageSink(Session session, OutputTableHandle table public ConnectorPageSink createPageSink(Session session, InsertTableHandle tableHandle, ConnectorPageSinkId pageSinkId) { // assumes connectorId and catalog are the same - ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getCatalogHandle()); - return providerFor(tableHandle.getCatalogHandle()).createPageSink(tableHandle.getTransactionHandle(), connectorSession, tableHandle.getConnectorHandle(), pageSinkId); + ConnectorSession connectorSession = session.toConnectorSession(tableHandle.catalogHandle()); + return providerFor(tableHandle.catalogHandle()).createPageSink(tableHandle.transactionHandle(), connectorSession, tableHandle.connectorHandle(), pageSinkId); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index 873f91b2b009..93da4ce2823c 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -229,7 +229,7 @@ private String anonymize(CreateTarget target) private String anonymize(InsertTarget target) { return anonymize( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName()); } @@ -245,7 +245,7 @@ private String anonymize(MergeTarget target) private String anonymize(RefreshMaterializedViewTarget target) { return anonymize( - target.getInsertHandle().getCatalogHandle().getCatalogName().toString(), + target.getInsertHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName()); } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java index 893da6129ba0..e8bedf2db364 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java @@ -699,7 +699,7 @@ public Void visitTableFinish(TableFinishNode node, IoPlanBuilder context) } else if (writerTarget instanceof InsertTarget target) { context.setOutputTable(new CatalogSchemaTableName( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName())); } @@ -711,7 +711,7 @@ else if (writerTarget instanceof MergeTarget target) { } else if (writerTarget instanceof TableWriterNode.RefreshMaterializedViewTarget target) { context.setOutputTable(new CatalogSchemaTableName( - target.getInsertHandle().getCatalogHandle().getCatalogName().toString(), + target.getInsertHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName())); } diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index 5eb1c6021e7f..f2dece73ce19 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -698,9 +698,9 @@ public boolean supportsMissingColumnsOnInsert(Session session, TableHandle table @Override public Optional finishInsert(Session session, InsertTableHandle tableHandle, List sourceTableHandles, Collection fragments, Collection computedStatistics) { - Span span = startSpan("finishInsert", tableHandle.getCatalogHandle().getCatalogName()); + Span span = startSpan("finishInsert", tableHandle.catalogHandle().getCatalogName()); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.TABLE, tableHandle.getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.TABLE, tableHandle.connectorHandle().toString()); } try (var ignored = scopedSpan(span)) { return delegate.finishInsert(session, tableHandle, sourceTableHandles, fragments, computedStatistics); diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java index e89094adb2e4..f95bd7c5cbfb 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java @@ -410,7 +410,7 @@ public void testInsert() .where(TableFinishNode.class::isInstance) .findOnlyElement(); TableWriterNode.InsertTarget insertTarget = ((TableWriterNode.InsertTarget) finishNode.getTarget()); - assertThat(((MockConnectorInsertTableHandle) insertTarget.getHandle().getConnectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); + assertThat(((MockConnectorInsertTableHandle) insertTarget.getHandle().connectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); assertThat(insertTarget.getSchemaTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); }); } From 426b44a5e4ce4529222633e8003b05fa3b8f0484 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:03:50 +0200 Subject: [PATCH 07/21] Convert FunctionKey to record --- .../metadata/InternalFunctionBundle.java | 52 ++----------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/InternalFunctionBundle.java b/core/trino-main/src/main/java/io/trino/metadata/InternalFunctionBundle.java index 54a8b6c65f50..24f7d2a87084 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/InternalFunctionBundle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/InternalFunctionBundle.java @@ -41,10 +41,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.function.Function; -import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Throwables.throwIfInstanceOf; import static com.google.common.collect.ImmutableList.toImmutableList; @@ -280,54 +278,12 @@ public InternalFunctionBundle build() } } - private static class FunctionKey + private record FunctionKey(FunctionId functionId, BoundSignature boundSignature) { - private final FunctionId functionId; - private final BoundSignature boundSignature; - - public FunctionKey(FunctionId functionId, BoundSignature boundSignature) - { - this.functionId = requireNonNull(functionId, "functionId is null"); - this.boundSignature = requireNonNull(boundSignature, "boundSignature is null"); - } - - public FunctionId getFunctionId() - { - return functionId; - } - - public BoundSignature getBoundSignature() - { - return boundSignature; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FunctionKey that = (FunctionKey) o; - return functionId.equals(that.functionId) && - boundSignature.equals(that.boundSignature); - } - - @Override - public int hashCode() - { - return Objects.hash(functionId, boundSignature); - } - - @Override - public String toString() + private FunctionKey { - return toStringHelper(this) - .add("functionId", functionId) - .add("boundSignature", boundSignature) - .toString(); + requireNonNull(functionId, "functionId is null"); + requireNonNull(boundSignature, "boundSignature is null"); } } } From a8bed0a91e82f156218f8227099a615c95e59d32 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:06:33 +0200 Subject: [PATCH 08/21] Convert MergeHandle to record --- .../java/io/trino/metadata/MergeHandle.java | 28 +++---------------- .../io/trino/metadata/MetadataManager.java | 4 +-- .../java/io/trino/split/PageSinkManager.java | 4 +-- .../optimizations/BeginTableWrite.java | 2 +- .../io/trino/tracing/TracingMetadata.java | 4 +-- 5 files changed, 11 insertions(+), 31 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MergeHandle.java b/core/trino-main/src/main/java/io/trino/metadata/MergeHandle.java index 39a598a59cd2..5a500a931872 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MergeHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MergeHandle.java @@ -13,35 +13,15 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.ConnectorMergeTableHandle; import static java.util.Objects.requireNonNull; -public final class MergeHandle +public record MergeHandle(TableHandle tableHandle, ConnectorMergeTableHandle connectorMergeHandle) { - private final TableHandle tableHandle; - private final ConnectorMergeTableHandle connectorMergeHandle; - - @JsonCreator - public MergeHandle( - @JsonProperty("tableHandle") TableHandle tableHandle, - @JsonProperty("connectorMergeHandle") ConnectorMergeTableHandle connectorMergeHandle) - { - this.tableHandle = requireNonNull(tableHandle, "tableHandle is null"); - this.connectorMergeHandle = requireNonNull(connectorMergeHandle, "connectorMergeHandle is null"); - } - - @JsonProperty - public TableHandle getTableHandle() - { - return tableHandle; - } - - @JsonProperty - public ConnectorMergeTableHandle getConnectorMergeHandle() + public MergeHandle { - return connectorMergeHandle; + requireNonNull(tableHandle, "tableHandle is null"); + requireNonNull(connectorMergeHandle, "connectorMergeHandle is null"); } } diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index 1dcc6f9cb058..f139b306fa30 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -1318,9 +1318,9 @@ public MergeHandle beginMerge(Session session, TableHandle tableHandle) @Override public void finishMerge(Session session, MergeHandle mergeHandle, Collection fragments, Collection computedStatistics) { - CatalogHandle catalogHandle = mergeHandle.getTableHandle().getCatalogHandle(); + CatalogHandle catalogHandle = mergeHandle.tableHandle().getCatalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - metadata.finishMerge(session.toConnectorSession(catalogHandle), mergeHandle.getConnectorMergeHandle(), fragments, computedStatistics); + metadata.finishMerge(session.toConnectorSession(catalogHandle), mergeHandle.connectorMergeHandle(), fragments, computedStatistics); } @Override diff --git a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java index c2ffb28363e1..ad7cbb72cef2 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java @@ -68,9 +68,9 @@ public ConnectorPageSink createPageSink(Session session, TableExecuteHandle tabl public ConnectorMergeSink createMergeSink(Session session, MergeHandle mergeHandle, ConnectorPageSinkId pageSinkId) { // assumes connectorId and catalog are the same - TableHandle tableHandle = mergeHandle.getTableHandle(); + TableHandle tableHandle = mergeHandle.tableHandle(); ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getCatalogHandle()); - return providerFor(tableHandle.getCatalogHandle()).createMergeSink(tableHandle.getTransaction(), connectorSession, mergeHandle.getConnectorMergeHandle(), pageSinkId); + return providerFor(tableHandle.getCatalogHandle()).createMergeSink(tableHandle.getTransaction(), connectorSession, mergeHandle.connectorMergeHandle(), pageSinkId); } private ConnectorPageSinkProvider providerFor(CatalogHandle catalogHandle) diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/BeginTableWrite.java b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/BeginTableWrite.java index 03780bbed88f..7b95ea916fd2 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/BeginTableWrite.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/BeginTableWrite.java @@ -248,7 +248,7 @@ private WriterTarget createWriterTarget(WriterTarget target, PlanNode planNode) if (target instanceof MergeTarget merge) { MergeHandle mergeHandle = metadata.beginMerge(session, merge.getHandle()); return new MergeTarget( - mergeHandle.getTableHandle(), + mergeHandle.tableHandle(), Optional.of(mergeHandle), merge.getSchemaTableName(), merge.getMergeParadigmAndTypes()); diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index f2dece73ce19..6af602274cc9 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -832,9 +832,9 @@ public MergeHandle beginMerge(Session session, TableHandle tableHandle) @Override public void finishMerge(Session session, MergeHandle tableHandle, Collection fragments, Collection computedStatistics) { - Span span = startSpan("finishMerge", tableHandle.getTableHandle().getCatalogHandle().getCatalogName()); + Span span = startSpan("finishMerge", tableHandle.tableHandle().getCatalogHandle().getCatalogName()); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.TABLE, tableHandle.getTableHandle().getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.TABLE, tableHandle.tableHandle().getConnectorHandle().toString()); } try (var ignored = scopedSpan(span)) { delegate.finishMerge(session, tableHandle, fragments, computedStatistics); From 4fdb6bf03f1f1341250103a2d4f0bd9fd3cb08b0 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:07:29 +0200 Subject: [PATCH 09/21] Convert OutputTableHandle to record --- .../io/trino/metadata/MetadataManager.java | 6 +-- .../io/trino/metadata/OutputTableHandle.java | 52 ++++--------------- .../java/io/trino/split/PageSinkManager.java | 4 +- .../planprinter/CounterBasedAnonymizer.java | 2 +- .../planner/planprinter/IoPlanPrinter.java | 2 +- .../io/trino/tracing/TracingMetadata.java | 4 +- 6 files changed, 19 insertions(+), 51 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index f139b306fa30..ecd1708c27d5 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -1127,13 +1127,13 @@ public OutputTableHandle beginCreateTable(Session session, String catalogName, C @Override public Optional finishCreateTable(Session session, OutputTableHandle tableHandle, Collection fragments, Collection computedStatistics) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - Optional output = metadata.finishCreateTable(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), fragments, computedStatistics); + Optional output = metadata.finishCreateTable(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), fragments, computedStatistics); if (catalogMetadata.getSecurityManagement() == SYSTEM) { - systemSecurityMetadata.tableCreated(session, new CatalogSchemaTableName(catalogHandle.getCatalogName().toString(), tableHandle.getTableName())); + systemSecurityMetadata.tableCreated(session, new CatalogSchemaTableName(catalogHandle.getCatalogName().toString(), tableHandle.tableName())); } return output; } diff --git a/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java b/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java index 80ace4d4f5ce..69442579726e 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java @@ -13,8 +13,6 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorOutputTableHandle; import io.trino.spi.connector.ConnectorTransactionHandle; @@ -24,48 +22,18 @@ import static java.util.Objects.requireNonNull; -public final class OutputTableHandle +public record OutputTableHandle( + CatalogHandle catalogHandle, + SchemaTableName tableName, + ConnectorTransactionHandle transactionHandle, + ConnectorOutputTableHandle connectorHandle) { - private final CatalogHandle catalogHandle; - private final SchemaTableName tableName; - private final ConnectorTransactionHandle transactionHandle; - private final ConnectorOutputTableHandle connectorHandle; - - @JsonCreator - public OutputTableHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("tableName") SchemaTableName tableName, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle, - @JsonProperty("connectorHandle") ConnectorOutputTableHandle connectorHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.tableName = requireNonNull(tableName, "tableName is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - @JsonProperty - public SchemaTableName getTableName() - { - return tableName; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() - { - return transactionHandle; - } - - @JsonProperty - public ConnectorOutputTableHandle getConnectorHandle() + public OutputTableHandle { - return connectorHandle; + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(tableName, "tableName is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); } @Override diff --git a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java index ad7cbb72cef2..204a4353c7d3 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java @@ -44,8 +44,8 @@ public PageSinkManager(CatalogServiceProvider pageSin @Override public ConnectorPageSink createPageSink(Session session, OutputTableHandle tableHandle, ConnectorPageSinkId pageSinkId) { - ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getCatalogHandle()); - return providerFor(tableHandle.getCatalogHandle()).createPageSink(tableHandle.getTransactionHandle(), connectorSession, tableHandle.getConnectorHandle(), pageSinkId); + ConnectorSession connectorSession = session.toConnectorSession(tableHandle.catalogHandle()); + return providerFor(tableHandle.catalogHandle()).createPageSink(tableHandle.transactionHandle(), connectorSession, tableHandle.connectorHandle(), pageSinkId); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index 93da4ce2823c..26abda0ad43f 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -221,7 +221,7 @@ public String anonymize(TableExecuteHandle tableHandle) private String anonymize(CreateTarget target) { return anonymize( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName()); } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java index e8bedf2db364..df07806678ed 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java @@ -693,7 +693,7 @@ public Void visitTableFinish(TableFinishNode node, IoPlanBuilder context) WriterTarget writerTarget = node.getTarget(); if (writerTarget instanceof CreateTarget target) { context.setOutputTable(new CatalogSchemaTableName( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName())); } diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index 6af602274cc9..efa94a5fffda 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -602,9 +602,9 @@ public OutputTableHandle beginCreateTable(Session session, String catalogName, C @Override public Optional finishCreateTable(Session session, OutputTableHandle tableHandle, Collection fragments, Collection computedStatistics) { - Span span = startSpan("finishCreateTable", tableHandle.getCatalogHandle().getCatalogName()); + Span span = startSpan("finishCreateTable", tableHandle.catalogHandle().getCatalogName()); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.TABLE, tableHandle.getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.TABLE, tableHandle.connectorHandle().toString()); } try (var ignored = scopedSpan(span)) { return delegate.finishCreateTable(session, tableHandle, fragments, computedStatistics); From 4492e26cd2b697d23de4e7d7204b258091f1c234 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:08:17 +0200 Subject: [PATCH 10/21] Convert PolymorphicScalarFunctionChoice to record --- .../metadata/PolymorphicScalarFunction.java | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java index ad0674064d7c..8f56b028d985 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java +++ b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java @@ -72,9 +72,9 @@ private ScalarImplementationChoice getScalarFunctionImplementationChoice( Optional matchingMethod = Optional.empty(); Optional matchingMethodsGroup = Optional.empty(); - for (MethodsGroup candidateMethodsGroup : choice.getMethodsGroups()) { + for (MethodsGroup candidateMethodsGroup : choice.methodsGroups()) { for (MethodAndNativeContainerTypes candidateMethod : candidateMethodsGroup.getMethods()) { - if (matchesParameterAndReturnTypes(candidateMethod, functionBinding.getBoundSignature(), choice.getArgumentConventions(), choice.getReturnConvention())) { + if (matchesParameterAndReturnTypes(candidateMethod, functionBinding.getBoundSignature(), choice.argumentConventions(), choice.returnConvention())) { if (matchingMethod.isPresent()) { throw new IllegalStateException("two matching methods (" + matchingMethod.get().getMethod().getName() + " and " + candidateMethod.getMethod().getName() + ") for parameter types " + functionBinding.getBoundSignature().getArgumentTypes()); } @@ -87,10 +87,10 @@ private ScalarImplementationChoice getScalarFunctionImplementationChoice( checkState(matchingMethod.isPresent(), "no matching method for parameter types %s", functionBinding.getBoundSignature()); List extraParameters = computeExtraParameters(matchingMethodsGroup.get(), context); - MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().getMethod(), extraParameters, choice.getArgumentConventions()); + MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().getMethod(), extraParameters, choice.argumentConventions()); return new ScalarImplementationChoice( - choice.getReturnConvention(), - choice.getArgumentConventions(), + choice.returnConvention(), + choice.argumentConventions(), ImmutableList.of(), methodHandle, Optional.empty()); @@ -181,35 +181,16 @@ private static Class getNullAwareContainerType(Class clazz, InvocationRetu }; } - static final class PolymorphicScalarFunctionChoice + record PolymorphicScalarFunctionChoice( + InvocationReturnConvention returnConvention, + List argumentConventions, + List methodsGroups) { - private final InvocationReturnConvention returnConvention; - private final List argumentConventions; - private final List methodsGroups; - - PolymorphicScalarFunctionChoice( - InvocationReturnConvention returnConvention, - List argumentConventions, - List methodsGroups) - { - this.returnConvention = requireNonNull(returnConvention, "returnConvention is null"); - this.argumentConventions = ImmutableList.copyOf(requireNonNull(argumentConventions, "argumentConventions is null")); - this.methodsGroups = ImmutableList.copyOf(requireNonNull(methodsGroups, "methodsGroups is null")); - } - - InvocationReturnConvention getReturnConvention() - { - return returnConvention; - } - - List getMethodsGroups() - { - return methodsGroups; - } - - List getArgumentConventions() + PolymorphicScalarFunctionChoice { - return argumentConventions; + requireNonNull(returnConvention, "returnConvention is null"); + argumentConventions = ImmutableList.copyOf(requireNonNull(argumentConventions, "argumentConventions is null")); + methodsGroups = ImmutableList.copyOf(requireNonNull(methodsGroups, "methodsGroups is null")); } } } From b7ff58f68f05232a6a190b52b21ae4cb5151bf90 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:08:42 +0200 Subject: [PATCH 11/21] Convert MethodAndNativeContainerTypes to record --- .../metadata/PolymorphicScalarFunction.java | 8 +++---- .../PolymorphicScalarFunctionBuilder.java | 22 +------------------ 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java index 8f56b028d985..85eb4cf676fa 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java +++ b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunction.java @@ -76,7 +76,7 @@ private ScalarImplementationChoice getScalarFunctionImplementationChoice( for (MethodAndNativeContainerTypes candidateMethod : candidateMethodsGroup.getMethods()) { if (matchesParameterAndReturnTypes(candidateMethod, functionBinding.getBoundSignature(), choice.argumentConventions(), choice.returnConvention())) { if (matchingMethod.isPresent()) { - throw new IllegalStateException("two matching methods (" + matchingMethod.get().getMethod().getName() + " and " + candidateMethod.getMethod().getName() + ") for parameter types " + functionBinding.getBoundSignature().getArgumentTypes()); + throw new IllegalStateException("two matching methods (" + matchingMethod.get().method().getName() + " and " + candidateMethod.method().getName() + ") for parameter types " + functionBinding.getBoundSignature().getArgumentTypes()); } matchingMethod = Optional.of(candidateMethod); @@ -87,7 +87,7 @@ private ScalarImplementationChoice getScalarFunctionImplementationChoice( checkState(matchingMethod.isPresent(), "no matching method for parameter types %s", functionBinding.getBoundSignature()); List extraParameters = computeExtraParameters(matchingMethodsGroup.get(), context); - MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().getMethod(), extraParameters, choice.argumentConventions()); + MethodHandle methodHandle = applyExtraParameters(matchingMethod.get().method(), extraParameters, choice.argumentConventions()); return new ScalarImplementationChoice( choice.returnConvention(), choice.argumentConventions(), @@ -102,7 +102,7 @@ private static boolean matchesParameterAndReturnTypes( List argumentConventions, InvocationReturnConvention returnConvention) { - Method method = methodAndNativeContainerTypes.getMethod(); + Method method = methodAndNativeContainerTypes.method(); checkState(method.getParameterCount() >= boundSignature.getArity(), "method %s has not enough arguments: %s (should have at least %s)", method.getName(), method.getParameterCount(), boundSignature.getArity()); @@ -125,7 +125,7 @@ private static boolean matchesParameterAndReturnTypes( actualType = Primitives.wrap(resolvedType.getJavaType()); break; case BLOCK_POSITION: - Optional> explicitNativeContainerTypes = methodAndNativeContainerTypes.getExplicitNativeContainerTypes().get(i); + Optional> explicitNativeContainerTypes = methodAndNativeContainerTypes.explicitNativeContainerTypes().get(i); if (explicitNativeContainerTypes.isPresent()) { expectedType = explicitNativeContainerTypes.get(); } diff --git a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunctionBuilder.java b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunctionBuilder.java index 972c5d8235ef..eadebdb42001 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunctionBuilder.java +++ b/core/trino-main/src/main/java/io/trino/metadata/PolymorphicScalarFunctionBuilder.java @@ -341,25 +341,5 @@ Optional>> getExtraParametersFunction() } } - static class MethodAndNativeContainerTypes - { - private final Method method; - private final List>> explicitNativeContainerTypes; - - MethodAndNativeContainerTypes(Method method, List>> explicitNativeContainerTypes) - { - this.method = method; - this.explicitNativeContainerTypes = explicitNativeContainerTypes; - } - - public Method getMethod() - { - return method; - } - - List>> getExplicitNativeContainerTypes() - { - return explicitNativeContainerTypes; - } - } + record MethodAndNativeContainerTypes(Method method, List>> explicitNativeContainerTypes) {} } From 5b3e555e783e53f3095bc03237b913c9081629ba Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:11:55 +0200 Subject: [PATCH 12/21] Convert FunctionTypeVariables to record --- .../src/main/java/io/trino/metadata/SignatureBinder.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/SignatureBinder.java b/core/trino-main/src/main/java/io/trino/metadata/SignatureBinder.java index feac419becd9..138ab90eeb3c 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/SignatureBinder.java +++ b/core/trino-main/src/main/java/io/trino/metadata/SignatureBinder.java @@ -1048,14 +1048,12 @@ public enum RelationshipType EXACT, IMPLICIT_COERCION, EXPLICIT_COERCION_TO, EXPLICIT_COERCION_FROM } - private static final class FunctionTypeVariables + private record FunctionTypeVariables(FunctionBinding functionBinding) implements TypeVariables { - private final FunctionBinding functionBinding; - - public FunctionTypeVariables(FunctionBinding functionBinding) + private FunctionTypeVariables { - this.functionBinding = requireNonNull(functionBinding, "functionBinding is null"); + requireNonNull(functionBinding, "functionBinding is null"); } @Override From 528513d15bf629ca836cd33dfc2f73e703cf1eba Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:13:38 +0200 Subject: [PATCH 13/21] Convert TableExecuteHandle to record --- .../io/trino/metadata/MetadataManager.java | 16 ++--- .../io/trino/metadata/TableExecuteHandle.java | 64 +++---------------- .../java/io/trino/split/PageSinkManager.java | 4 +- .../trino/sql/analyzer/StatementAnalyzer.java | 2 +- .../sql/planner/plan/TableWriterNode.java | 2 +- .../planprinter/CounterBasedAnonymizer.java | 4 +- .../io/trino/tracing/TracingMetadata.java | 4 +- 7 files changed, 24 insertions(+), 72 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index ecd1708c27d5..96bfea24b056 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -321,21 +321,21 @@ public Optional getTableHandleForExecute(Session session, Ta @Override public Optional getLayoutForTableExecute(Session session, TableExecuteHandle tableExecuteHandle) { - CatalogHandle catalogHandle = tableExecuteHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableExecuteHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - return metadata.getLayoutForTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.getConnectorHandle()) + return metadata.getLayoutForTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.connectorHandle()) .map(layout -> new TableLayout(catalogHandle, catalogMetadata.getTransactionHandleFor(catalogHandle), layout)); } @Override public BeginTableExecuteResult beginTableExecute(Session session, TableExecuteHandle tableExecuteHandle, TableHandle sourceHandle) { - CatalogHandle catalogHandle = tableExecuteHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableExecuteHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - BeginTableExecuteResult connectorBeginResult = metadata.beginTableExecute(session.toConnectorSession(), tableExecuteHandle.getConnectorHandle(), sourceHandle.getConnectorHandle()); + BeginTableExecuteResult connectorBeginResult = metadata.beginTableExecute(session.toConnectorSession(), tableExecuteHandle.connectorHandle(), sourceHandle.getConnectorHandle()); return new BeginTableExecuteResult<>( tableExecuteHandle.withConnectorHandle(connectorBeginResult.getTableExecuteHandle()), @@ -345,17 +345,17 @@ public BeginTableExecuteResult beginTableExecut @Override public void finishTableExecute(Session session, TableExecuteHandle tableExecuteHandle, Collection fragments, List tableExecuteState) { - CatalogHandle catalogHandle = tableExecuteHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableExecuteHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - metadata.finishTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.getConnectorHandle(), fragments, tableExecuteState); + metadata.finishTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.connectorHandle(), fragments, tableExecuteState); } @Override public void executeTableExecute(Session session, TableExecuteHandle tableExecuteHandle) { - CatalogHandle catalogHandle = tableExecuteHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableExecuteHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - metadata.executeTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.getConnectorHandle()); + metadata.executeTableExecute(session.toConnectorSession(catalogHandle), tableExecuteHandle.connectorHandle()); } @Override diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableExecuteHandle.java b/core/trino-main/src/main/java/io/trino/metadata/TableExecuteHandle.java index f1f9a7e0dc4f..23f76a01c5d9 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableExecuteHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableExecuteHandle.java @@ -13,53 +13,26 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorTableExecuteHandle; import io.trino.spi.connector.ConnectorTransactionHandle; -import java.util.Objects; - import static java.util.Objects.requireNonNull; /** * TableExecuteHandle wraps connectors ConnectorTableExecuteHandle which identifies instance of executing * specific table procedure o specific table. See {#link {@link ConnectorTableExecuteHandle}} for more details. */ -public final class TableExecuteHandle +public record TableExecuteHandle( + CatalogHandle catalogHandle, + ConnectorTransactionHandle transactionHandle, + ConnectorTableExecuteHandle connectorHandle) { - private final CatalogHandle catalogHandle; - private final ConnectorTransactionHandle transactionHandle; - private final ConnectorTableExecuteHandle connectorHandle; - - @JsonCreator - public TableExecuteHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle, - @JsonProperty("connectorHandle") ConnectorTableExecuteHandle connectorHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() + public TableExecuteHandle { - return catalogHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() - { - return transactionHandle; - } - - @JsonProperty - public ConnectorTableExecuteHandle getConnectorHandle() - { - return connectorHandle; + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); } public TableExecuteHandle withConnectorHandle(ConnectorTableExecuteHandle connectorHandle) @@ -67,27 +40,6 @@ public TableExecuteHandle withConnectorHandle(ConnectorTableExecuteHandle connec return new TableExecuteHandle(catalogHandle, transactionHandle, connectorHandle); } - @Override - public boolean equals(Object obj) - { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - TableExecuteHandle o = (TableExecuteHandle) obj; - return Objects.equals(this.catalogHandle, o.catalogHandle) && - Objects.equals(this.transactionHandle, o.transactionHandle) && - Objects.equals(this.connectorHandle, o.connectorHandle); - } - - @Override - public int hashCode() - { - return Objects.hash(catalogHandle, transactionHandle, connectorHandle); - } - @Override public String toString() { diff --git a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java index 204a4353c7d3..5757c7679d65 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java @@ -60,8 +60,8 @@ public ConnectorPageSink createPageSink(Session session, InsertTableHandle table public ConnectorPageSink createPageSink(Session session, TableExecuteHandle tableHandle, ConnectorPageSinkId pageSinkId) { // assumes connectorId and catalog are the same - ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getCatalogHandle()); - return providerFor(tableHandle.getCatalogHandle()).createPageSink(tableHandle.getTransactionHandle(), connectorSession, tableHandle.getConnectorHandle(), pageSinkId); + ConnectorSession connectorSession = session.toConnectorSession(tableHandle.catalogHandle()); + return providerFor(tableHandle.catalogHandle()).createPageSink(tableHandle.transactionHandle(), connectorSession, tableHandle.connectorHandle(), pageSinkId); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index 3da56635f729..f72a216a8b8c 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -1300,7 +1300,7 @@ protected Scope visitTableExecute(TableExecute node, Optional scope) analysis.setTableExecuteHandle(executeHandle); analysis.setUpdateType("ALTER TABLE EXECUTE"); - analysis.setUpdateTarget(executeHandle.getCatalogHandle().getVersion(), tableName, Optional.of(table), Optional.empty()); + analysis.setUpdateTarget(executeHandle.catalogHandle().getVersion(), tableName, Optional.of(table), Optional.empty()); return createAndAssignScope(node, scope, Field.newUnqualified("rows", BIGINT)); } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java b/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java index a5d77c51bd26..015227e2e54b 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java @@ -835,7 +835,7 @@ public boolean supportsMultipleWritersPerPartition(Metadata metadata, Session se @Override public OptionalInt getMaxWriterTasks(Metadata metadata, Session session) { - return metadata.getMaxWriterTasks(session, executeHandle.getCatalogHandle().getCatalogName().toString()); + return metadata.getMaxWriterTasks(session, executeHandle.catalogHandle().getCatalogName().toString()); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index 26abda0ad43f..81bf6343974e 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -215,7 +215,7 @@ public String anonymize(TableHandle tableHandle) @Override public String anonymize(TableExecuteHandle tableHandle) { - return anonymize(tableHandle.getCatalogHandle().getCatalogName().toString(), ObjectType.CATALOG); + return anonymize(tableHandle.catalogHandle().getCatalogName().toString(), ObjectType.CATALOG); } private String anonymize(CreateTarget target) @@ -253,7 +253,7 @@ private String anonymize(RefreshMaterializedViewTarget target) private String anonymize(TableExecuteTarget target) { return anonymize( - target.getExecuteHandle().getCatalogHandle().getCatalogName().toString(), + target.getExecuteHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName()); } diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index efa94a5fffda..63f7e264c55d 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -1605,8 +1605,8 @@ private Span startSpan(String methodName, TableExecuteHandle handle) { Span span = startSpan(methodName); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.CATALOG, handle.getCatalogHandle().getCatalogName().toString()); - span.setAttribute(TrinoAttributes.HANDLE, handle.getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.CATALOG, handle.catalogHandle().getCatalogName().toString()); + span.setAttribute(TrinoAttributes.HANDLE, handle.connectorHandle().toString()); } return span; } From 8773b3d2fb39be9ee58280a128382dd838253eba Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:14:21 +0200 Subject: [PATCH 14/21] Convert TableFunctionHandle to record --- .../io/trino/metadata/FunctionManager.java | 4 +- .../io/trino/metadata/MetadataManager.java | 6 +-- .../trino/metadata/TableFunctionHandle.java | 41 ++++--------------- .../java/io/trino/split/SplitManager.java | 8 ++-- .../sql/planner/LocalExecutionPlanner.java | 8 ++-- .../io/trino/tracing/TracingMetadata.java | 4 +- .../io/trino/sql/planner/TestJsonTable.java | 2 +- 7 files changed, 24 insertions(+), 49 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/FunctionManager.java b/core/trino-main/src/main/java/io/trino/metadata/FunctionManager.java index df01f2cbe6a8..12c2fb14b39c 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/FunctionManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/FunctionManager.java @@ -159,7 +159,7 @@ private WindowFunctionSupplier getWindowFunctionSupplierInternal(ResolvedFunctio public TableFunctionProcessorProvider getTableFunctionProcessorProvider(TableFunctionHandle tableFunctionHandle) { - CatalogHandle catalogHandle = tableFunctionHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableFunctionHandle.catalogHandle(); FunctionProvider provider; if (catalogHandle.equals(GlobalSystemConnector.CATALOG_HANDLE)) { @@ -170,7 +170,7 @@ public TableFunctionProcessorProvider getTableFunctionProcessorProvider(TableFun checkArgument(provider != null, "No function provider for catalog: '%s'", catalogHandle); } - return provider.getTableFunctionProcessorProvider(tableFunctionHandle.getFunctionHandle()); + return provider.getTableFunctionProcessorProvider(tableFunctionHandle.functionHandle()); } private FunctionDependencies getFunctionDependencies(ResolvedFunction resolvedFunction) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index 96bfea24b056..04beed745194 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -2068,12 +2068,12 @@ public Optional> applyTopN( @Override public Optional> applyTableFunction(Session session, TableFunctionHandle handle) { - CatalogHandle catalogHandle = handle.getCatalogHandle(); + CatalogHandle catalogHandle = handle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - return metadata.applyTableFunction(session.toConnectorSession(catalogHandle), handle.getFunctionHandle()) + return metadata.applyTableFunction(session.toConnectorSession(catalogHandle), handle.functionHandle()) .map(result -> new TableFunctionApplicationResult<>( - new TableHandle(catalogHandle, result.getTableHandle(), handle.getTransactionHandle()), + new TableHandle(catalogHandle, result.getTableHandle(), handle.transactionHandle()), result.getColumnHandles())); } diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableFunctionHandle.java b/core/trino-main/src/main/java/io/trino/metadata/TableFunctionHandle.java index 6f6865ab762c..e12867e39aa4 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableFunctionHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableFunctionHandle.java @@ -13,46 +13,21 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorTransactionHandle; import io.trino.spi.function.table.ConnectorTableFunctionHandle; import static java.util.Objects.requireNonNull; -public class TableFunctionHandle +public record TableFunctionHandle( + CatalogHandle catalogHandle, + ConnectorTableFunctionHandle functionHandle, + ConnectorTransactionHandle transactionHandle) { - private final CatalogHandle catalogHandle; - private final ConnectorTableFunctionHandle functionHandle; - private final ConnectorTransactionHandle transactionHandle; - - @JsonCreator - public TableFunctionHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("functionHandle") ConnectorTableFunctionHandle functionHandle, - @JsonProperty("transactionHandle") ConnectorTransactionHandle transactionHandle) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.functionHandle = requireNonNull(functionHandle, "functionHandle is null"); - this.transactionHandle = requireNonNull(transactionHandle, "transactionHandle is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - @JsonProperty - public ConnectorTableFunctionHandle getFunctionHandle() - { - return functionHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransactionHandle() + public TableFunctionHandle { - return transactionHandle; + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(functionHandle, "functionHandle is null"); + requireNonNull(transactionHandle, "transactionHandle is null"); } } diff --git a/core/trino-main/src/main/java/io/trino/split/SplitManager.java b/core/trino-main/src/main/java/io/trino/split/SplitManager.java index e43e4d2da411..a34e114b719c 100644 --- a/core/trino-main/src/main/java/io/trino/split/SplitManager.java +++ b/core/trino-main/src/main/java/io/trino/split/SplitManager.java @@ -112,18 +112,18 @@ public SplitSource getSplits( public SplitSource getSplits(Session session, Span parentSpan, TableFunctionHandle function) { - CatalogHandle catalogHandle = function.getCatalogHandle(); + CatalogHandle catalogHandle = function.catalogHandle(); ConnectorSplitManager splitManager = splitManagerProvider.getService(catalogHandle); ConnectorSplitSource source; try (var ignore = scopedSpan(tracer.spanBuilder("SplitManager.getSplits") .setParent(Context.current().with(parentSpan)) - .setAttribute(TrinoAttributes.FUNCTION, function.getFunctionHandle().toString()) + .setAttribute(TrinoAttributes.FUNCTION, function.functionHandle().toString()) .startSpan())) { source = splitManager.getSplits( - function.getTransactionHandle(), + function.transactionHandle(), session.toConnectorSession(catalogHandle), - function.getFunctionHandle()); + function.functionHandle()); } SplitSource splitSource = new ConnectorAwareSplitSource(catalogHandle, source); diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/LocalExecutionPlanner.java b/core/trino-main/src/main/java/io/trino/sql/planner/LocalExecutionPlanner.java index 6be494f04d25..896bbe52e204 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/LocalExecutionPlanner.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/LocalExecutionPlanner.java @@ -1628,9 +1628,9 @@ public PhysicalOperation visitTableFunctionProcessor(TableFunctionProcessorNode OperatorFactory operatorFactory = new LeafTableFunctionOperatorFactory( context.getNextOperatorId(), node.getId(), - node.getHandle().getCatalogHandle(), + node.getHandle().catalogHandle(), processorProvider, - node.getHandle().getFunctionHandle()); + node.getHandle().functionHandle()); return new PhysicalOperation(operatorFactory, makeLayout(node)); } @@ -1677,8 +1677,8 @@ public PhysicalOperation visitTableFunctionProcessor(TableFunctionProcessorNode context.getNextOperatorId(), node.getId(), processorProvider, - node.getHandle().getCatalogHandle(), - node.getHandle().getFunctionHandle(), + node.getHandle().catalogHandle(), + node.getHandle().functionHandle(), properChannelsCount, toIntExact(passThroughSourcesCount), requiredChannels, diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index 63f7e264c55d..be1aa13f4d76 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -1037,8 +1037,8 @@ public Optional> applyTopN(Session session, T public Optional> applyTableFunction(Session session, TableFunctionHandle handle) { Span span = startSpan("applyTableFunction") - .setAttribute(TrinoAttributes.CATALOG, handle.getCatalogHandle().getCatalogName().toString()) - .setAttribute(TrinoAttributes.HANDLE, handle.getFunctionHandle().toString()); + .setAttribute(TrinoAttributes.CATALOG, handle.catalogHandle().getCatalogName().toString()) + .setAttribute(TrinoAttributes.HANDLE, handle.functionHandle().toString()); try (var ignored = scopedSpan(span)) { return delegate.applyTableFunction(session, handle); } diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/TestJsonTable.java b/core/trino-main/src/test/java/io/trino/sql/planner/TestJsonTable.java index 1891083d218d..30828cf0d7bc 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/TestJsonTable.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/TestJsonTable.java @@ -551,7 +551,7 @@ private void assertJsonTablePlan(@Language("SQL") String sql, JsonTablePlanNode getPlanTester().inTransaction(transactionSession -> { Plan queryPlan = getPlanTester().createPlan(transactionSession, sql, ImmutableList.of(), CREATED, WarningCollector.NOOP, createPlanOptimizersStatsCollector()); TableFunctionNode tableFunctionNode = (TableFunctionNode) getOnlyElement(PlanNodeSearcher.searchFrom(queryPlan.getRoot()).where(TableFunctionNode.class::isInstance).findAll()); - JsonTablePlanNode actualPlan = ((JsonTable.JsonTableFunctionHandle) tableFunctionNode.getHandle().getFunctionHandle()).processingPlan(); + JsonTablePlanNode actualPlan = ((JsonTable.JsonTableFunctionHandle) tableFunctionNode.getHandle().functionHandle()).processingPlan(); assertThat(actualPlan) .usingComparator(planComparator()) .isEqualTo(expectedPlan); From 2dfdd0d627976e038137121d97d18160b5e18d22 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:14:45 +0200 Subject: [PATCH 15/21] Convert TableFunctionMetadata to record --- .../trino/metadata/TableFunctionMetadata.java | 21 ++++--------------- .../trino/sql/analyzer/StatementAnalyzer.java | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableFunctionMetadata.java b/core/trino-main/src/main/java/io/trino/metadata/TableFunctionMetadata.java index dfef7d239fd1..e5031d20f463 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableFunctionMetadata.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableFunctionMetadata.java @@ -18,24 +18,11 @@ import static java.util.Objects.requireNonNull; -public class TableFunctionMetadata +public record TableFunctionMetadata(CatalogHandle catalogHandle, ConnectorTableFunction function) { - private final CatalogHandle catalogHandle; - private final ConnectorTableFunction function; - - public TableFunctionMetadata(CatalogHandle catalogHandle, ConnectorTableFunction function) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.function = requireNonNull(function, "function is null"); - } - - public CatalogHandle getCatalogHandle() - { - return catalogHandle; - } - - public ConnectorTableFunction getFunction() + public TableFunctionMetadata { - return function; + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(function, "function is null"); } } diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index f72a216a8b8c..9b029092684b 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -1665,8 +1665,8 @@ protected Scope visitTableFunctionInvocation(TableFunctionInvocation node, Optio TableFunctionMetadata tableFunctionMetadata = resolveTableFunction(node) .orElseThrow(() -> semanticException(FUNCTION_NOT_FOUND, node, "Table function '%s' not registered", node.getName())); - ConnectorTableFunction function = tableFunctionMetadata.getFunction(); - CatalogHandle catalogHandle = tableFunctionMetadata.getCatalogHandle(); + ConnectorTableFunction function = tableFunctionMetadata.function(); + CatalogHandle catalogHandle = tableFunctionMetadata.catalogHandle(); Node errorLocation = node; if (!node.getArguments().isEmpty()) { From 0880073aa8235718bfc4a5d371a65765ad460e66 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:15:26 +0200 Subject: [PATCH 16/21] Convert TableHandle to record --- .../io/trino/execution/AddColumnTask.java | 2 +- .../io/trino/execution/RenameTableTask.java | 2 +- .../io/trino/execution/SqlQueryExecution.java | 2 +- ...NoMemoryAwarePartitionMemoryEstimator.java | 4 +- .../io/trino/metadata/MetadataManager.java | 246 +++++++++--------- .../java/io/trino/metadata/TableHandle.java | 61 +---- .../java/io/trino/split/PageSinkManager.java | 4 +- .../io/trino/split/PageSourceManager.java | 6 +- .../java/io/trino/split/SplitManager.java | 8 +- .../trino/sql/analyzer/StatementAnalyzer.java | 12 +- .../io/trino/sql/planner/InputExtractor.java | 2 +- .../io/trino/sql/planner/LogicalPlanner.java | 2 +- .../planner/optimizations/AddExchanges.java | 2 +- .../sql/planner/plan/TableWriterNode.java | 6 +- .../planprinter/CounterBasedAnonymizer.java | 4 +- .../planner/planprinter/IoPlanPrinter.java | 2 +- .../trino/sql/rewrite/ShowQueriesRewrite.java | 4 +- .../io/trino/tracing/TracingMetadata.java | 12 +- .../execution/BaseDataDefinitionTaskTest.java | 2 +- .../io/trino/execution/TaskTestUtils.java | 2 +- .../io/trino/sql/analyzer/TestAnalyzer.java | 4 +- .../TestEffectivePredicateExtractor.java | 2 +- .../ConnectorAwareTableScanMatcher.java | 2 +- ...estDetermineTableScanNodePartitioning.java | 2 +- .../rule/TestPushDownDereferencesRules.java | 2 +- .../iterative/rule/test/PlanBuilder.java | 2 +- ...DeltaLakeNodeLocalDynamicSplitPruning.java | 2 +- .../TestDeltaLakeProjectionPushdownPlans.java | 4 +- .../plugin/hive/BaseHiveConnectorTest.java | 2 +- .../TestNodeLocalDynamicSplitPruning.java | 2 +- ...stHiveProjectionPushdownIntoTableScan.java | 4 +- .../iceberg/BaseIcebergConnectorTest.java | 2 +- ...stIcebergNodeLocalDynamicSplitPruning.java | 2 +- .../TestIcebergProjectionPushdownPlans.java | 4 +- ...TestConnectorPushdownRulesWithIceberg.java | 2 +- .../TestMongoProjectionPushdownPlans.java | 4 +- .../testing/AbstractTestQueryFramework.java | 2 +- .../trino/execution/TestTableRedirection.java | 6 +- 38 files changed, 192 insertions(+), 243 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/execution/AddColumnTask.java b/core/trino-main/src/main/java/io/trino/execution/AddColumnTask.java index 70a7725d892b..bff5e1e38c9b 100644 --- a/core/trino-main/src/main/java/io/trino/execution/AddColumnTask.java +++ b/core/trino-main/src/main/java/io/trino/execution/AddColumnTask.java @@ -96,7 +96,7 @@ public ListenableFuture execute( return immediateVoidFuture(); } TableHandle tableHandle = redirectionAwareTableHandle.tableHandle().get(); - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); QualifiedObjectName qualifiedTableName = redirectionAwareTableHandle.redirectedTableName().orElse(originalTableName); diff --git a/core/trino-main/src/main/java/io/trino/execution/RenameTableTask.java b/core/trino-main/src/main/java/io/trino/execution/RenameTableTask.java index 4e917aed3064..84a57f316fb8 100644 --- a/core/trino-main/src/main/java/io/trino/execution/RenameTableTask.java +++ b/core/trino-main/src/main/java/io/trino/execution/RenameTableTask.java @@ -107,7 +107,7 @@ public ListenableFuture execute( if (metadata.getTableHandle(session, target).isPresent()) { throw semanticException(TABLE_ALREADY_EXISTS, statement, "Target table '%s' already exists", target); } - if (!tableHandle.getCatalogHandle().getCatalogName().toString().equals(target.catalogName())) { + if (!tableHandle.catalogHandle().getCatalogName().toString().equals(target.catalogName())) { throw semanticException(NOT_SUPPORTED, statement, "Table rename across catalogs is not supported"); } accessControl.checkCanRenameTable(session.toSecurityContext(), source, target); diff --git a/core/trino-main/src/main/java/io/trino/execution/SqlQueryExecution.java b/core/trino-main/src/main/java/io/trino/execution/SqlQueryExecution.java index 492b90c13259..b25f8520f216 100644 --- a/core/trino-main/src/main/java/io/trino/execution/SqlQueryExecution.java +++ b/core/trino-main/src/main/java/io/trino/execution/SqlQueryExecution.java @@ -742,7 +742,7 @@ private boolean shouldWaitForMinWorkers(Statement statement) // Allow set session statements and queries on internal system connectors to run without waiting Collection tables = analysis.getTables(); return !tables.stream() - .map(TableHandle::getCatalogHandle) + .map(TableHandle::catalogHandle) .allMatch(catalogName -> catalogName.getType().isInternal()); } return true; diff --git a/core/trino-main/src/main/java/io/trino/execution/scheduler/faulttolerant/NoMemoryAwarePartitionMemoryEstimator.java b/core/trino-main/src/main/java/io/trino/execution/scheduler/faulttolerant/NoMemoryAwarePartitionMemoryEstimator.java index 429893b02acd..3931d8d671a4 100644 --- a/core/trino-main/src/main/java/io/trino/execution/scheduler/faulttolerant/NoMemoryAwarePartitionMemoryEstimator.java +++ b/core/trino-main/src/main/java/io/trino/execution/scheduler/faulttolerant/NoMemoryAwarePartitionMemoryEstimator.java @@ -94,8 +94,8 @@ private boolean isNoMemoryFragment(PlanFragment fragment, Function getTableHandleForExecute(Session session, Ta requireNonNull(procedure, "procedure is null"); requireNonNull(executeProperties, "executeProperties is null"); - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); Optional executeHandle = metadata.getTableHandleForExecute( session.toConnectorSession(catalogHandle), - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), procedure, executeProperties, getRetryPolicy(session).getRetryMode()); return executeHandle.map(handle -> new TableExecuteHandle( catalogHandle, - tableHandle.getTransaction(), + tableHandle.transaction(), handle)); } @@ -335,7 +335,7 @@ public BeginTableExecuteResult beginTableExecut CatalogHandle catalogHandle = tableExecuteHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - BeginTableExecuteResult connectorBeginResult = metadata.beginTableExecute(session.toConnectorSession(), tableExecuteHandle.connectorHandle(), sourceHandle.getConnectorHandle()); + BeginTableExecuteResult connectorBeginResult = metadata.beginTableExecute(session.toConnectorSession(), tableExecuteHandle.connectorHandle(), sourceHandle.connectorHandle()); return new BeginTableExecuteResult<>( tableExecuteHandle.withConnectorHandle(connectorBeginResult.getTableExecuteHandle()), @@ -380,12 +380,12 @@ public Optional getSystemTable(Session session, QualifiedObjectName @Override public TableProperties getTableProperties(Session session, TableHandle handle) { - CatalogHandle catalogHandle = handle.getCatalogHandle(); + CatalogHandle catalogHandle = handle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return new TableProperties(catalogHandle, handle.getTransaction(), metadata.getTableProperties(connectorSession, handle.getConnectorHandle())); + return new TableProperties(catalogHandle, handle.transaction(), metadata.getTableProperties(connectorSession, handle.connectorHandle())); } @Override @@ -393,14 +393,14 @@ public TableHandle makeCompatiblePartitioning(Session session, TableHandle table { checkArgument(partitioningHandle.getCatalogHandle().isPresent(), "Expect partitioning handle from connector, got system partitioning handle"); CatalogHandle catalogHandle = partitioningHandle.getCatalogHandle().get(); - checkArgument(catalogHandle.equals(tableHandle.getCatalogHandle()), "ConnectorId of tableHandle and partitioningHandle does not match"); + checkArgument(catalogHandle.equals(tableHandle.catalogHandle()), "ConnectorId of tableHandle and partitioningHandle does not match"); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(catalogHandle); ConnectorTableHandle newTableHandle = metadata.makeCompatiblePartitioning( session.toConnectorSession(catalogHandle), - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), partitioningHandle.getConnectorHandle()); return new TableHandle(catalogHandle, newTableHandle, transaction); } @@ -426,19 +426,19 @@ public Optional getCommonPartitioning(Session session, Parti @Override public Optional getInfo(Session session, TableHandle handle) { - CatalogHandle catalogHandle = handle.getCatalogHandle(); + CatalogHandle catalogHandle = handle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - return metadata.getInfo(handle.getConnectorHandle()); + return metadata.getInfo(handle.connectorHandle()); } @Override public CatalogSchemaTableName getTableName(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); - SchemaTableName tableName = metadata.getTableName(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + SchemaTableName tableName = metadata.getTableName(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); return new CatalogSchemaTableName(catalogMetadata.getCatalogName().toString(), tableName); } @@ -446,10 +446,10 @@ public CatalogSchemaTableName getTableName(Session session, TableHandle tableHan @Override public TableSchema getTableSchema(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); - ConnectorTableSchema tableSchema = metadata.getTableSchema(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + ConnectorTableSchema tableSchema = metadata.getTableSchema(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); return new TableSchema(catalogMetadata.getCatalogName(), tableSchema); } @@ -457,10 +457,10 @@ public TableSchema getTableSchema(Session session, TableHandle tableHandle) @Override public TableMetadata getTableMetadata(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); - ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); return new TableMetadata(catalogMetadata.getCatalogName(), tableMetadata); } @@ -468,9 +468,9 @@ public TableMetadata getTableMetadata(Session session, TableHandle tableHandle) @Override public TableStatistics getTableStatistics(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - TableStatistics tableStatistics = metadata.getTableStatistics(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + TableStatistics tableStatistics = metadata.getTableStatistics(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); verifyNotNull(tableStatistics, "%s returned null tableStatistics for %s", metadata, tableHandle); return tableStatistics; } @@ -478,9 +478,9 @@ public TableStatistics getTableStatistics(Session session, TableHandle tableHand @Override public Map getColumnHandles(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - Map handles = metadata.getColumnHandles(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + Map handles = metadata.getColumnHandles(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); ImmutableMap.Builder map = ImmutableMap.builder(); for (Entry mapEntry : handles.entrySet()) { @@ -495,9 +495,9 @@ public ColumnMetadata getColumnMetadata(Session session, TableHandle tableHandle requireNonNull(tableHandle, "tableHandle is null"); requireNonNull(columnHandle, "columnHandle is null"); - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - return metadata.getColumnMetadata(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), columnHandle); + return metadata.getColumnMetadata(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), columnHandle); } @Override @@ -828,11 +828,11 @@ public void renameTable(Session session, TableHandle tableHandle, CatalogSchemaT String catalogName = newTableName.catalogName(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogName); CatalogHandle catalogHandle = catalogMetadata.getCatalogHandle(); - if (!tableHandle.getCatalogHandle().equals(catalogHandle)) { + if (!tableHandle.catalogHandle().equals(catalogHandle)) { throw new TrinoException(SYNTAX_ERROR, "Cannot rename tables across catalogs"); } ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - metadata.renameTable(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), newTableName.asSchemaTableName()); + metadata.renameTable(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), newTableName.asSchemaTableName()); if (catalogMetadata.getSecurityManagement() != CONNECTOR) { systemSecurityMetadata.tableRenamed(session, sourceTableName, newTableName.asCatalogSchemaTableName()); } @@ -841,17 +841,17 @@ public void renameTable(Session session, TableHandle tableHandle, CatalogSchemaT @Override public void setTableProperties(Session session, TableHandle tableHandle, Map> properties) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.setTableProperties(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), properties); + metadata.setTableProperties(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), properties); } @Override public void setTableComment(Session session, TableHandle tableHandle, Optional comment) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.setTableComment(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), comment); + metadata.setTableComment(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), comment); } @Override @@ -875,18 +875,18 @@ public void setViewColumnComment(Session session, QualifiedObjectName viewName, @Override public void setColumnComment(Session session, TableHandle tableHandle, ColumnHandle column, Optional comment) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.setColumnComment(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column, comment); + metadata.setColumnComment(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column, comment); } @Override public void renameColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnHandle source, String target) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle.getCatalogName().toString()); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.renameColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), source, target.toLowerCase(ENGLISH)); + metadata.renameColumn(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), source, target.toLowerCase(ENGLISH)); if (catalogMetadata.getSecurityManagement() == SYSTEM) { ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, source); systemSecurityMetadata.columnRenamed(session, table, columnMetadata.getName(), target); @@ -896,18 +896,18 @@ public void renameColumn(Session session, TableHandle tableHandle, CatalogSchema @Override public void renameField(Session session, TableHandle tableHandle, List fieldPath, String target) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.renameField(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), fieldPath, target.toLowerCase(ENGLISH)); + metadata.renameField(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), fieldPath, target.toLowerCase(ENGLISH)); } @Override public void addColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnMetadata column) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle.getCatalogName().toString()); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.addColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column); + metadata.addColumn(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column); if (catalogMetadata.getSecurityManagement() == SYSTEM) { systemSecurityMetadata.columnCreated(session, table, column.getName()); } @@ -916,18 +916,18 @@ public void addColumn(Session session, TableHandle tableHandle, CatalogSchemaTab @Override public void addField(Session session, TableHandle tableHandle, List parentPath, String fieldName, Type type, boolean ignoreExisting) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.addField(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), parentPath, fieldName, type, ignoreExisting); + metadata.addField(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), parentPath, fieldName, type, ignoreExisting); } @Override public void dropColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnHandle column) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle.getCatalogName().toString()); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.dropColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column); + metadata.dropColumn(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column); if (catalogMetadata.getSecurityManagement() == SYSTEM) { ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, column); systemSecurityMetadata.columnDropped(session, table, columnMetadata.getName()); @@ -937,19 +937,19 @@ public void dropColumn(Session session, TableHandle tableHandle, CatalogSchemaTa @Override public void dropField(Session session, TableHandle tableHandle, ColumnHandle column, List fieldPath) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.dropField(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column, fieldPath); + metadata.dropField(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column, fieldPath); } @Override public void setColumnType(Session session, TableHandle tableHandle, ColumnHandle column, Type type) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle.getCatalogName().toString()); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, column); - metadata.setColumnType(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column, type); + metadata.setColumnType(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column, type); if (catalogMetadata.getSecurityManagement() == SYSTEM) { systemSecurityMetadata.columnTypeChanged( session, @@ -963,20 +963,20 @@ public void setColumnType(Session session, TableHandle tableHandle, ColumnHandle @Override public void setFieldType(Session session, TableHandle tableHandle, List fieldPath, Type type) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.setFieldType(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), fieldPath, type); + metadata.setFieldType(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), fieldPath, type); } @Override public void dropNotNullConstraint(Session session, TableHandle tableHandle, ColumnHandle column) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, column); - metadata.dropNotNullConstraint(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column); + metadata.dropNotNullConstraint(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), column); if (catalogMetadata.getSecurityManagement() == SYSTEM) { systemSecurityMetadata.columnNotNullConstraintDropped( session, @@ -1001,10 +1001,10 @@ public void setTableAuthorization(Session session, CatalogSchemaTableName table, @Override public void dropTable(Session session, TableHandle tableHandle, CatalogSchemaTableName tableName) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - metadata.dropTable(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + metadata.dropTable(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); if (catalogMetadata.getSecurityManagement() != CONNECTOR) { systemSecurityMetadata.tableDropped(session, tableName); } @@ -1013,19 +1013,19 @@ public void dropTable(Session session, TableHandle tableHandle, CatalogSchemaTab @Override public void truncateTable(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - metadata.truncateTable(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + metadata.truncateTable(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); } @Override public Optional getInsertLayout(Session session, TableHandle table) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - return metadata.getInsertLayout(session.toConnectorSession(catalogHandle), table.getConnectorHandle()) + return metadata.getInsertLayout(session.toConnectorSession(catalogHandle), table.connectorHandle()) .map(layout -> new TableLayout(catalogHandle, catalogMetadata.getTransactionHandleFor(catalogHandle), layout)); } @@ -1040,23 +1040,23 @@ public TableStatisticsMetadata getStatisticsCollectionMetadataForWrite(Session s @Override public AnalyzeMetadata getStatisticsCollectionMetadata(Session session, TableHandle tableHandle, Map analyzeProperties) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); - ConnectorAnalyzeMetadata analyze = metadata.getStatisticsCollectionMetadata(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), analyzeProperties); - return new AnalyzeMetadata(analyze.getStatisticsMetadata(), new TableHandle(catalogHandle, analyze.getTableHandle(), tableHandle.getTransaction())); + ConnectorAnalyzeMetadata analyze = metadata.getStatisticsCollectionMetadata(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), analyzeProperties); + return new AnalyzeMetadata(analyze.getStatisticsMetadata(), new TableHandle(catalogHandle, analyze.getTableHandle(), tableHandle.transaction())); } @Override public AnalyzeTableHandle beginStatisticsCollection(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalogHandle); - ConnectorTableHandle connectorTableHandle = metadata.beginStatisticsCollection(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + ConnectorTableHandle connectorTableHandle = metadata.beginStatisticsCollection(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); return new AnalyzeTableHandle(catalogHandle, transactionHandle, connectorTableHandle); } @@ -1141,18 +1141,18 @@ public Optional finishCreateTable(Session session, Outp @Override public InsertTableHandle beginInsert(Session session, TableHandle tableHandle, List columns) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalogHandle); - ConnectorInsertTableHandle handle = metadata.beginInsert(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), columns, getRetryPolicy(session).getRetryMode()); - return new InsertTableHandle(tableHandle.getCatalogHandle(), transactionHandle, handle); + ConnectorInsertTableHandle handle = metadata.beginInsert(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), columns, getRetryPolicy(session).getRetryMode()); + return new InsertTableHandle(tableHandle.catalogHandle(), transactionHandle, handle); } @Override public boolean supportsMissingColumnsOnInsert(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); return catalogMetadata.getMetadata(session).supportsMissingColumnsOnInsert(); } @@ -1163,8 +1163,8 @@ public Optional finishInsert(Session session, InsertTab CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); List sourceConnectorHandles = sourceTableHandles.stream() - .filter(handle -> handle.getCatalogHandle().equals(catalogHandle)) - .map(TableHandle::getConnectorHandle) + .filter(handle -> handle.catalogHandle().equals(catalogHandle)) + .map(TableHandle::connectorHandle) .collect(toImmutableList()); return metadata.finishInsert(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), sourceConnectorHandles, fragments, computedStatistics); } @@ -1195,19 +1195,19 @@ private static ListenableFuture asVoid(ListenableFuture future) @Override public InsertTableHandle beginRefreshMaterializedView(Session session, TableHandle tableHandle, List sourceTableHandles) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalogHandle); List sourceConnectorHandles = sourceTableHandles.stream() - .map(TableHandle::getConnectorHandle) + .map(TableHandle::connectorHandle) .collect(Collectors.toList()); - sourceConnectorHandles.add(tableHandle.getConnectorHandle()); + sourceConnectorHandles.add(tableHandle.connectorHandle()); - ConnectorInsertTableHandle handle = metadata.beginRefreshMaterializedView(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), sourceConnectorHandles, getRetryPolicy(session).getRetryMode()); + ConnectorInsertTableHandle handle = metadata.beginRefreshMaterializedView(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), sourceConnectorHandles, getRetryPolicy(session).getRetryMode()); - return new InsertTableHandle(tableHandle.getCatalogHandle(), transactionHandle, handle); + return new InsertTableHandle(tableHandle.catalogHandle(), transactionHandle, handle); } @Override @@ -1224,11 +1224,11 @@ public Optional finishRefreshMaterializedView( ConnectorMetadata metadata = getMetadata(session, catalogHandle); List sourceConnectorHandles = sourceTableHandles.stream() - .map(TableHandle::getConnectorHandle) + .map(TableHandle::connectorHandle) .collect(toImmutableList()); return metadata.finishRefreshMaterializedView( session.toConnectorSession(catalogHandle), - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), insertHandle.connectorHandle(), fragments, computedStatistics, @@ -1239,86 +1239,86 @@ public Optional finishRefreshMaterializedView( @Override public ColumnHandle getMergeRowIdColumnHandle(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - return metadata.getMergeRowIdColumnHandle(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + return metadata.getMergeRowIdColumnHandle(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); } @Override public Optional getUpdateLayout(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadata(session); ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalogHandle); - return metadata.getUpdateLayout(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()) + return metadata.getUpdateLayout(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()) .map(partitioning -> new PartitioningHandle(Optional.of(catalogHandle), Optional.of(transactionHandle), partitioning)); } @Override public Optional applyUpdate(Session session, TableHandle table, Map assignments) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyUpdate(connectorSession, table.getConnectorHandle(), assignments) - .map(newHandle -> new TableHandle(catalogHandle, newHandle, table.getTransaction())); + return metadata.applyUpdate(connectorSession, table.connectorHandle(), assignments) + .map(newHandle -> new TableHandle(catalogHandle, newHandle, table.transaction())); } @Override public OptionalLong executeUpdate(Session session, TableHandle table) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.executeUpdate(connectorSession, table.getConnectorHandle()); + return metadata.executeUpdate(connectorSession, table.connectorHandle()); } @Override public Optional applyDelete(Session session, TableHandle table) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyDelete(connectorSession, table.getConnectorHandle()) - .map(newHandle -> new TableHandle(catalogHandle, newHandle, table.getTransaction())); + return metadata.applyDelete(connectorSession, table.connectorHandle()) + .map(newHandle -> new TableHandle(catalogHandle, newHandle, table.transaction())); } @Override public OptionalLong executeDelete(Session session, TableHandle table) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.executeDelete(connectorSession, table.getConnectorHandle()); + return metadata.executeDelete(connectorSession, table.connectorHandle()); } @Override public RowChangeParadigm getRowChangeParadigm(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - return metadata.getRowChangeParadigm(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle()); + return metadata.getRowChangeParadigm(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle()); } @Override public MergeHandle beginMerge(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle); - ConnectorMergeTableHandle newHandle = metadata.beginMerge(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), getRetryPolicy(session).getRetryMode()); + ConnectorMergeTableHandle newHandle = metadata.beginMerge(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), getRetryPolicy(session).getRetryMode()); return new MergeHandle(tableHandle.withConnectorHandle(newHandle.getTableHandle()), newHandle); } @Override public void finishMerge(Session session, MergeHandle mergeHandle, Collection fragments, Collection computedStatistics) { - CatalogHandle catalogHandle = mergeHandle.tableHandle().getCatalogHandle(); + CatalogHandle catalogHandle = mergeHandle.tableHandle().catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); metadata.finishMerge(session.toConnectorSession(catalogHandle), mergeHandle.connectorMergeHandle(), fragments, computedStatistics); } @@ -1835,11 +1835,11 @@ private static boolean isExternalInformationSchema(CatalogHandle catalogHandle, @Override public Optional applyTableScanRedirect(Session session, TableHandle tableHandle) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyTableScanRedirect(connectorSession, tableHandle.getConnectorHandle()); + return metadata.applyTableScanRedirect(connectorSession, tableHandle.connectorHandle()); } private QualifiedObjectName getRedirectedTableName(Session session, QualifiedObjectName originalTableName) @@ -1919,25 +1919,25 @@ public RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session sessio @Override public Optional resolveIndex(Session session, TableHandle tableHandle, Set indexableColumns, Set outputColumns, TupleDomain tupleDomain) { - CatalogHandle catalogHandle = tableHandle.getCatalogHandle(); + CatalogHandle catalogHandle = tableHandle.catalogHandle(); CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogHandle); ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle); ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - Optional resolvedIndex = metadata.resolveIndex(connectorSession, tableHandle.getConnectorHandle(), indexableColumns, outputColumns, tupleDomain); - return resolvedIndex.map(resolved -> new ResolvedIndex(tableHandle.getCatalogHandle(), transaction, resolved)); + Optional resolvedIndex = metadata.resolveIndex(connectorSession, tableHandle.connectorHandle(), indexableColumns, outputColumns, tupleDomain); + return resolvedIndex.map(resolved -> new ResolvedIndex(tableHandle.catalogHandle(), transaction, resolved)); } @Override public Optional> applyLimit(Session session, TableHandle table, long limit) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyLimit(connectorSession, table.getConnectorHandle(), limit) + return metadata.applyLimit(connectorSession, table.connectorHandle(), limit) .map(result -> new LimitApplicationResult<>( - new TableHandle(catalogHandle, result.getHandle(), table.getTransaction()), + new TableHandle(catalogHandle, result.getHandle(), table.transaction()), result.isLimitGuaranteed(), result.isPrecalculateStatistics())); } @@ -1945,15 +1945,15 @@ public Optional> applyLimit(Session session, @Override public Optional> applySample(Session session, TableHandle table, SampleType sampleType, double sampleRatio) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applySample(connectorSession, table.getConnectorHandle(), sampleType, sampleRatio) + return metadata.applySample(connectorSession, table.connectorHandle(), sampleType, sampleRatio) .map(result -> new SampleApplicationResult<>(new TableHandle( catalogHandle, result.getHandle(), - table.getTransaction()), + table.transaction()), result.isPrecalculateStatistics())); } @@ -1968,16 +1968,16 @@ public Optional> applyAggregation( // Global aggregation is represented by [[]] checkArgument(!groupingSets.isEmpty(), "No grouping sets provided"); - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyAggregation(connectorSession, table.getConnectorHandle(), aggregations, assignments, groupingSets) + return metadata.applyAggregation(connectorSession, table.connectorHandle(), aggregations, assignments, groupingSets) .map(result -> { verifyProjection(table, result.getProjections(), result.getAssignments(), aggregations.size()); return new AggregationApplicationResult<>( - new TableHandle(catalogHandle, result.getHandle(), table.getTransaction()), + new TableHandle(catalogHandle, result.getHandle(), table.transaction()), result.getProjections(), result.getAssignments(), result.getGroupingColumnMapping(), @@ -1996,13 +1996,13 @@ public Optional> applyJoin( Map rightAssignments, JoinStatistics statistics) { - if (!right.getCatalogHandle().equals(left.getCatalogHandle())) { + if (!right.catalogHandle().equals(left.catalogHandle())) { // Exact comparison is fine as catalog name here is passed from CatalogMetadata and is normalized to lowercase return Optional.empty(); } - CatalogHandle catalogHandle = left.getCatalogHandle(); + CatalogHandle catalogHandle = left.catalogHandle(); - ConnectorTransactionHandle transaction = left.getTransaction(); + ConnectorTransactionHandle transaction = left.transaction(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); @@ -2010,8 +2010,8 @@ public Optional> applyJoin( metadata.applyJoin( connectorSession, joinType, - left.getConnectorHandle(), - right.getConnectorHandle(), + left.connectorHandle(), + right.connectorHandle(), joinCondition, leftAssignments, rightAssignments, @@ -2054,13 +2054,13 @@ public Optional> applyTopN( List sortItems, Map assignments) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyTopN(connectorSession, table.getConnectorHandle(), topNCount, sortItems, assignments) + return metadata.applyTopN(connectorSession, table.connectorHandle(), topNCount, sortItems, assignments) .map(result -> new TopNApplicationResult<>( - new TableHandle(catalogHandle, result.getHandle(), table.getTransaction()), + new TableHandle(catalogHandle, result.getHandle(), table.transaction()), result.isTopNGuaranteed(), result.isPrecalculateStatistics())); } @@ -2103,35 +2103,35 @@ private void verifyProjection(TableHandle table, List proje @Override public void validateScan(Session session, TableHandle table) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); - metadata.validateScan(session.toConnectorSession(catalogHandle), table.getConnectorHandle()); + metadata.validateScan(session.toConnectorSession(catalogHandle), table.connectorHandle()); } @Override public Optional> applyFilter(Session session, TableHandle table, Constraint constraint) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyFilter(connectorSession, table.getConnectorHandle(), constraint) - .map(result -> result.transform(handle -> new TableHandle(catalogHandle, handle, table.getTransaction()))); + return metadata.applyFilter(connectorSession, table.connectorHandle(), constraint) + .map(result -> result.transform(handle -> new TableHandle(catalogHandle, handle, table.transaction()))); } @Override public Optional> applyProjection(Session session, TableHandle table, List projections, Map assignments) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorMetadata metadata = getMetadata(session, catalogHandle); ConnectorSession connectorSession = session.toConnectorSession(catalogHandle); - return metadata.applyProjection(connectorSession, table.getConnectorHandle(), projections, assignments) + return metadata.applyProjection(connectorSession, table.connectorHandle(), projections, assignments) .map(result -> { verifyProjection(table, result.getProjections(), result.getAssignments(), projections.size()); return new ProjectionApplicationResult<>( - new TableHandle(catalogHandle, result.getHandle(), table.getTransaction()), + new TableHandle(catalogHandle, result.getHandle(), table.transaction()), result.getProjections(), result.getAssignments(), result.isPrecalculateStatistics()); @@ -2755,8 +2755,8 @@ public WriterScalingOptions getNewTableWriterScalingOptions(Session session, Qua @Override public WriterScalingOptions getInsertWriterScalingOptions(Session session, TableHandle tableHandle) { - ConnectorMetadata metadata = getMetadataForWrite(session, tableHandle.getCatalogHandle()); - return metadata.getInsertWriterScalingOptions(session.toConnectorSession(tableHandle.getCatalogHandle()), tableHandle.getConnectorHandle()); + ConnectorMetadata metadata = getMetadataForWrite(session, tableHandle.catalogHandle()); + return metadata.getInsertWriterScalingOptions(session.toConnectorSession(tableHandle.catalogHandle()), tableHandle.connectorHandle()); } private Optional toConnectorVersion(Optional version) diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableHandle.java b/core/trino-main/src/main/java/io/trino/metadata/TableHandle.java index b352196524d7..c4d96e2e350a 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableHandle.java @@ -13,49 +13,19 @@ */ package io.trino.metadata; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import io.trino.spi.connector.CatalogHandle; import io.trino.spi.connector.ConnectorTableHandle; import io.trino.spi.connector.ConnectorTransactionHandle; -import java.util.Objects; - import static java.util.Objects.requireNonNull; -public final class TableHandle +public record TableHandle(CatalogHandle catalogHandle, ConnectorTableHandle connectorHandle, ConnectorTransactionHandle transaction) { - private final CatalogHandle catalogHandle; - private final ConnectorTableHandle connectorHandle; - private final ConnectorTransactionHandle transaction; - - @JsonCreator - public TableHandle( - @JsonProperty("catalogHandle") CatalogHandle catalogHandle, - @JsonProperty("connectorHandle") ConnectorTableHandle connectorHandle, - @JsonProperty("transaction") ConnectorTransactionHandle transaction) - { - this.catalogHandle = requireNonNull(catalogHandle, "catalogHandle is null"); - this.connectorHandle = requireNonNull(connectorHandle, "connectorHandle is null"); - this.transaction = requireNonNull(transaction, "transaction is null"); - } - - @JsonProperty - public CatalogHandle getCatalogHandle() + public TableHandle { - return catalogHandle; - } - - @JsonProperty - public ConnectorTableHandle getConnectorHandle() - { - return connectorHandle; - } - - @JsonProperty - public ConnectorTransactionHandle getTransaction() - { - return transaction; + requireNonNull(catalogHandle, "catalogHandle is null"); + requireNonNull(connectorHandle, "connectorHandle is null"); + requireNonNull(transaction, "transaction is null"); } public TableHandle withConnectorHandle(ConnectorTableHandle connectorHandle) @@ -71,25 +41,4 @@ public String toString() { return catalogHandle + ":" + connectorHandle; } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TableHandle other = (TableHandle) o; - return Objects.equals(catalogHandle, other.catalogHandle) && - Objects.equals(connectorHandle, other.connectorHandle) && - Objects.equals(transaction, other.transaction); - } - - @Override - public int hashCode() - { - return Objects.hash(catalogHandle, connectorHandle, transaction); - } } diff --git a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java index 5757c7679d65..5c082eddd31e 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSinkManager.java @@ -69,8 +69,8 @@ public ConnectorMergeSink createMergeSink(Session session, MergeHandle mergeHand { // assumes connectorId and catalog are the same TableHandle tableHandle = mergeHandle.tableHandle(); - ConnectorSession connectorSession = session.toConnectorSession(tableHandle.getCatalogHandle()); - return providerFor(tableHandle.getCatalogHandle()).createMergeSink(tableHandle.getTransaction(), connectorSession, mergeHandle.connectorMergeHandle(), pageSinkId); + ConnectorSession connectorSession = session.toConnectorSession(tableHandle.catalogHandle()); + return providerFor(tableHandle.catalogHandle()).createMergeSink(tableHandle.transaction(), connectorSession, mergeHandle.connectorMergeHandle(), pageSinkId); } private ConnectorPageSinkProvider providerFor(CatalogHandle catalogHandle) diff --git a/core/trino-main/src/main/java/io/trino/split/PageSourceManager.java b/core/trino-main/src/main/java/io/trino/split/PageSourceManager.java index b985551cfee5..b2b0572bf6c5 100644 --- a/core/trino-main/src/main/java/io/trino/split/PageSourceManager.java +++ b/core/trino-main/src/main/java/io/trino/split/PageSourceManager.java @@ -47,7 +47,7 @@ public PageSourceManager(CatalogServiceProvider pag public ConnectorPageSource createPageSource(Session session, Split split, TableHandle table, List columns, DynamicFilter dynamicFilter) { requireNonNull(columns, "columns is null"); - checkArgument(split.getCatalogHandle().equals(table.getCatalogHandle()), "mismatched split and table"); + checkArgument(split.getCatalogHandle().equals(table.catalogHandle()), "mismatched split and table"); CatalogHandle catalogHandle = split.getCatalogHandle(); ConnectorPageSourceProvider provider = pageSourceProvider.getService(catalogHandle); @@ -59,10 +59,10 @@ public ConnectorPageSource createPageSource(Session session, Split split, TableH dynamicFilter = DynamicFilter.EMPTY; } return provider.createPageSource( - table.getTransaction(), + table.transaction(), session.toConnectorSession(catalogHandle), split.getConnectorSplit(), - table.getConnectorHandle(), + table.connectorHandle(), columns, dynamicFilter); } diff --git a/core/trino-main/src/main/java/io/trino/split/SplitManager.java b/core/trino-main/src/main/java/io/trino/split/SplitManager.java index a34e114b719c..12d9e1491d4c 100644 --- a/core/trino-main/src/main/java/io/trino/split/SplitManager.java +++ b/core/trino-main/src/main/java/io/trino/split/SplitManager.java @@ -73,7 +73,7 @@ public SplitSource getSplits( DynamicFilter dynamicFilter, Constraint constraint) { - CatalogHandle catalogHandle = table.getCatalogHandle(); + CatalogHandle catalogHandle = table.catalogHandle(); ConnectorSplitManager splitManager = splitManagerProvider.getService(catalogHandle); if (!isAllowPushdownIntoConnectors(session)) { dynamicFilter = DynamicFilter.EMPTY; @@ -84,12 +84,12 @@ public SplitSource getSplits( ConnectorSplitSource source; try (var ignore = scopedSpan(tracer.spanBuilder("SplitManager.getSplits") .setParent(Context.current().with(parentSpan)) - .setAttribute(TrinoAttributes.TABLE, table.getConnectorHandle().toString()) + .setAttribute(TrinoAttributes.TABLE, table.connectorHandle().toString()) .startSpan())) { source = splitManager.getSplits( - table.getTransaction(), + table.transaction(), connectorSession, - table.getConnectorHandle(), + table.connectorHandle(), dynamicFilter, constraint); } diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index 9b029092684b..bbdcf2dd2fdb 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -671,7 +671,7 @@ protected Scope visitInsert(Insert insert, Optional scope) Column::new); analysis.setUpdateTarget( - targetTableHandle.get().getCatalogHandle().getVersion(), + targetTableHandle.get().catalogHandle().getVersion(), targetTable, Optional.empty(), Optional.of(Streams.zip( @@ -846,7 +846,7 @@ protected Scope visitDelete(Delete node, Optional scope) node.getWhere().ifPresent(where -> analyzeWhere(node, tableScope, where)); analysis.setUpdateType("DELETE"); - analysis.setUpdateTarget(handle.getCatalogHandle().getVersion(), tableName, Optional.of(table), Optional.empty()); + analysis.setUpdateTarget(handle.catalogHandle().getVersion(), tableName, Optional.of(table), Optional.empty()); Scope accessControlScope = Scope.builder() .withRelationType(RelationId.anonymous(), analysis.getScope(table).getRelationType()) .build(); @@ -871,7 +871,7 @@ protected Scope visitAnalyze(Analyze node, Optional scope) .orElseThrow(() -> semanticException(TABLE_NOT_FOUND, node, "Table '%s' does not exist", tableName)); analysis.setUpdateType("ANALYZE"); - analysis.setUpdateTarget(tableHandle.getCatalogHandle().getVersion(), tableName, Optional.empty(), Optional.empty()); + analysis.setUpdateTarget(tableHandle.catalogHandle().getVersion(), tableName, Optional.empty(), Optional.empty()); validateProperties(node.getProperties(), scope); String catalogName = tableName.catalogName(); @@ -923,7 +923,7 @@ protected Scope visitCreateTableAsSelect(CreateTableAsSelect node, Optional scope) } analysis.setUpdateTarget( - handle.getCatalogHandle().getVersion(), + handle.catalogHandle().getVersion(), tableName, Optional.of(table), Optional.of(updatedColumnSchemas.stream() @@ -3630,7 +3630,7 @@ else if (operation instanceof MergeInsert && caseColumnNames.isEmpty()) { .map(columnHandle -> new OutputColumn(new Column(columnHandle, dataColumnTypes.get(columnHandle).toString()), ImmutableSet.of())) .collect(toImmutableList()); - analysis.setUpdateTarget(targetTableHandle.getCatalogHandle().getVersion(), tableName, Optional.of(table), Optional.of(updatedColumns)); + analysis.setUpdateTarget(targetTableHandle.catalogHandle().getVersion(), tableName, Optional.of(table), Optional.of(updatedColumns)); List> mergeCaseColumnHandles = buildCaseColumnLists(merge, dataColumnSchemas, allColumnHandles); createMergeAnalysis(table, targetTableHandle, tableSchema, targetTableScope, joinScope, mergeCaseColumnHandles); diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/InputExtractor.java b/core/trino-main/src/main/java/io/trino/sql/planner/InputExtractor.java index 5f8a9b82c1ce..8bd27af4829d 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/InputExtractor.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/InputExtractor.java @@ -69,7 +69,7 @@ private Input createInput(Session session, TableHandle table, Set column Optional inputMetadata = metadata.getInfo(session, table); return new Input( tableName.getCatalogName(), - table.getCatalogHandle().getVersion(), + table.catalogHandle().getVersion(), schemaTable.getSchemaName(), schemaTable.getTableName(), inputMetadata, diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java b/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java index 3f484499c1f7..152e3a9c7d36 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/LogicalPlanner.java @@ -588,7 +588,7 @@ private RelationPlan getInsertPlan( .map(ColumnMetadata::getName) .collect(toImmutableList()); - TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, tableHandle.getCatalogHandle(), tableMetadata.metadata()); + TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, tableHandle.catalogHandle(), tableMetadata.metadata()); if (materializedViewRefreshWriterTarget.isPresent()) { return createTableWriterPlan( diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/AddExchanges.java b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/AddExchanges.java index 782ea823e36a..0603bcb8c8b5 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/AddExchanges.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/AddExchanges.java @@ -1531,7 +1531,7 @@ private static Stream collectSourceCatalogs(PlanNode root) .findAll() .stream() .map(TableScanNode.class::cast) - .map(node -> node.getTable().getCatalogHandle()); + .map(node -> node.getTable().catalogHandle()); } private static boolean isNotRemoteExchange(PlanNode node) diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java b/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java index 015227e2e54b..adb8ff023997 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/plan/TableWriterNode.java @@ -389,7 +389,7 @@ public boolean supportsMultipleWritersPerPartition(Metadata metadata, Session se @Override public OptionalInt getMaxWriterTasks(Metadata metadata, Session session) { - return metadata.getMaxWriterTasks(session, handle.getCatalogHandle().getCatalogName().toString()); + return metadata.getMaxWriterTasks(session, handle.catalogHandle().getCatalogName().toString()); } @Override @@ -528,7 +528,7 @@ public boolean supportsMultipleWritersPerPartition(Metadata metadata, Session se @Override public OptionalInt getMaxWriterTasks(Metadata metadata, Session session) { - return metadata.getMaxWriterTasks(session, storageTableHandle.getCatalogHandle().getCatalogName().toString()); + return metadata.getMaxWriterTasks(session, storageTableHandle.catalogHandle().getCatalogName().toString()); } public List getSourceTableFunctions() @@ -623,7 +623,7 @@ public boolean supportsMultipleWritersPerPartition(Metadata metadata, Session se @Override public OptionalInt getMaxWriterTasks(Metadata metadata, Session session) { - return metadata.getMaxWriterTasks(session, tableHandle.getCatalogHandle().getCatalogName().toString()); + return metadata.getMaxWriterTasks(session, tableHandle.catalogHandle().getCatalogName().toString()); } @Override diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java index 81bf6343974e..ae4ff82ce774 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/CounterBasedAnonymizer.java @@ -209,7 +209,7 @@ public String anonymize(WriteStatisticsTarget target) @Override public String anonymize(TableHandle tableHandle) { - return anonymize(tableHandle.getCatalogHandle().getCatalogName().toString(), ObjectType.CATALOG); + return anonymize(tableHandle.catalogHandle().getCatalogName().toString(), ObjectType.CATALOG); } @Override @@ -237,7 +237,7 @@ private String anonymize(InsertTarget target) private String anonymize(MergeTarget target) { return anonymize( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName()); } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java index df07806678ed..b0de8d9d0f12 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/planprinter/IoPlanPrinter.java @@ -705,7 +705,7 @@ else if (writerTarget instanceof InsertTarget target) { } else if (writerTarget instanceof MergeTarget target) { context.setOutputTable(new CatalogSchemaTableName( - target.getHandle().getCatalogHandle().getCatalogName().toString(), + target.getHandle().catalogHandle().getCatalogName().toString(), target.getSchemaTableName().getSchemaName(), target.getSchemaTableName().getTableName())); } diff --git a/core/trino-main/src/main/java/io/trino/sql/rewrite/ShowQueriesRewrite.java b/core/trino-main/src/main/java/io/trino/sql/rewrite/ShowQueriesRewrite.java index 72a5346cb0d3..4a8d94592f66 100644 --- a/core/trino-main/src/main/java/io/trino/sql/rewrite/ShowQueriesRewrite.java +++ b/core/trino-main/src/main/java/io/trino/sql/rewrite/ShowQueriesRewrite.java @@ -690,7 +690,7 @@ protected Node visitShowCreate(ShowCreate node, Void context) accessControl.checkCanShowCreateTable(session.toSecurityContext(), targetTableName); ConnectorTableMetadata connectorTableMetadata = metadata.getTableMetadata(session, tableHandle).metadata(); - Collection> allColumnProperties = columnPropertyManager.getAllProperties(tableHandle.getCatalogHandle()); + Collection> allColumnProperties = columnPropertyManager.getAllProperties(tableHandle.catalogHandle()); List columns = connectorTableMetadata.getColumns().stream() .filter(column -> !column.isHidden()) @@ -706,7 +706,7 @@ protected Node visitShowCreate(ShowCreate node, Void context) .collect(toImmutableList()); Map properties = connectorTableMetadata.getProperties(); - Collection> allTableProperties = tablePropertyManager.getAllProperties(tableHandle.getCatalogHandle()); + Collection> allTableProperties = tablePropertyManager.getAllProperties(tableHandle.catalogHandle()); List propertyNodes = buildProperties(targetTableName, Optional.empty(), INVALID_TABLE_PROPERTY, properties, allTableProperties); CreateTable createTable = new CreateTable( diff --git a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java index be1aa13f4d76..a4d4141bbf6e 100644 --- a/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java +++ b/core/trino-main/src/main/java/io/trino/tracing/TracingMetadata.java @@ -832,9 +832,9 @@ public MergeHandle beginMerge(Session session, TableHandle tableHandle) @Override public void finishMerge(Session session, MergeHandle tableHandle, Collection fragments, Collection computedStatistics) { - Span span = startSpan("finishMerge", tableHandle.tableHandle().getCatalogHandle().getCatalogName()); + Span span = startSpan("finishMerge", tableHandle.tableHandle().catalogHandle().getCatalogName()); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.TABLE, tableHandle.tableHandle().getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.TABLE, tableHandle.tableHandle().connectorHandle().toString()); } try (var ignored = scopedSpan(span)) { delegate.finishMerge(session, tableHandle, fragments, computedStatistics); @@ -1016,8 +1016,8 @@ public Optional> applyAggregation(Sess public Optional> applyJoin(Session session, JoinType joinType, TableHandle left, TableHandle right, ConnectorExpression joinCondition, Map leftAssignments, Map rightAssignments, JoinStatistics statistics) { Span span = startSpan("applyJoin"); - if (span.isRecording() && left.getCatalogHandle().equals(right.getCatalogHandle())) { - span.setAttribute(TrinoAttributes.CATALOG, left.getCatalogHandle().getCatalogName().toString()); + if (span.isRecording() && left.catalogHandle().equals(right.catalogHandle())) { + span.setAttribute(TrinoAttributes.CATALOG, left.catalogHandle().getCatalogName().toString()); } try (var ignored = scopedSpan(span)) { return delegate.applyJoin(session, joinType, left, right, joinCondition, leftAssignments, rightAssignments, statistics); @@ -1595,8 +1595,8 @@ private Span startSpan(String methodName, TableHandle handle) { Span span = startSpan(methodName); if (span.isRecording()) { - span.setAttribute(TrinoAttributes.CATALOG, handle.getCatalogHandle().getCatalogName().toString()); - span.setAttribute(TrinoAttributes.HANDLE, handle.getConnectorHandle().toString()); + span.setAttribute(TrinoAttributes.CATALOG, handle.catalogHandle().getCatalogName().toString()); + span.setAttribute(TrinoAttributes.HANDLE, handle.connectorHandle().toString()); } return span; } diff --git a/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java b/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java index 2d2b0b308944..1cfdc1acaaa4 100644 --- a/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java +++ b/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java @@ -444,7 +444,7 @@ private ConnectorTableMetadata getTableMetadata(TableHandle tableHandle) private SchemaTableName getTableName(TableHandle tableHandle) { - return ((TestingTableHandle) tableHandle.getConnectorHandle()).getTableName(); + return ((TestingTableHandle) tableHandle.connectorHandle()).getTableName(); } @Override diff --git a/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java b/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java index ebe717b3ac46..da2dd1f46341 100644 --- a/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java +++ b/core/trino-main/src/test/java/io/trino/execution/TaskTestUtils.java @@ -80,7 +80,7 @@ private TaskTestUtils() {} public static final PlanNodeId TABLE_SCAN_NODE_ID = new PlanNodeId("tableScan"); - private static final CatalogHandle CATALOG_HANDLE = TEST_TABLE_HANDLE.getCatalogHandle(); + private static final CatalogHandle CATALOG_HANDLE = TEST_TABLE_HANDLE.catalogHandle(); public static final ScheduledSplit SPLIT = new ScheduledSplit(0, TABLE_SCAN_NODE_ID, new Split(CATALOG_HANDLE, TestingSplit.createLocalSplit())); diff --git a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java index a1be71f611c4..aab7348ba32f 100644 --- a/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java +++ b/core/trino-main/src/test/java/io/trino/sql/analyzer/TestAnalyzer.java @@ -3532,12 +3532,12 @@ public void testAnalysisDuplicateNames() // Materialized view redirects to "t1" Analysis analysis = analyze("SELECT * FROM table_view_and_materialized_view"); TableHandle handle = getOnlyElement(analysis.getTables()); - assertThat(((TestingTableHandle) handle.getConnectorHandle()).getTableName().getTableName()).isEqualTo("t1"); + assertThat(((TestingTableHandle) handle.connectorHandle()).getTableName().getTableName()).isEqualTo("t1"); // View redirects to "t2" analysis = analyze("SELECT * FROM table_and_view"); handle = getOnlyElement(analysis.getTables()); - assertThat(((TestingTableHandle) handle.getConnectorHandle()).getTableName().getTableName()).isEqualTo("t2"); + assertThat(((TestingTableHandle) handle.connectorHandle()).getTableName().getTableName()).isEqualTo("t2"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/TestEffectivePredicateExtractor.java b/core/trino-main/src/test/java/io/trino/sql/planner/TestEffectivePredicateExtractor.java index f886c04a229e..7d33868d308a 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/TestEffectivePredicateExtractor.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/TestEffectivePredicateExtractor.java @@ -147,7 +147,7 @@ public TableProperties getTableProperties(Session session, TableHandle handle) TEST_CATALOG_HANDLE, TestingConnectorTransactionHandle.INSTANCE, new ConnectorTableProperties( - ((PredicatedTableHandle) handle.getConnectorHandle()).getPredicate(), + ((PredicatedTableHandle) handle.connectorHandle()).getPredicate(), Optional.empty(), Optional.empty(), ImmutableList.of())); diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/assertions/ConnectorAwareTableScanMatcher.java b/core/trino-main/src/test/java/io/trino/sql/planner/assertions/ConnectorAwareTableScanMatcher.java index 7526bb819ca8..dbf56a362c91 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/assertions/ConnectorAwareTableScanMatcher.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/assertions/ConnectorAwareTableScanMatcher.java @@ -63,7 +63,7 @@ public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session ses TupleDomain actual = tableScanNode.getEnforcedConstraint(); - boolean tableMatches = expectedTable.test(tableScanNode.getTable().getConnectorHandle()); + boolean tableMatches = expectedTable.test(tableScanNode.getTable().connectorHandle()); boolean domainsMatch = domainsMatch(expectedEnforcedConstraint, actual); boolean statisticMatch = expectedStatistics.test(tableScanNode.getStatistics()); diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestDetermineTableScanNodePartitioning.java b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestDetermineTableScanNodePartitioning.java index d99e3feea531..b8a1da7b82bc 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestDetermineTableScanNodePartitioning.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestDetermineTableScanNodePartitioning.java @@ -155,7 +155,7 @@ private void testPlanWithTableNodePartitioning( }) .matches( tableScan( - tableHandle.getConnectorHandle()::equals, + tableHandle.connectorHandle()::equals, TupleDomain.all(), ImmutableMap.of( "A", COLUMN_HANDLE_A::equals, diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestPushDownDereferencesRules.java b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestPushDownDereferencesRules.java index 27ce5ad88f7f..1f98fede465d 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestPushDownDereferencesRules.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/TestPushDownDereferencesRules.java @@ -351,7 +351,7 @@ public void testExtractDereferencesFromFilterAboveScan() "a", expression(new Reference(nestedRowType, "a")), "b", expression(new Reference(ROW_TYPE, "b"))), tableScan( - testTable.getConnectorHandle()::equals, + testTable.connectorHandle()::equals, TupleDomain.all(), ImmutableMap.of( "a", new TpchColumnHandle("a", nestedRowType)::equals, diff --git a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/test/PlanBuilder.java b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/test/PlanBuilder.java index d5ee038e8c0a..59d440a27a08 100644 --- a/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/test/PlanBuilder.java +++ b/core/trino-main/src/test/java/io/trino/sql/planner/iterative/rule/test/PlanBuilder.java @@ -867,7 +867,7 @@ public IndexSourceNode indexSource( return new IndexSourceNode( idAllocator.getNextId(), new IndexHandle( - tableHandle.getCatalogHandle(), + tableHandle.catalogHandle(), TestingConnectorTransactionHandle.INSTANCE, TestingConnectorIndexHandle.INSTANCE), tableHandle, diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeNodeLocalDynamicSplitPruning.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeNodeLocalDynamicSplitPruning.java index 23c4021abc1b..0f138d5ae673 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeNodeLocalDynamicSplitPruning.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeNodeLocalDynamicSplitPruning.java @@ -335,7 +335,7 @@ private static ConnectorPageSource createTestingPageSource( transaction, getSession(deltaLakeConfig), split, - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), columns, dynamicFilter); } diff --git a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeProjectionPushdownPlans.java b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeProjectionPushdownPlans.java index bd96e9f46a1e..69bb1df51727 100644 --- a/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeProjectionPushdownPlans.java +++ b/plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeProjectionPushdownPlans.java @@ -179,7 +179,7 @@ public void testDereferencePushdown() assertPlan( "SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan( - equalTo(((DeltaLakeTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), + equalTo(((DeltaLakeTableHandle) tableHandle.get().connectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), TupleDomain.all(), ImmutableMap.of("col0.x", equalTo(columnX), "col0.y", equalTo(columnY))))); @@ -251,7 +251,7 @@ public void testDereferencePushdown() .right( anyTree( tableScan( - equalTo(((DeltaLakeTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(column1Handle))), + equalTo(((DeltaLakeTableHandle) tableHandle.get().connectorHandle()).withProjectedColumns(Set.of(column1Handle))), TupleDomain.all(), ImmutableMap.of("s_expr_1", equalTo(column1Handle))))); })))); diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java index ce9d00a53e4e..a400228843c5 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/BaseHiveConnectorTest.java @@ -3814,7 +3814,7 @@ private Object getHiveTableProperty(String tableName, Function new AssertionError("applyFilter did not return a result")) .getHandle(); - return propertyGetter.apply((HiveTableHandle) table.getConnectorHandle()); + return propertyGetter.apply((HiveTableHandle) table.connectorHandle()); }); } diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestNodeLocalDynamicSplitPruning.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestNodeLocalDynamicSplitPruning.java index 52c13e20554a..2c8738bdedc7 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestNodeLocalDynamicSplitPruning.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestNodeLocalDynamicSplitPruning.java @@ -165,7 +165,7 @@ private static ConnectorPageSource createTestingPageSource(HiveTransactionHandle transaction, getSession(hiveConfig), split, - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), ImmutableList.of(BUCKET_HIVE_COLUMN_HANDLE, PARTITION_HIVE_COLUMN_HANDLE), dynamicFilter); } diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/optimizer/TestHiveProjectionPushdownIntoTableScan.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/optimizer/TestHiveProjectionPushdownIntoTableScan.java index f643bab995e7..619901020c97 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/optimizer/TestHiveProjectionPushdownIntoTableScan.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/optimizer/TestHiveProjectionPushdownIntoTableScan.java @@ -168,7 +168,7 @@ public void testDereferencePushdown() assertPlan( "SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan( - ((HiveTableHandle) tableHandle.get().getConnectorHandle()) + ((HiveTableHandle) tableHandle.get().connectorHandle()) .withProjectedColumns(ImmutableSet.of(columnX, columnY))::equals, TupleDomain.all(), ImmutableMap.of("col0#x", columnX::equals, "col0#y", columnY::equals)))); @@ -230,7 +230,7 @@ public void testDereferencePushdown() .right( anyTree( tableScan( - ((HiveTableHandle) tableHandle.get().getConnectorHandle()) + ((HiveTableHandle) tableHandle.get().connectorHandle()) .withProjectedColumns(ImmutableSet.of(column1Handle))::equals, TupleDomain.all(), ImmutableMap.of("s_expr_1", column1Handle::equals)))))))); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java index 9f72fcf068e2..fe2e1927c96f 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java @@ -3932,7 +3932,7 @@ private void assertFilterPushdown( assertThat((expectedUnenforcedPredicate == null && expectedEnforcedPredicate == null)).isEqualTo(result.isEmpty()); if (result.isPresent()) { - IcebergTableHandle newTable = (IcebergTableHandle) result.get().getHandle().getConnectorHandle(); + IcebergTableHandle newTable = (IcebergTableHandle) result.get().getHandle().connectorHandle(); assertThat(newTable.getEnforcedPredicate()).isEqualTo(TupleDomain.withColumnDomains(expectedEnforcedPredicate.entrySet().stream() .collect(toImmutableMap(entry -> columns.get(entry.getKey()), Map.Entry::getValue)))); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java index 360b165ad0f0..58e05af7da68 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java @@ -578,7 +578,7 @@ private static ConnectorPageSource createTestingPageSource( transaction, getSession(icebergConfig), split, - tableHandle.getConnectorHandle(), + tableHandle.connectorHandle(), columns, dynamicFilter); } diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java index 7bffb6dba579..68b08555344c 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java @@ -183,7 +183,7 @@ public void testDereferencePushdown() assertPlan( "SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan( - equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), + equalTo(((IcebergTableHandle) tableHandle.get().connectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), TupleDomain.all(), ImmutableMap.of("col0#x", equalTo(columnX), "col0#y", equalTo(columnY))))); @@ -233,7 +233,7 @@ public void testDereferencePushdown() .left( anyTree( tableScan( - equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(column1Handle))), + equalTo(((IcebergTableHandle) tableHandle.get().connectorHandle()).withProjectedColumns(Set.of(column1Handle))), TupleDomain.all(), ImmutableMap.of("s_expr_1", equalTo(column1Handle))))) .right( diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java index 1f8748b91356..5d7cc69e655c 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java @@ -239,7 +239,7 @@ public void testPredicatePushdown() { String tableName = "predicate_test"; tester().getPlanTester().executeStatement(format("CREATE TABLE %s (a, b) AS SELECT 5, 6", tableName)); - long snapshotId = ((IcebergTableHandle) tester().getPlanTester().getTableHandle(TEST_CATALOG_NAME, SCHEMA_NAME, tableName).getConnectorHandle()).getSnapshotId().orElseThrow(); + long snapshotId = ((IcebergTableHandle) tester().getPlanTester().getTableHandle(TEST_CATALOG_NAME, SCHEMA_NAME, tableName).connectorHandle()).getSnapshotId().orElseThrow(); PushPredicateIntoTableScan pushPredicateIntoTableScan = new PushPredicateIntoTableScan(tester().getPlannerContext(), false); diff --git a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoProjectionPushdownPlans.java b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoProjectionPushdownPlans.java index 01a86a666bf3..63a23b0d021d 100644 --- a/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoProjectionPushdownPlans.java +++ b/plugin/trino-mongodb/src/test/java/io/trino/plugin/mongodb/TestMongoProjectionPushdownPlans.java @@ -150,7 +150,7 @@ public void testDereferencePushdown() Optional tableHandle = getTableHandle(session, completeTableName); assertThat(tableHandle).as("expected the table handle to be present").isPresent(); - MongoTableHandle mongoTableHandle = (MongoTableHandle) tableHandle.get().getConnectorHandle(); + MongoTableHandle mongoTableHandle = (MongoTableHandle) tableHandle.get().connectorHandle(); Map columns = getColumnHandles(session, completeTableName); MongoColumnHandle column0Handle = (MongoColumnHandle) columns.get("col0"); @@ -247,7 +247,7 @@ public void testDereferencePushdownWithDotAndDollarContainingField() Optional tableHandle = getTableHandle(session, completeTableName); assertThat(tableHandle).as("expected the table handle to be present").isPresent(); - MongoTableHandle mongoTableHandle = (MongoTableHandle) tableHandle.get().getConnectorHandle(); + MongoTableHandle mongoTableHandle = (MongoTableHandle) tableHandle.get().connectorHandle(); Map columns = getColumnHandles(session, completeTableName); RowType rowType = RowType.rowType( diff --git a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java index f222b4e7444b..35fcb9c81a83 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestQueryFramework.java @@ -722,7 +722,7 @@ private CatalogSchemaTableName getTableName(TableHandle tableHandle) { return inTransaction(getSession(), transactionSession -> { // metadata.getCatalogHandle() registers the catalog for the transaction - getQueryRunner().getPlannerContext().getMetadata().getCatalogHandle(transactionSession, tableHandle.getCatalogHandle().getCatalogName().toString()); + getQueryRunner().getPlannerContext().getMetadata().getCatalogHandle(transactionSession, tableHandle.catalogHandle().getCatalogName().toString()); return getQueryRunner().getPlannerContext().getMetadata().getTableName(transactionSession, tableHandle); }); } diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java index f95bd7c5cbfb..bfb8b1f903d7 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestTableRedirection.java @@ -428,7 +428,7 @@ public void testDelete() .where(TableFinishNode.class::isInstance) .findOnlyElement(); TableWriterNode.MergeTarget mergeTarget = (TableWriterNode.MergeTarget) finishNode.getTarget(); - assertThat(((MockConnectorTableHandle) mergeTarget.getHandle().getConnectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); + assertThat(((MockConnectorTableHandle) mergeTarget.getHandle().connectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); assertThat(mergeTarget.getSchemaTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); }); } @@ -446,7 +446,7 @@ public void testUpdate() .where(TableFinishNode.class::isInstance) .findOnlyElement(); TableWriterNode.MergeTarget mergeTarget = (TableWriterNode.MergeTarget) finishNode.getTarget(); - assertThat(((MockConnectorTableHandle) mergeTarget.getHandle().getConnectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); + assertThat(((MockConnectorTableHandle) mergeTarget.getHandle().connectorHandle()).getTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); assertThat(mergeTarget.getSchemaTableName()).isEqualTo(schemaTableName(SCHEMA_TWO, VALID_REDIRECTION_TARGET)); }); } @@ -466,7 +466,7 @@ private Consumer verifySingleTableScan(String schemaName, String tableName TableScanNode tableScan = (TableScanNode) searchFrom(plan.getRoot()) .where(TableScanNode.class::isInstance) .findOnlyElement(); - SchemaTableName actual = ((MockConnectorTableHandle) tableScan.getTable().getConnectorHandle()).getTableName(); + SchemaTableName actual = ((MockConnectorTableHandle) tableScan.getTable().connectorHandle()).getTableName(); assertThat(actual).isEqualTo(schemaTableName(schemaName, tableName)); }; } From 791b063ea6adf696a55f6288f8e03a8b68b3829b Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:16:42 +0200 Subject: [PATCH 17/21] Convert TablePartitioning to record --- .../io/trino/metadata/TableProperties.java | 53 +++---------------- .../io/trino/sql/planner/PlanFragmenter.java | 4 +- .../DetermineTableScanNodePartitioning.java | 4 +- .../optimizations/PropertyDerivations.java | 6 +-- .../StreamPropertyDerivations.java | 4 +- 5 files changed, 16 insertions(+), 55 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableProperties.java b/core/trino-main/src/main/java/io/trino/metadata/TableProperties.java index 2bca714eb7db..332134bdad58 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableProperties.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableProperties.java @@ -24,7 +24,6 @@ import io.trino.sql.planner.PartitioningHandle; import java.util.List; -import java.util.Objects; import java.util.Optional; import static java.util.Objects.requireNonNull; @@ -73,53 +72,15 @@ public Optional getDiscretePredicates() return tableProperties.getDiscretePredicates(); } - public static class TablePartitioning + public record TablePartitioning( + PartitioningHandle partitioningHandle, + List partitioningColumns, + boolean singleSplitPerPartition) { - private final PartitioningHandle partitioningHandle; - private final List partitioningColumns; - private final boolean singleSplitPerPartition; - - public TablePartitioning(PartitioningHandle partitioningHandle, List partitioningColumns, boolean singleSplitPerPartition) - { - this.partitioningHandle = requireNonNull(partitioningHandle, "partitioningHandle is null"); - this.partitioningColumns = ImmutableList.copyOf(requireNonNull(partitioningColumns, "partitioningColumns is null")); - this.singleSplitPerPartition = singleSplitPerPartition; - } - - public PartitioningHandle getPartitioningHandle() - { - return partitioningHandle; - } - - public List getPartitioningColumns() - { - return partitioningColumns; - } - - public boolean isSingleSplitPerPartition() - { - return singleSplitPerPartition; - } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TablePartitioning that = (TablePartitioning) o; - return singleSplitPerPartition == that.singleSplitPerPartition && - Objects.equals(partitioningHandle, that.partitioningHandle) && - Objects.equals(partitioningColumns, that.partitioningColumns); - } - - @Override - public int hashCode() + public TablePartitioning { - return Objects.hash(partitioningHandle, partitioningColumns, singleSplitPerPartition); + requireNonNull(partitioningHandle, "partitioningHandle is null"); + partitioningColumns = ImmutableList.copyOf(requireNonNull(partitioningColumns, "partitioningColumns is null")); } } } diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java b/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java index d1f5ee107c93..1f8c5989c02c 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/PlanFragmenter.java @@ -361,7 +361,7 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext node.isUseConnectorNodePartitioning()) - .map(TablePartitioning::getPartitioningHandle) + .map(TablePartitioning::partitioningHandle) .orElse(SOURCE_DISTRIBUTION); context.get().addSourceDistribution(node.getId(), partitioning, metadata, session); @@ -799,7 +799,7 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext context) PartitioningHandle partitioning = metadata.getTableProperties(session, node.getTable()) .getTablePartitioning() .filter(value -> node.isUseConnectorNodePartitioning()) - .map(TablePartitioning::getPartitioningHandle) + .map(TablePartitioning::partitioningHandle) .orElse(SOURCE_DISTRIBUTION); if (partitioning.equals(fragmentPartitioningHandle)) { // do nothing if the current scan node's partitioning matches the fragment's diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/DetermineTableScanNodePartitioning.java b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/DetermineTableScanNodePartitioning.java index 8b562a63ad29..0810f8381196 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/DetermineTableScanNodePartitioning.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/iterative/rule/DetermineTableScanNodePartitioning.java @@ -64,7 +64,7 @@ public Result apply(TableScanNode node, Captures captures, Context context) } TablePartitioning partitioning = properties.getTablePartitioning().get(); - Optional bucketNodeMap = nodePartitioningManager.getConnectorBucketNodeMap(context.getSession(), partitioning.getPartitioningHandle()); + Optional bucketNodeMap = nodePartitioningManager.getConnectorBucketNodeMap(context.getSession(), partitioning.partitioningHandle()); if (bucketNodeMap.map(ConnectorBucketNodeMap::hasFixedMapping).orElse(false)) { // use connector table scan node partitioning when bucket to node assignments are fixed return Result.ofPlanNode(node.withUseConnectorNodePartitioning(true)); @@ -75,7 +75,7 @@ public Result apply(TableScanNode node, Captures captures, Context context) } int numberOfBuckets = bucketNodeMap.map(ConnectorBucketNodeMap::getBucketCount) - .orElseGet(() -> nodePartitioningManager.getNodeCount(context.getSession(), partitioning.getPartitioningHandle())); + .orElseGet(() -> nodePartitioningManager.getNodeCount(context.getSession(), partitioning.partitioningHandle())); int numberOfTasks = max(taskCountEstimator.estimateSourceDistributedTaskCount(context.getSession()), 1); return Result.ofPlanNode(node diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PropertyDerivations.java b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PropertyDerivations.java index 6b34be6f02d8..c84f1c58ad40 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PropertyDerivations.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PropertyDerivations.java @@ -894,12 +894,12 @@ private Global deriveGlobalProperties(TableScanNode node, TableProperties layout { if (layout.getTablePartitioning().isPresent() && node.isUseConnectorNodePartitioning()) { TablePartitioning tablePartitioning = layout.getTablePartitioning().get(); - if (assignments.keySet().containsAll(tablePartitioning.getPartitioningColumns())) { - List arguments = tablePartitioning.getPartitioningColumns().stream() + if (assignments.keySet().containsAll(tablePartitioning.partitioningColumns())) { + List arguments = tablePartitioning.partitioningColumns().stream() .map(assignments::get) .collect(toImmutableList()); - return partitionedOn(tablePartitioning.getPartitioningHandle(), arguments); + return partitionedOn(tablePartitioning.partitioningHandle(), arguments); } } return arbitraryPartition(); diff --git a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/StreamPropertyDerivations.java b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/StreamPropertyDerivations.java index ab181c9e58f2..2a717e4ec8ef 100644 --- a/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/StreamPropertyDerivations.java +++ b/core/trino-main/src/main/java/io/trino/sql/planner/optimizations/StreamPropertyDerivations.java @@ -321,10 +321,10 @@ public StreamProperties visitTableScan(TableScanNode node, List constants.add(entry.getKey())); Optional> partitioningSymbols = layout.getTablePartitioning().flatMap(partitioning -> { - if (!partitioning.isSingleSplitPerPartition()) { + if (!partitioning.singleSplitPerPartition()) { return Optional.empty(); } - Optional> symbols = getNonConstantSymbols(partitioning.getPartitioningColumns(), assignments, constants); + Optional> symbols = getNonConstantSymbols(partitioning.partitioningColumns(), assignments, constants); // if we are partitioned on empty set, we must say multiple of unknown partitioning, because // the connector does not guarantee a single split in this case (since it might not understand // that the value is a constant). From de815f0622ba7eda4468de7b017ec19a3b4925e4 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Tue, 16 Apr 2024 14:18:38 +0200 Subject: [PATCH 18/21] Convert TableVersion to record --- .../io/trino/metadata/MetadataManager.java | 2 +- .../java/io/trino/metadata/TableVersion.java | 29 +------------------ .../trino/sql/analyzer/StatementAnalyzer.java | 6 ++-- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java index 0d51aa3aaded..300f02821866 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MetadataManager.java @@ -2763,7 +2763,7 @@ private Optional toConnectorVersion(Optional connectorVersion = Optional.empty(); if (version.isPresent()) { - connectorVersion = Optional.of(new ConnectorTableVersion(version.get().getPointerType(), version.get().getObjectType(), version.get().getPointer())); + connectorVersion = Optional.of(new ConnectorTableVersion(version.get().pointerType(), version.get().objectType(), version.get().pointer())); } return connectorVersion; } diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java b/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java index 0c9be6598d56..c6378d6a6584 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java @@ -16,31 +16,4 @@ import io.trino.spi.connector.PointerType; import io.trino.spi.type.Type; -public class TableVersion -{ - private final PointerType pointerType; - private final Type objectType; - private final Object pointer; - - public TableVersion(PointerType pointerType, Type objectType, Object pointer) - { - this.pointerType = pointerType; - this.objectType = objectType; - this.pointer = pointer; - } - - public PointerType getPointerType() - { - return pointerType; - } - - public Type getObjectType() - { - return objectType; - } - - public Object getPointer() - { - return pointer; - } -} +public record TableVersion(PointerType pointerType, Type objectType, Object pointer) {} diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index bbdcf2dd2fdb..eca7716c508c 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -5860,9 +5860,9 @@ private Optional extractTableVersion(Table table, Optional Date: Tue, 16 Apr 2024 14:19:45 +0200 Subject: [PATCH 19/21] Convert ViewColumn to record --- .../connector/InternalMetadataProvider.java | 4 +- .../java/io/trino/execution/CommentTask.java | 6 +-- .../metadata/MaterializedViewDefinition.java | 2 +- .../java/io/trino/metadata/ViewColumn.java | 50 ++----------------- .../io/trino/metadata/ViewDefinition.java | 2 +- .../trino/sql/analyzer/StatementAnalyzer.java | 14 +++--- .../execution/BaseDataDefinitionTaskTest.java | 4 +- .../io/trino/execution/TestCommentTask.java | 4 +- 8 files changed, 23 insertions(+), 63 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/connector/InternalMetadataProvider.java b/core/trino-main/src/main/java/io/trino/connector/InternalMetadataProvider.java index e579c22d9d90..6ff348d7ab6f 100644 --- a/core/trino-main/src/main/java/io/trino/connector/InternalMetadataProvider.java +++ b/core/trino-main/src/main/java/io/trino/connector/InternalMetadataProvider.java @@ -76,8 +76,8 @@ private List toColumnSchema(List viewColumns) return viewColumns.stream() .map(viewColumn -> ColumnSchema.builder() - .setName(viewColumn.getName()) - .setType(typeManager.getType(viewColumn.getType())) + .setName(viewColumn.name()) + .setType(typeManager.getType(viewColumn.type())) .build()) .collect(toImmutableList()); } diff --git a/core/trino-main/src/main/java/io/trino/execution/CommentTask.java b/core/trino-main/src/main/java/io/trino/execution/CommentTask.java index 7b148d0cdc80..5b27b082d8a2 100644 --- a/core/trino-main/src/main/java/io/trino/execution/CommentTask.java +++ b/core/trino-main/src/main/java/io/trino/execution/CommentTask.java @@ -145,12 +145,12 @@ private void commentOnColumn(Comment statement, Session session) if (view.isPresent()) { ViewDefinition viewDefinition = view.get(); ViewColumn viewColumn = findAndCheckViewColumn(statement, session, viewDefinition, originalObjectName); - metadata.setViewColumnComment(session, originalObjectName, viewColumn.getName(), statement.getComment()); + metadata.setViewColumnComment(session, originalObjectName, viewColumn.name(), statement.getComment()); } else if (metadata.isMaterializedView(session, originalObjectName)) { MaterializedViewDefinition materializedViewDefinition = metadata.getMaterializedView(session, originalObjectName).get(); ViewColumn viewColumn = findAndCheckViewColumn(statement, session, materializedViewDefinition, originalObjectName); - metadata.setMaterializedViewColumnComment(session, originalObjectName, viewColumn.getName(), statement.getComment()); + metadata.setMaterializedViewColumnComment(session, originalObjectName, viewColumn.name(), statement.getComment()); } else { RedirectionAwareTableHandle redirectionAwareTableHandle = metadata.getRedirectionAwareTableHandle(session, originalObjectName); @@ -175,7 +175,7 @@ private ViewColumn findAndCheckViewColumn(Comment statement, Session session, Vi { String columnName = statement.getName().getSuffix(); ViewColumn viewColumn = viewDefinition.getColumns().stream() - .filter(column -> column.getName().equals(columnName)) + .filter(column -> column.name().equals(columnName)) .findAny() .orElseThrow(() -> semanticException(COLUMN_NOT_FOUND, statement, "Column does not exist: %s", columnName)); accessControl.checkCanSetColumnComment(session.toSecurityContext(), originalObjectName); diff --git a/core/trino-main/src/main/java/io/trino/metadata/MaterializedViewDefinition.java b/core/trino-main/src/main/java/io/trino/metadata/MaterializedViewDefinition.java index 6dc49947b030..c6aa7e5be41f 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/MaterializedViewDefinition.java +++ b/core/trino-main/src/main/java/io/trino/metadata/MaterializedViewDefinition.java @@ -68,7 +68,7 @@ public ConnectorMaterializedViewDefinition toConnectorMaterializedViewDefinition getCatalog(), getSchema(), getColumns().stream() - .map(column -> new ConnectorMaterializedViewDefinition.Column(column.getName(), column.getType(), column.getComment())) + .map(column -> new ConnectorMaterializedViewDefinition.Column(column.name(), column.type(), column.comment())) .collect(toImmutableList()), getGracePeriod(), getComment(), diff --git a/core/trino-main/src/main/java/io/trino/metadata/ViewColumn.java b/core/trino-main/src/main/java/io/trino/metadata/ViewColumn.java index ce03e472d80c..72e4ee22644d 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/ViewColumn.java +++ b/core/trino-main/src/main/java/io/trino/metadata/ViewColumn.java @@ -15,39 +15,18 @@ import io.trino.spi.type.TypeId; -import java.util.Objects; import java.util.Optional; import static com.google.common.base.MoreObjects.toStringHelper; import static java.util.Objects.requireNonNull; -public final class ViewColumn +public record ViewColumn(String name, TypeId type, Optional comment) { - private final String name; - private final TypeId type; - - private final Optional comment; - - public ViewColumn(String name, TypeId type, Optional comment) - { - this.name = requireNonNull(name, "name is null"); - this.type = requireNonNull(type, "type is null"); - this.comment = requireNonNull(comment, "comment is null"); - } - - public String getName() + public ViewColumn { - return name; - } - - public TypeId getType() - { - return type; - } - - public Optional getComment() - { - return comment; + requireNonNull(name, "name is null"); + requireNonNull(type, "type is null"); + requireNonNull(comment, "comment is null"); } @Override @@ -59,23 +38,4 @@ public String toString() .add("comment", comment.orElse(null)) .toString(); } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - ViewColumn that = (ViewColumn) o; - return Objects.equals(name, that.name) && Objects.equals(type, that.type) && Objects.equals(comment, that.comment); - } - - @Override - public int hashCode() - { - return Objects.hash(name, type, comment); - } } diff --git a/core/trino-main/src/main/java/io/trino/metadata/ViewDefinition.java b/core/trino-main/src/main/java/io/trino/metadata/ViewDefinition.java index 413c46f024f5..d87dfdb0dd07 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/ViewDefinition.java +++ b/core/trino-main/src/main/java/io/trino/metadata/ViewDefinition.java @@ -102,7 +102,7 @@ public ConnectorViewDefinition toConnectorViewDefinition() catalog, schema, columns.stream() - .map(column -> new ConnectorViewDefinition.ViewColumn(column.getName(), column.getType(), column.getComment())) + .map(column -> new ConnectorViewDefinition.ViewColumn(column.name(), column.type(), column.comment())) .collect(toImmutableList()), comment, runAsIdentity.map(Identity::getUser), diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java index eca7716c508c..1f70ad5754c2 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/StatementAnalyzer.java @@ -2544,11 +2544,11 @@ private Scope createScopeForView( List viewFields = columns.stream() .map(column -> Field.newQualified( table.getName(), - Optional.of(column.getName()), + Optional.of(column.name()), getViewColumnType(column, name, table), false, Optional.of(name), - Optional.of(column.getName()), + Optional.of(column.name()), false)) .collect(toImmutableList()); @@ -5005,13 +5005,13 @@ private Optional checkViewStaleness(List columns, Collection i)); } String fieldName = field.getName().orElseThrow(); - if (!column.getName().equalsIgnoreCase(fieldName)) { + if (!column.name().equalsIgnoreCase(fieldName)) { return Optional.of(format( "column [%s] of type %s projected from query view at position %s has a different name from column [%s] of type %s stored in view definition", fieldName, field.getType(), i, - column.getName(), + column.name(), type)); } if (!typeCoercion.canCoerce(field.getType(), type)) { @@ -5020,7 +5020,7 @@ private Optional checkViewStaleness(List columns, Collection fieldName, field.getType(), i, - column.getName(), + column.name(), type)); } } @@ -5031,10 +5031,10 @@ private Optional checkViewStaleness(List columns, Collection private Type getViewColumnType(ViewColumn column, QualifiedObjectName name, Node node) { try { - return plannerContext.getTypeManager().getType(column.getType()); + return plannerContext.getTypeManager().getType(column.type()); } catch (TypeNotFoundException e) { - throw semanticException(INVALID_VIEW, node, e, "Unknown type '%s' for column '%s' in view: %s", column.getType(), column.getName(), name); + throw semanticException(INVALID_VIEW, node, e, "Unknown type '%s' for column '%s' in view: %s", column.type(), column.name(), name); } } diff --git a/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java b/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java index 1cfdc1acaaa4..be6856872441 100644 --- a/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java +++ b/core/trino-main/src/test/java/io/trino/execution/BaseDataDefinitionTaskTest.java @@ -520,7 +520,7 @@ public void setMaterializedViewColumnComment(Session session, QualifiedObjectNam view.getCatalog(), view.getSchema(), view.getColumns().stream() - .map(currentViewColumn -> columnName.equals(currentViewColumn.getName()) ? new ViewColumn(currentViewColumn.getName(), currentViewColumn.getType(), comment) : currentViewColumn) + .map(currentViewColumn -> columnName.equals(currentViewColumn.name()) ? new ViewColumn(currentViewColumn.name(), currentViewColumn.type(), comment) : currentViewColumn) .collect(toImmutableList()), view.getGracePeriod(), view.getComment(), @@ -616,7 +616,7 @@ public void setViewColumnComment(Session session, QualifiedObjectName viewName, view.getCatalog(), view.getSchema(), view.getColumns().stream() - .map(currentViewColumn -> columnName.equals(currentViewColumn.getName()) ? new ViewColumn(currentViewColumn.getName(), currentViewColumn.getType(), comment) : currentViewColumn) + .map(currentViewColumn -> columnName.equals(currentViewColumn.name()) ? new ViewColumn(currentViewColumn.name(), currentViewColumn.type(), comment) : currentViewColumn) .collect(toImmutableList()), view.getComment(), view.getRunAsIdentity(), diff --git a/core/trino-main/src/test/java/io/trino/execution/TestCommentTask.java b/core/trino-main/src/test/java/io/trino/execution/TestCommentTask.java index 0748ca4bf702..1b4618309e23 100644 --- a/core/trino-main/src/test/java/io/trino/execution/TestCommentTask.java +++ b/core/trino-main/src/test/java/io/trino/execution/TestCommentTask.java @@ -134,7 +134,7 @@ public void testCommentViewColumn() assertThat(metadata.isView(testSession, viewName)).isTrue(); getFutureValue(setComment(COLUMN, columnName, Optional.of("new test column comment"))); - assertThat(metadata.getView(testSession, viewName).get().getColumns().stream().filter(column -> "test".equals(column.getName())).collect(onlyElement()).getComment()) + assertThat(metadata.getView(testSession, viewName).get().getColumns().stream().filter(column -> "test".equals(column.name())).collect(onlyElement()).comment()) .isEqualTo(Optional.of("new test column comment")); assertTrinoExceptionThrownBy(() -> getFutureValue(setComment(COLUMN, missingColumnName, Optional.of("comment for missing column")))) @@ -153,7 +153,7 @@ public void testCommentMaterializedViewColumn() QualifiedName missingColumnName = qualifiedColumnName("existing_materialized_view", "missing"); getFutureValue(setComment(COLUMN, columnName, Optional.of("new test column comment"))); - assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getColumns().stream().filter(column -> "test".equals(column.getName())).collect(onlyElement()).getComment()) + assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getColumns().stream().filter(column -> "test".equals(column.name())).collect(onlyElement()).comment()) .isEqualTo(Optional.of("new test column comment")); assertTrinoExceptionThrownBy(() -> getFutureValue(setComment(COLUMN, missingColumnName, Optional.of("comment for missing column")))) From ebdd8dd1e0be3384c8dee80566a62c3814d89e4d Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Wed, 17 Apr 2024 09:12:43 +0200 Subject: [PATCH 20/21] Include tableName in the OutputTableHandle equals and hashCode --- .../io/trino/metadata/OutputTableHandle.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java b/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java index 69442579726e..45d132c327bc 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java +++ b/core/trino-main/src/main/java/io/trino/metadata/OutputTableHandle.java @@ -18,8 +18,6 @@ import io.trino.spi.connector.ConnectorTransactionHandle; import io.trino.spi.connector.SchemaTableName; -import java.util.Objects; - import static java.util.Objects.requireNonNull; public record OutputTableHandle( @@ -36,27 +34,6 @@ public record OutputTableHandle( requireNonNull(connectorHandle, "connectorHandle is null"); } - @Override - public int hashCode() - { - return Objects.hash(catalogHandle, transactionHandle, connectorHandle); - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - OutputTableHandle other = (OutputTableHandle) obj; - return Objects.equals(this.catalogHandle, other.catalogHandle) && - Objects.equals(this.transactionHandle, other.transactionHandle) && - Objects.equals(this.connectorHandle, other.connectorHandle); - } - @Override public String toString() { From 122abdf6a4888a4bc1e0aa3d8eee661a1f66a3c4 Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Wed, 17 Apr 2024 09:14:35 +0200 Subject: [PATCH 21/21] Validate non-nullable TableVersion constructor arguments --- .../src/main/java/io/trino/metadata/TableVersion.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java b/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java index c6378d6a6584..9ea922d40f44 100644 --- a/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java +++ b/core/trino-main/src/main/java/io/trino/metadata/TableVersion.java @@ -16,4 +16,12 @@ import io.trino.spi.connector.PointerType; import io.trino.spi.type.Type; -public record TableVersion(PointerType pointerType, Type objectType, Object pointer) {} +import static java.util.Objects.requireNonNull; + +public record TableVersion(PointerType pointerType, Type objectType, Object pointer) +{ + public TableVersion + { + requireNonNull(objectType, "objectType is null"); + } +}