From aebd6bd1e27d8ec430d64c72a5761ed3a1ab0706 Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Wed, 26 Jul 2023 07:33:09 +0900 Subject: [PATCH] Replace CountingAccessMetadata with OpenTelemetry --- .../metadata/CountingAccessMetadata.java | 907 ------------------ plugin/trino-iceberg/pom.xml | 12 + ...stIcebergGetTableStatisticsOperations.java | 40 +- testing/trino-tests/pom.xml | 12 + .../TestGetTableStatisticsOperations.java | 40 +- 5 files changed, 74 insertions(+), 937 deletions(-) delete mode 100644 core/trino-main/src/test/java/io/trino/metadata/CountingAccessMetadata.java diff --git a/core/trino-main/src/test/java/io/trino/metadata/CountingAccessMetadata.java b/core/trino-main/src/test/java/io/trino/metadata/CountingAccessMetadata.java deleted file mode 100644 index 86c34c265116..000000000000 --- a/core/trino-main/src/test/java/io/trino/metadata/CountingAccessMetadata.java +++ /dev/null @@ -1,907 +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 com.google.common.collect.ConcurrentHashMultiset; -import com.google.common.collect.ImmutableMultiset; -import com.google.common.collect.Multiset; -import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.slice.Slice; -import io.trino.Session; -import io.trino.spi.connector.AggregateFunction; -import io.trino.spi.connector.AggregationApplicationResult; -import io.trino.spi.connector.BeginTableExecuteResult; -import io.trino.spi.connector.CatalogHandle; -import io.trino.spi.connector.CatalogSchemaName; -import io.trino.spi.connector.CatalogSchemaTableName; -import io.trino.spi.connector.ColumnHandle; -import io.trino.spi.connector.ColumnMetadata; -import io.trino.spi.connector.ConnectorCapabilities; -import io.trino.spi.connector.ConnectorOutputMetadata; -import io.trino.spi.connector.ConnectorTableMetadata; -import io.trino.spi.connector.Constraint; -import io.trino.spi.connector.ConstraintApplicationResult; -import io.trino.spi.connector.JoinApplicationResult; -import io.trino.spi.connector.JoinStatistics; -import io.trino.spi.connector.JoinType; -import io.trino.spi.connector.LimitApplicationResult; -import io.trino.spi.connector.MaterializedViewFreshness; -import io.trino.spi.connector.ProjectionApplicationResult; -import io.trino.spi.connector.RowChangeParadigm; -import io.trino.spi.connector.SampleApplicationResult; -import io.trino.spi.connector.SampleType; -import io.trino.spi.connector.SortItem; -import io.trino.spi.connector.SystemTable; -import io.trino.spi.connector.TableColumnsMetadata; -import io.trino.spi.connector.TableFunctionApplicationResult; -import io.trino.spi.connector.TableScanRedirectApplicationResult; -import io.trino.spi.connector.TopNApplicationResult; -import io.trino.spi.expression.ConnectorExpression; -import io.trino.spi.function.AggregationFunctionMetadata; -import io.trino.spi.function.FunctionMetadata; -import io.trino.spi.function.OperatorType; -import io.trino.spi.predicate.TupleDomain; -import io.trino.spi.security.GrantInfo; -import io.trino.spi.security.Identity; -import io.trino.spi.security.Privilege; -import io.trino.spi.security.RoleGrant; -import io.trino.spi.security.TrinoPrincipal; -import io.trino.spi.statistics.ComputedStatistics; -import io.trino.spi.statistics.TableStatistics; -import io.trino.spi.statistics.TableStatisticsMetadata; -import io.trino.spi.type.Type; -import io.trino.sql.analyzer.TypeSignatureProvider; -import io.trino.sql.planner.PartitioningHandle; -import io.trino.sql.tree.QualifiedName; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.OptionalInt; -import java.util.OptionalLong; -import java.util.Set; - -public class CountingAccessMetadata - implements Metadata -{ - public enum Method - { - GET_TABLE_STATISTICS, - } - - private final Metadata delegate; - private final ConcurrentHashMultiset methodInvocations = ConcurrentHashMultiset.create(); - - public CountingAccessMetadata(Metadata delegate) - { - this.delegate = delegate; - } - - public Multiset getMethodInvocations() - { - return ImmutableMultiset.copyOf(methodInvocations); - } - - public void resetCounters() - { - methodInvocations.clear(); - } - - @Override - public Set getConnectorCapabilities(Session session, CatalogHandle catalogHandle) - { - return delegate.getConnectorCapabilities(session, catalogHandle); - } - - @Override - public boolean catalogExists(Session session, String catalogName) - { - return delegate.catalogExists(session, catalogName); - } - - @Override - public boolean schemaExists(Session session, CatalogSchemaName schema) - { - return delegate.schemaExists(session, schema); - } - - @Override - public List listSchemaNames(Session session, String catalogName) - { - return delegate.listSchemaNames(session, catalogName); - } - - @Override - public Optional getTableHandle(Session session, QualifiedObjectName tableName) - { - return delegate.getTableHandle(session, tableName); - } - - @Override - public Optional getSystemTable(Session session, QualifiedObjectName tableName) - { - return delegate.getSystemTable(session, tableName); - } - - @Override - public Optional getTableHandleForExecute(Session session, TableHandle tableHandle, String procedureName, Map executeProperties) - { - return delegate.getTableHandleForExecute(session, tableHandle, procedureName, executeProperties); - } - - @Override - public Optional getLayoutForTableExecute(Session session, TableExecuteHandle tableExecuteHandle) - { - return delegate.getLayoutForTableExecute(session, tableExecuteHandle); - } - - @Override - public BeginTableExecuteResult beginTableExecute(Session session, TableExecuteHandle handle, TableHandle updatedSourceTableHandle) - { - return delegate.beginTableExecute(session, handle, updatedSourceTableHandle); - } - - @Override - public void finishTableExecute(Session session, TableExecuteHandle handle, Collection fragments, List tableExecuteState) - { - delegate.finishTableExecute(session, handle, fragments, tableExecuteState); - } - - @Override - public void executeTableExecute(Session session, TableExecuteHandle handle) - { - delegate.executeTableExecute(session, handle); - } - - @Override - public TableProperties getTableProperties(Session session, TableHandle handle) - { - return delegate.getTableProperties(session, handle); - } - - @Override - public TableHandle makeCompatiblePartitioning(Session session, TableHandle table, PartitioningHandle partitioningHandle) - { - return delegate.makeCompatiblePartitioning(session, table, partitioningHandle); - } - - @Override - public Optional getCommonPartitioning(Session session, PartitioningHandle left, PartitioningHandle right) - { - return delegate.getCommonPartitioning(session, left, right); - } - - @Override - public Optional getInfo(Session session, TableHandle handle) - { - return delegate.getInfo(session, handle); - } - - @Override - public CatalogSchemaTableName getTableName(Session session, TableHandle tableHandle) - { - return delegate.getTableName(session, tableHandle); - } - - @Override - public TableSchema getTableSchema(Session session, TableHandle tableHandle) - { - return delegate.getTableSchema(session, tableHandle); - } - - @Override - public TableMetadata getTableMetadata(Session session, TableHandle tableHandle) - { - return delegate.getTableMetadata(session, tableHandle); - } - - @Override - public TableStatistics getTableStatistics(Session session, TableHandle tableHandle) - { - methodInvocations.add(Method.GET_TABLE_STATISTICS); - return delegate.getTableStatistics(session, tableHandle); - } - - @Override - public List listTables(Session session, QualifiedTablePrefix prefix) - { - return delegate.listTables(session, prefix); - } - - @Override - public Map getColumnHandles(Session session, TableHandle tableHandle) - { - return delegate.getColumnHandles(session, tableHandle); - } - - @Override - public ColumnMetadata getColumnMetadata(Session session, TableHandle tableHandle, ColumnHandle columnHandle) - { - return delegate.getColumnMetadata(session, tableHandle, columnHandle); - } - - @Override - public List listTableColumns(Session session, QualifiedTablePrefix prefix) - { - return delegate.listTableColumns(session, prefix); - } - - @Override - public void createSchema(Session session, CatalogSchemaName schema, Map properties, TrinoPrincipal principal) - { - delegate.createSchema(session, schema, properties, principal); - } - - @Override - public void dropSchema(Session session, CatalogSchemaName schema, boolean cascade) - { - delegate.dropSchema(session, schema, cascade); - } - - @Override - public void renameSchema(Session session, CatalogSchemaName source, String target) - { - delegate.renameSchema(session, source, target); - } - - @Override - public void setSchemaAuthorization(Session session, CatalogSchemaName source, TrinoPrincipal principal) - { - delegate.setSchemaAuthorization(session, source, principal); - } - - @Override - public void createTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) - { - delegate.createTable(session, catalogName, tableMetadata, ignoreExisting); - } - - @Override - public void renameTable(Session session, TableHandle tableHandle, CatalogSchemaTableName currentTableName, QualifiedObjectName newTableName) - { - delegate.renameTable(session, tableHandle, currentTableName, newTableName); - } - - @Override - public void setTableProperties(Session session, TableHandle tableHandle, Map> properties) - { - delegate.setTableProperties(session, tableHandle, properties); - } - - @Override - public void setTableComment(Session session, TableHandle tableHandle, Optional comment) - { - delegate.setTableComment(session, tableHandle, comment); - } - - @Override - public void setViewComment(Session session, QualifiedObjectName viewName, Optional comment) - { - delegate.setViewComment(session, viewName, comment); - } - - @Override - public void setViewColumnComment(Session session, QualifiedObjectName viewName, String columnName, Optional comment) - { - delegate.setViewColumnComment(session, viewName, columnName, comment); - } - - @Override - public void setColumnComment(Session session, TableHandle tableHandle, ColumnHandle column, Optional comment) - { - delegate.setColumnComment(session, tableHandle, column, comment); - } - - @Override - public void setColumnType(Session session, TableHandle tableHandle, ColumnHandle column, Type type) - { - delegate.setColumnType(session, tableHandle, column, type); - } - - @Override - public void renameColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnHandle source, String target) - { - delegate.renameColumn(session, tableHandle, table, source, target); - } - - @Override - public void renameField(Session session, TableHandle tableHandle, List fieldPath, String target) - { - throw new UnsupportedOperationException(); - } - - @Override - public void addColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnMetadata column) - { - delegate.addColumn(session, tableHandle, table, column); - } - - @Override - public void addField(Session session, TableHandle tableHandle, List parentPath, String fieldName, Type type, boolean ignoreExisting) - { - throw new UnsupportedOperationException(); - } - - @Override - public void setTableAuthorization(Session session, CatalogSchemaTableName table, TrinoPrincipal principal) - { - delegate.setTableAuthorization(session, table, principal); - } - - @Override - public void dropColumn(Session session, TableHandle tableHandle, CatalogSchemaTableName table, ColumnHandle column) - { - delegate.dropColumn(session, tableHandle, table, column); - } - - @Override - public void dropField(Session session, TableHandle tableHandle, ColumnHandle column, List fieldPath) - { - delegate.dropField(session, tableHandle, column, fieldPath); - } - - @Override - public void dropTable(Session session, TableHandle tableHandle, CatalogSchemaTableName tableName) - { - delegate.dropTable(session, tableHandle, tableName); - } - - @Override - public void truncateTable(Session session, TableHandle tableHandle) - { - delegate.truncateTable(session, tableHandle); - } - - @Override - public Optional getNewTableLayout(Session session, String catalogName, ConnectorTableMetadata tableMetadata) - { - return delegate.getNewTableLayout(session, catalogName, tableMetadata); - } - - @Override - public OutputTableHandle beginCreateTable(Session session, String catalogName, ConnectorTableMetadata tableMetadata, Optional layout) - { - return delegate.beginCreateTable(session, catalogName, tableMetadata, layout); - } - - @Override - public Optional finishCreateTable(Session session, OutputTableHandle tableHandle, Collection fragments, Collection computedStatistics) - { - return delegate.finishCreateTable(session, tableHandle, fragments, computedStatistics); - } - - @Override - public Optional getInsertLayout(Session session, TableHandle target) - { - return delegate.getInsertLayout(session, target); - } - - @Override - public TableStatisticsMetadata getStatisticsCollectionMetadataForWrite(Session session, CatalogHandle catalogHandle, ConnectorTableMetadata tableMetadata) - { - return delegate.getStatisticsCollectionMetadataForWrite(session, catalogHandle, tableMetadata); - } - - @Override - public AnalyzeMetadata getStatisticsCollectionMetadata(Session session, TableHandle tableHandle, Map analyzeProperties) - { - return delegate.getStatisticsCollectionMetadata(session, tableHandle, analyzeProperties); - } - - @Override - public AnalyzeTableHandle beginStatisticsCollection(Session session, TableHandle tableHandle) - { - return delegate.beginStatisticsCollection(session, tableHandle); - } - - @Override - public void finishStatisticsCollection(Session session, AnalyzeTableHandle tableHandle, Collection computedStatistics) - { - delegate.finishStatisticsCollection(session, tableHandle, computedStatistics); - } - - @Override - public void cleanupQuery(Session session) - { - delegate.cleanupQuery(session); - } - - @Override - public InsertTableHandle beginInsert(Session session, TableHandle tableHandle, List columns) - { - return delegate.beginInsert(session, tableHandle, columns); - } - - @Override - public boolean supportsMissingColumnsOnInsert(Session session, TableHandle tableHandle) - { - return delegate.supportsMissingColumnsOnInsert(session, tableHandle); - } - - @Override - public Optional finishInsert(Session session, InsertTableHandle tableHandle, Collection fragments, Collection computedStatistics) - { - return delegate.finishInsert(session, tableHandle, fragments, computedStatistics); - } - - @Override - public boolean delegateMaterializedViewRefreshToConnector(Session session, QualifiedObjectName viewName) - { - return delegate.delegateMaterializedViewRefreshToConnector(session, viewName); - } - - @Override - public ListenableFuture refreshMaterializedView(Session session, QualifiedObjectName viewName) - { - return delegate.refreshMaterializedView(session, viewName); - } - - @Override - public InsertTableHandle beginRefreshMaterializedView(Session session, TableHandle tableHandle, List sourceTableHandles) - { - return delegate.beginRefreshMaterializedView(session, tableHandle, sourceTableHandles); - } - - @Override - public Optional finishRefreshMaterializedView(Session session, TableHandle tableHandle, InsertTableHandle insertTableHandle, Collection fragments, Collection computedStatistics, List sourceTableHandles) - { - return delegate.finishRefreshMaterializedView(session, tableHandle, insertTableHandle, fragments, computedStatistics, sourceTableHandles); - } - - @Override - public Optional applyDelete(Session session, TableHandle tableHandle) - { - return delegate.applyDelete(session, tableHandle); - } - - @Override - public OptionalLong executeDelete(Session session, TableHandle tableHandle) - { - return delegate.executeDelete(session, tableHandle); - } - - @Override - public RowChangeParadigm getRowChangeParadigm(Session session, TableHandle tableHandle) - { - return delegate.getRowChangeParadigm(session, tableHandle); - } - - @Override - public ColumnHandle getMergeRowIdColumnHandle(Session session, TableHandle tableHandle) - { - return delegate.getMergeRowIdColumnHandle(session, tableHandle); - } - - @Override - public Optional getUpdateLayout(Session session, TableHandle tableHandle) - { - return delegate.getUpdateLayout(session, tableHandle); - } - - @Override - public MergeHandle beginMerge(Session session, TableHandle tableHandle) - { - return delegate.beginMerge(session, tableHandle); - } - - @Override - public void finishMerge(Session session, MergeHandle tableHandle, Collection fragments, Collection computedStatistics) - { - delegate.finishMerge(session, tableHandle, fragments, computedStatistics); - } - - @Override - public Optional getCatalogHandle(Session session, String catalogName) - { - return delegate.getCatalogHandle(session, catalogName); - } - - @Override - public List listCatalogs(Session session) - { - return delegate.listCatalogs(session); - } - - @Override - public List listViews(Session session, QualifiedTablePrefix prefix) - { - return delegate.listViews(session, prefix); - } - - @Override - public Map getViews(Session session, QualifiedTablePrefix prefix) - { - return delegate.getViews(session, prefix); - } - - @Override - public boolean isView(Session session, QualifiedObjectName viewName) - { - return delegate.isView(session, viewName); - } - - @Override - public Optional getView(Session session, QualifiedObjectName viewName) - { - return delegate.getView(session, viewName); - } - - @Override - public Map getSchemaProperties(Session session, CatalogSchemaName schemaName) - { - return delegate.getSchemaProperties(session, schemaName); - } - - @Override - public Optional getSchemaOwner(Session session, CatalogSchemaName schemaName) - { - return delegate.getSchemaOwner(session, schemaName); - } - - @Override - public void createView(Session session, QualifiedObjectName viewName, ViewDefinition definition, boolean replace) - { - delegate.createView(session, viewName, definition, replace); - } - - @Override - public void renameView(Session session, QualifiedObjectName existingViewName, QualifiedObjectName newViewName) - { - delegate.renameView(session, existingViewName, newViewName); - } - - @Override - public void setViewAuthorization(Session session, CatalogSchemaTableName view, TrinoPrincipal principal) - { - delegate.setViewAuthorization(session, view, principal); - } - - @Override - public void dropView(Session session, QualifiedObjectName viewName) - { - delegate.dropView(session, viewName); - } - - @Override - public Optional resolveIndex(Session session, TableHandle tableHandle, Set indexableColumns, Set outputColumns, TupleDomain tupleDomain) - { - return delegate.resolveIndex(session, tableHandle, indexableColumns, outputColumns, tupleDomain); - } - - @Override - public Optional> applyLimit(Session session, TableHandle table, long limit) - { - return delegate.applyLimit(session, table, limit); - } - - @Override - public Optional> applyFilter(Session session, TableHandle table, Constraint constraint) - { - return delegate.applyFilter(session, table, constraint); - } - - @Override - public Optional> applyProjection(Session session, TableHandle table, List projections, Map assignments) - { - return delegate.applyProjection(session, table, projections, assignments); - } - - @Override - public Optional> applySample(Session session, TableHandle table, SampleType sampleType, double sampleRatio) - { - return delegate.applySample(session, table, sampleType, sampleRatio); - } - - @Override - public Optional> applyAggregation(Session session, TableHandle table, List aggregations, Map assignments, List> groupingSets) - { - return delegate.applyAggregation(session, table, aggregations, assignments, groupingSets); - } - - @Override - public Optional> applyJoin(Session session, JoinType joinType, TableHandle left, TableHandle right, ConnectorExpression joinCondition, Map leftAssignments, Map rightAssignments, JoinStatistics statistics) - { - return delegate.applyJoin(session, joinType, left, right, joinCondition, leftAssignments, rightAssignments, statistics); - } - - @Override - public Optional> applyTopN(Session session, TableHandle handle, long topNCount, List sortItems, Map assignments) - { - return delegate.applyTopN(session, handle, topNCount, sortItems, assignments); - } - - @Override - public Optional> applyTableFunction(Session session, TableFunctionHandle handle) - { - return delegate.applyTableFunction(session, handle); - } - - @Override - public void validateScan(Session session, TableHandle table) - { - delegate.validateScan(session, table); - } - - @Override - public boolean isCatalogManagedSecurity(Session session, String catalog) - { - return delegate.isCatalogManagedSecurity(session, catalog); - } - - @Override - public boolean roleExists(Session session, String role, Optional catalog) - { - return delegate.roleExists(session, role, catalog); - } - - @Override - public void createRole(Session session, String role, Optional grantor, Optional catalog) - { - delegate.createRole(session, role, grantor, catalog); - } - - @Override - public void dropRole(Session session, String role, Optional catalog) - { - delegate.dropRole(session, role, catalog); - } - - @Override - public Set listRoles(Session session, Optional catalog) - { - return delegate.listRoles(session, catalog); - } - - @Override - public Set listRoleGrants(Session session, Optional catalog, TrinoPrincipal principal) - { - return delegate.listRoleGrants(session, catalog, principal); - } - - @Override - public void grantRoles(Session session, Set roles, Set grantees, boolean adminOption, Optional grantor, Optional catalog) - { - delegate.grantRoles(session, roles, grantees, adminOption, grantor, catalog); - } - - @Override - public void revokeRoles(Session session, Set roles, Set grantees, boolean adminOption, Optional grantor, Optional catalog) - { - delegate.revokeRoles(session, roles, grantees, adminOption, grantor, catalog); - } - - @Override - public Set listApplicableRoles(Session session, TrinoPrincipal principal, Optional catalog) - { - return delegate.listApplicableRoles(session, principal, catalog); - } - - @Override - public Set listEnabledRoles(Identity identity) - { - return delegate.listEnabledRoles(identity); - } - - @Override - public Set listEnabledRoles(Session session, String catalog) - { - return delegate.listEnabledRoles(session, catalog); - } - - @Override - public void grantSchemaPrivileges(Session session, CatalogSchemaName schemaName, Set privileges, TrinoPrincipal grantee, boolean grantOption) - { - delegate.grantSchemaPrivileges(session, schemaName, privileges, grantee, grantOption); - } - - @Override - public void denySchemaPrivileges(Session session, CatalogSchemaName schemaName, Set privileges, TrinoPrincipal grantee) - { - delegate.denySchemaPrivileges(session, schemaName, privileges, grantee); - } - - @Override - public void revokeSchemaPrivileges(Session session, CatalogSchemaName schemaName, Set privileges, TrinoPrincipal grantee, boolean grantOption) - { - delegate.revokeSchemaPrivileges(session, schemaName, privileges, grantee, grantOption); - } - - @Override - public void grantTablePrivileges(Session session, QualifiedObjectName tableName, Set privileges, TrinoPrincipal grantee, boolean grantOption) - { - delegate.grantTablePrivileges(session, tableName, privileges, grantee, grantOption); - } - - @Override - public void denyTablePrivileges(Session session, QualifiedObjectName tableName, Set privileges, TrinoPrincipal grantee) - { - delegate.denyTablePrivileges(session, tableName, privileges, grantee); - } - - @Override - public void revokeTablePrivileges(Session session, QualifiedObjectName tableName, Set privileges, TrinoPrincipal grantee, boolean grantOption) - { - delegate.revokeTablePrivileges(session, tableName, privileges, grantee, grantOption); - } - - @Override - public List listTablePrivileges(Session session, QualifiedTablePrefix prefix) - { - return delegate.listTablePrivileges(session, prefix); - } - - @Override - public Collection listFunctions(Session session) - { - return delegate.listFunctions(session); - } - - @Override - public ResolvedFunction decodeFunction(QualifiedName name) - { - return delegate.decodeFunction(name); - } - - @Override - public ResolvedFunction resolveFunction(Session session, QualifiedName name, List parameterTypes) - { - return delegate.resolveFunction(session, name, parameterTypes); - } - - @Override - public ResolvedFunction resolveOperator(Session session, OperatorType operatorType, List argumentTypes) - throws OperatorNotFoundException - { - return delegate.resolveOperator(session, operatorType, argumentTypes); - } - - @Override - public ResolvedFunction getCoercion(Session session, Type fromType, Type toType) - { - return delegate.getCoercion(session, fromType, toType); - } - - @Override - public ResolvedFunction getCoercion(Session session, OperatorType operatorType, Type fromType, Type toType) - { - return delegate.getCoercion(session, operatorType, fromType, toType); - } - - @Override - public ResolvedFunction getCoercion(Session session, QualifiedName name, Type fromType, Type toType) - { - return delegate.getCoercion(session, name, fromType, toType); - } - - @Override - public boolean isAggregationFunction(Session session, QualifiedName name) - { - return delegate.isAggregationFunction(session, name); - } - - @Override - public boolean isWindowFunction(Session session, QualifiedName name) - { - return delegate.isWindowFunction(session, name); - } - - @Override - public FunctionMetadata getFunctionMetadata(Session session, ResolvedFunction resolvedFunction) - { - return delegate.getFunctionMetadata(session, resolvedFunction); - } - - @Override - public AggregationFunctionMetadata getAggregationFunctionMetadata(Session session, ResolvedFunction resolvedFunction) - { - return delegate.getAggregationFunctionMetadata(session, resolvedFunction); - } - - @Override - public void createMaterializedView(Session session, QualifiedObjectName viewName, MaterializedViewDefinition definition, boolean replace, boolean ignoreExisting) - { - delegate.createMaterializedView(session, viewName, definition, replace, ignoreExisting); - } - - @Override - public void dropMaterializedView(Session session, QualifiedObjectName viewName) - { - delegate.dropMaterializedView(session, viewName); - } - - @Override - public List listMaterializedViews(Session session, QualifiedTablePrefix prefix) - { - return delegate.listMaterializedViews(session, prefix); - } - - @Override - public Map getMaterializedViews(Session session, QualifiedTablePrefix prefix) - { - return delegate.getMaterializedViews(session, prefix); - } - - @Override - public boolean isMaterializedView(Session session, QualifiedObjectName viewName) - { - return delegate.isMaterializedView(session, viewName); - } - - @Override - public Optional getMaterializedView(Session session, QualifiedObjectName viewName) - { - return delegate.getMaterializedView(session, viewName); - } - - @Override - public MaterializedViewFreshness getMaterializedViewFreshness(Session session, QualifiedObjectName name) - { - return delegate.getMaterializedViewFreshness(session, name); - } - - @Override - public void renameMaterializedView(Session session, QualifiedObjectName existingViewName, QualifiedObjectName newViewName) - { - delegate.renameMaterializedView(session, existingViewName, newViewName); - } - - @Override - public void setMaterializedViewProperties(Session session, QualifiedObjectName viewName, Map> properties) - { - delegate.setMaterializedViewProperties(session, viewName, properties); - } - - @Override - public Optional applyTableScanRedirect(Session session, TableHandle tableHandle) - { - return delegate.applyTableScanRedirect(session, tableHandle); - } - - @Override - public RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session session, QualifiedObjectName tableName) - { - return delegate.getRedirectionAwareTableHandle(session, tableName); - } - - @Override - public RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session session, QualifiedObjectName tableName, Optional startVersion, Optional endVersion) - { - return delegate.getRedirectionAwareTableHandle(session, tableName, startVersion, endVersion); - } - - @Override - public boolean supportsReportingWrittenBytes(Session session, TableHandle tableHandle) - { - return false; - } - - @Override - public boolean supportsReportingWrittenBytes(Session session, QualifiedObjectName tableName, Map tableProperties) - { - return false; - } - - @Override - public Optional getTableHandle(Session session, QualifiedObjectName tableName, Optional startVersion, Optional endVersion) - { - return delegate.getTableHandle(session, tableName, startVersion, endVersion); - } - - @Override - public OptionalInt getMaxWriterTasks(Session session, String catalogName) - { - return delegate.getMaxWriterTasks(session, catalogName); - } -} diff --git a/plugin/trino-iceberg/pom.xml b/plugin/trino-iceberg/pom.xml index 7b7ba2474112..6d43f147fa10 100644 --- a/plugin/trino-iceberg/pom.xml +++ b/plugin/trino-iceberg/pom.xml @@ -400,6 +400,18 @@ + + io.opentelemetry + opentelemetry-sdk-testing + test + + + + io.opentelemetry + opentelemetry-sdk-trace + test + + io.trino trino-exchange-filesystem diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergGetTableStatisticsOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergGetTableStatisticsOperations.java index 522fbac5f565..08e56a4e8b3c 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergGetTableStatisticsOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergGetTableStatisticsOperations.java @@ -14,9 +14,11 @@ package io.trino.plugin.iceberg; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultiset; +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.trino.execution.warnings.WarningCollector; -import io.trino.metadata.CountingAccessMetadata; import io.trino.metadata.InternalFunctionBundle; import io.trino.metadata.MetadataManager; import io.trino.plugin.hive.metastore.Database; @@ -27,6 +29,7 @@ import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; +import io.trino.tracing.TracingMetadata; import org.intellij.lang.annotations.Language; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod; @@ -54,18 +57,23 @@ public class TestIcebergGetTableStatisticsOperations extends AbstractTestQueryFramework { private LocalQueryRunner localQueryRunner; - private CountingAccessMetadata metadata; + private InMemorySpanExporter spanExporter; private File metastoreDir; @Override protected QueryRunner createQueryRunner() throws Exception { + spanExporter = closeAfterClass(InMemorySpanExporter.create()); + + SdkTracerProvider tracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(SimpleSpanProcessor.create(spanExporter)) + .build(); + localQueryRunner = LocalQueryRunner.builder(testSessionBuilder().build()) .withMetadataProvider((systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager) - -> new CountingAccessMetadata(new MetadataManager(systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager))) + -> new TracingMetadata(tracerProvider.get("test"), new MetadataManager(systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager))) .build(); - metadata = (CountingAccessMetadata) localQueryRunner.getMetadata(); localQueryRunner.installPlugin(new TpchPlugin()); localQueryRunner.createCatalog("tpch", "tpch", ImmutableMap.of()); @@ -100,13 +108,13 @@ public void tearDown() deleteRecursively(metastoreDir.toPath(), ALLOW_INSECURE); localQueryRunner.close(); localQueryRunner = null; - metadata = null; + spanExporter = null; } @BeforeMethod public void resetCounters() { - metadata.resetCounters(); + spanExporter.reset(); } @Test @@ -115,10 +123,7 @@ public void testTwoWayJoin() planDistributedQuery("SELECT * " + "FROM iceberg.tiny.orders o, iceberg.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey"); - assertThat(metadata.getMethodInvocations()).containsExactlyInAnyOrderElementsOf( - ImmutableMultiset.builder() - .addCopies(CountingAccessMetadata.Method.GET_TABLE_STATISTICS, 2) - .build()); + assertThat(getTableStatisticsMethodInvocations()).isEqualTo(2); } @Test @@ -127,10 +132,7 @@ public void testThreeWayJoin() planDistributedQuery("SELECT * " + "FROM iceberg.tiny.customer c, iceberg.tiny.orders o, iceberg.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey AND c.custkey = o.custkey"); - assertThat(metadata.getMethodInvocations()).containsExactlyInAnyOrderElementsOf( - ImmutableMultiset.builder() - .addCopies(CountingAccessMetadata.Method.GET_TABLE_STATISTICS, 3) - .build()); + assertThat(getTableStatisticsMethodInvocations()).isEqualTo(3); } private void planDistributedQuery(@Language("SQL") String sql) @@ -140,4 +142,12 @@ private void planDistributedQuery(@Language("SQL") String sql) localQueryRunner.createPlan(session, sql, OPTIMIZED_AND_VALIDATED, false, WarningCollector.NOOP, createPlanOptimizersStatsCollector()); }); } + + private long getTableStatisticsMethodInvocations() + { + return spanExporter.getFinishedSpanItems().stream() + .map(SpanData::getName) + .filter(name -> name.equals("Metadata.getTableStatistics")) + .count(); + } } diff --git a/testing/trino-tests/pom.xml b/testing/trino-tests/pom.xml index 9e79348540b1..ac2ee048cafe 100644 --- a/testing/trino-tests/pom.xml +++ b/testing/trino-tests/pom.xml @@ -146,6 +146,18 @@ test + + io.opentelemetry + opentelemetry-sdk-testing + test + + + + io.opentelemetry + opentelemetry-sdk-trace + test + + io.trino trino-base-jdbc diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java b/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java index ef3362d8587a..f854548a2e55 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestGetTableStatisticsOperations.java @@ -14,14 +14,17 @@ package io.trino.tests; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultiset; +import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.trino.execution.warnings.WarningCollector; -import io.trino.metadata.CountingAccessMetadata; import io.trino.metadata.MetadataManager; import io.trino.plugin.tpch.TpchPlugin; import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.LocalQueryRunner; import io.trino.testing.QueryRunner; +import io.trino.tracing.TracingMetadata; import org.intellij.lang.annotations.Language; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod; @@ -38,17 +41,22 @@ public class TestGetTableStatisticsOperations extends AbstractTestQueryFramework { private LocalQueryRunner localQueryRunner; - private CountingAccessMetadata metadata; + private InMemorySpanExporter spanExporter; @Override protected QueryRunner createQueryRunner() throws Exception { + spanExporter = closeAfterClass(InMemorySpanExporter.create()); + + SdkTracerProvider tracerProvider = SdkTracerProvider.builder() + .addSpanProcessor(SimpleSpanProcessor.create(spanExporter)) + .build(); + localQueryRunner = LocalQueryRunner.builder(testSessionBuilder().build()) .withMetadataProvider((systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager) - -> new CountingAccessMetadata(new MetadataManager(systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager))) + -> new TracingMetadata(tracerProvider.get("test"), new MetadataManager(systemSecurityMetadata, transactionManager, globalFunctionCatalog, typeManager))) .build(); - metadata = (CountingAccessMetadata) localQueryRunner.getMetadata(); localQueryRunner.installPlugin(new TpchPlugin()); localQueryRunner.createCatalog("tpch", "tpch", ImmutableMap.of()); return localQueryRunner; @@ -59,13 +67,13 @@ public void tearDown() { localQueryRunner.close(); localQueryRunner = null; - metadata = null; + spanExporter = null; } @BeforeMethod public void resetCounters() { - metadata.resetCounters(); + spanExporter.reset(); } @Test @@ -74,10 +82,7 @@ public void testTwoWayJoin() planDistributedQuery("SELECT * " + "FROM tpch.tiny.orders o, tpch.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey"); - assertThat(metadata.getMethodInvocations()).containsExactlyInAnyOrderElementsOf( - ImmutableMultiset.builder() - .addCopies(CountingAccessMetadata.Method.GET_TABLE_STATISTICS, 2) - .build()); + assertThat(getTableStatisticsMethodInvocations()).isEqualTo(2); } @Test @@ -86,10 +91,7 @@ public void testThreeWayJoin() planDistributedQuery("SELECT * " + "FROM tpch.tiny.customer c, tpch.tiny.orders o, tpch.tiny.lineitem l " + "WHERE o.orderkey = l.orderkey AND c.custkey = o.custkey"); - assertThat(metadata.getMethodInvocations()).containsExactlyInAnyOrderElementsOf( - ImmutableMultiset.builder() - .addCopies(CountingAccessMetadata.Method.GET_TABLE_STATISTICS, 3) - .build()); + assertThat(getTableStatisticsMethodInvocations()).isEqualTo(3); } private void planDistributedQuery(@Language("SQL") String sql) @@ -99,4 +101,12 @@ private void planDistributedQuery(@Language("SQL") String sql) localQueryRunner.createPlan(session, sql, OPTIMIZED_AND_VALIDATED, false, WarningCollector.NOOP, createPlanOptimizersStatsCollector()); }); } + + private long getTableStatisticsMethodInvocations() + { + return spanExporter.getFinishedSpanItems().stream() + .map(SpanData::getName) + .filter(name -> name.equals("Metadata.getTableStatistics")) + .count(); + } }