diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java index eaa423967fbb..db6cb8640eb4 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java @@ -1585,6 +1585,8 @@ public ConnectorTableHandle beginStatisticsCollection(ConnectorSession session, @Override public void finishStatisticsCollection(ConnectorSession session, ConnectorTableHandle tableHandle, Collection computedStatistics) { + verify(isStatisticsEnabled(session), "statistics not enabled"); + HiveTableHandle handle = (HiveTableHandle) tableHandle; SchemaTableName tableName = handle.getSchemaTableName(); Table table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName()) @@ -3453,6 +3455,9 @@ public TableStatisticsMetadata getStatisticsCollectionMetadataForWrite(Connector if (!isCollectColumnStatisticsOnWrite(session)) { return TableStatisticsMetadata.empty(); } + if (!isStatisticsEnabled(session)) { + throw new TrinoException(NOT_SUPPORTED, "Table statistics must be enabled when column statistics collection on write is enabled"); + } if (isTransactional(tableMetadata.getProperties()).orElse(false)) { // TODO(https://github.com/trinodb/trino/issues/1956) updating table statistics for transactional not supported right now. return TableStatisticsMetadata.empty(); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProvider.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProvider.java deleted file mode 100644 index a0b4024fcb3a..000000000000 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProvider.java +++ /dev/null @@ -1,69 +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.plugin.hive.metastore.glue; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import io.trino.plugin.hive.HiveColumnStatisticType; -import io.trino.plugin.hive.metastore.HiveColumnStatistics; -import io.trino.plugin.hive.metastore.Partition; -import io.trino.plugin.hive.metastore.Table; -import io.trino.spi.TrinoException; -import io.trino.spi.type.Type; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -import static com.google.common.collect.ImmutableMap.toImmutableMap; -import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED; -import static java.util.function.UnaryOperator.identity; - -public class DisabledGlueColumnStatisticsProvider - implements GlueColumnStatisticsProvider -{ - @Override - public Set getSupportedColumnStatistics(Type type) - { - return ImmutableSet.of(); - } - - @Override - public Map getTableColumnStatistics(Table table) - { - return ImmutableMap.of(); - } - - @Override - public Map> getPartitionColumnStatistics(Collection partitions) - { - return partitions.stream().collect(toImmutableMap(identity(), partition -> ImmutableMap.of())); - } - - @Override - public void updateTableColumnStatistics(Table table, Map columnStatistics) - { - if (!columnStatistics.isEmpty()) { - throw new TrinoException(NOT_SUPPORTED, "Glue metastore column level statistics are disabled"); - } - } - - @Override - public void updatePartitionStatistics(Set partitionStatisticsUpdates) - { - if (partitionStatisticsUpdates.stream().anyMatch(update -> !update.getColumnStatistics().isEmpty())) { - throw new TrinoException(NOT_SUPPORTED, "Glue metastore column level statistics are disabled"); - } - } -} diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProviderFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProviderFactory.java deleted file mode 100644 index 6a06aa5bc33f..000000000000 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/DisabledGlueColumnStatisticsProviderFactory.java +++ /dev/null @@ -1,26 +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.plugin.hive.metastore.glue; - -import com.amazonaws.services.glue.AWSGlueAsync; - -public class DisabledGlueColumnStatisticsProviderFactory - implements GlueColumnStatisticsProviderFactory -{ - @Override - public GlueColumnStatisticsProvider createGlueColumnStatisticsProvider(AWSGlueAsync glueClient, GlueMetastoreStats stats) - { - return new DisabledGlueColumnStatisticsProvider(); - } -} diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueMetastoreModule.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueMetastoreModule.java index 75b0e59a1687..751973e8f0a2 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueMetastoreModule.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueMetastoreModule.java @@ -19,7 +19,6 @@ import com.amazonaws.services.glue.model.Table; import com.google.inject.Binder; import com.google.inject.Key; -import com.google.inject.Module; import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.Singleton; @@ -42,7 +41,6 @@ import static com.google.inject.multibindings.Multibinder.newSetBinder; import static com.google.inject.multibindings.OptionalBinder.newOptionalBinder; import static io.airlift.concurrent.Threads.daemonThreadsNamed; -import static io.airlift.configuration.ConditionalModule.conditionalModule; import static io.airlift.configuration.ConfigBinder.configBinder; import static java.util.concurrent.Executors.newCachedThreadPool; import static org.weakref.jmx.guice.ExportBinder.newExporter; @@ -78,19 +76,8 @@ protected void setup(Binder binder) binder.bind(Key.get(boolean.class, AllowHiveTableRename.class)).toInstance(false); - install(conditionalModule( - HiveConfig.class, - HiveConfig::isTableStatisticsEnabled, - getGlueStatisticsModule(DefaultGlueColumnStatisticsProviderFactory.class), - getGlueStatisticsModule(DisabledGlueColumnStatisticsProviderFactory.class))); - } - - private Module getGlueStatisticsModule(Class statisticsProviderFactoryClass) - { - return internalBinder -> newOptionalBinder(internalBinder, GlueColumnStatisticsProviderFactory.class) - .setDefault() - .to(statisticsProviderFactoryClass) - .in(Scopes.SINGLETON); + newOptionalBinder(binder, GlueColumnStatisticsProviderFactory.class) + .setDefault().to(DefaultGlueColumnStatisticsProviderFactory.class).in(Scopes.SINGLETON); } @ProvidesIntoSet diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/statistics/MetastoreHiveStatisticsProvider.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/statistics/MetastoreHiveStatisticsProvider.java index 860eb4162c8d..3d79eed2a4d8 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/statistics/MetastoreHiveStatisticsProvider.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/statistics/MetastoreHiveStatisticsProvider.java @@ -29,6 +29,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static io.trino.plugin.hive.HivePartition.UNPARTITIONED_ID; +import static io.trino.plugin.hive.HiveSessionProperties.isStatisticsEnabled; import static java.util.Objects.requireNonNull; public class MetastoreHiveStatisticsProvider @@ -44,6 +45,9 @@ public MetastoreHiveStatisticsProvider(SemiTransactionalHiveMetastore metastore) @Override protected Map getPartitionsStatistics(ConnectorSession session, SchemaTableName table, List hivePartitions, Set columns) { + if (!isStatisticsEnabled(session)) { + return ImmutableMap.of(); + } if (hivePartitions.isEmpty()) { return ImmutableMap.of(); }