From b99b181f1e069e3117488db371cc06d92837fd4e Mon Sep 17 00:00:00 2001 From: Alex Jo Date: Wed, 3 Aug 2022 17:53:43 -0400 Subject: [PATCH] Use the HiveTableHandle enforced constraint when loading stats --- .../src/main/java/io/trino/plugin/hive/HiveMetadata.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 92099b09e581..598f9c538054 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 @@ -785,19 +785,20 @@ public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTab if (!isStatisticsEnabled(session)) { return TableStatistics.empty(); } + HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle; Map columns = getColumnHandles(session, tableHandle) .entrySet().stream() .filter(entry -> !((HiveColumnHandle) entry.getValue()).isHidden()) .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); Map columnTypes = columns.entrySet().stream() .collect(toImmutableMap(Map.Entry::getKey, entry -> getColumnMetadata(session, tableHandle, entry.getValue()).getType())); - HivePartitionResult partitionResult = partitionManager.getPartitions(metastore, tableHandle, Constraint.alwaysTrue()); + HivePartitionResult partitionResult = partitionManager.getPartitions(metastore, tableHandle, new Constraint(hiveTableHandle.getEnforcedConstraint())); // If partitions are not loaded, then don't generate table statistics. // Note that the computation is not persisted in the table handle, so can be redone many times // TODO: https://github.com/trinodb/trino/issues/10980. if (partitionManager.canPartitionsBeLoaded(partitionResult)) { List partitions = partitionManager.getPartitionsAsList(partitionResult); - return hiveStatisticsProvider.getTableStatistics(session, ((HiveTableHandle) tableHandle).getSchemaTableName(), columns, columnTypes, partitions); + return hiveStatisticsProvider.getTableStatistics(session, hiveTableHandle.getSchemaTableName(), columns, columnTypes, partitions); } return TableStatistics.empty(); }