diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index b98b4b4005..3f81c5da8a 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -9052,21 +9052,28 @@ public AggrStats get_aggr_stats_for(String catName, String dbName, String tblNam return null; } - MTable table = getMTable(catName, dbName, tblName); + Table table = getTable(catName, dbName, tblName); boolean isTxn = TxnUtils.isTransactionalTable(table.getParameters()); if (isTxn && !areTxnStatsSupported) { return null; } + GetPartitionsFilterSpec fs = new GetPartitionsFilterSpec(); + fs.setFilterMode(PartitionFilterMode.BY_NAMES); + fs.setFilters(partNames); + GetPartitionsProjectionSpec ps = new GetPartitionsProjectionSpec(); + ps.setIncludeParamKeyPattern(StatsSetupConst.COLUMN_STATS_ACCURATE + '%'); + ps.setFieldList(Lists.newArrayList("writeId", "parameters", "values")); + List parts = getPartitionSpecsByFilterAndProjection(table, ps, fs); + // List parts = getPartitionsByNames(catName, dbName, tblName, partNames); // Loop through the given "partNames" list // checking isolation-level-compliance of each partition column stats. - for (String partName : partNames) { - MPartition mpart = getMPartition( - catName, dbName, tblName, Warehouse.getPartValuesFromPartName(partName)); - if (!isCurrentStatsValidForTheQuery(mpart, writeIdList, false)) { - LOG.debug("The current metastore transactional partition column statistics " + - "for " + dbName + "." + tblName + "." + mpart.getPartitionName() + " is not valid " + - "for the current query."); + for (Partition part : parts) { + + if (!isCurrentStatsValidForTheQuery(part, part.getWriteId(), writeIdList, false)) { + String partName = Warehouse.makePartName(table.getPartitionKeys(), part.getValues()); + LOG.debug("The current metastore transactional partition column statistics for " + dbName + + "." + tblName + "." + partName + " is not valid for the current query"); return null; } } diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionProjectionEvaluator.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionProjectionEvaluator.java index e918a3335f..c3a0093322 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionProjectionEvaluator.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/PartitionProjectionEvaluator.java @@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; + import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.Partition; @@ -38,6 +39,7 @@ import javax.jdo.PersistenceManager; import javax.jdo.Query; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -369,8 +371,8 @@ private PartitionFieldNode createIfNotExists(Map nes int numColumns = buildQueryForSingleValuedFields(partitionIds, queryTextBuilder); String queryText = queryTextBuilder.toString(); - try (Query query = pm.newQuery("javax.jdo.query.SQL", queryText)) { - + Query query = pm.newQuery("javax.jdo.query.SQL", queryText); + try { long start = LOG.isDebugEnabled() ? System.nanoTime() : 0; List sqlResult = MetastoreDirectSqlUtils.executeWithArray(query, null, queryText); long queryTime = LOG.isDebugEnabled() ? System.nanoTime() : 0; @@ -456,6 +458,8 @@ public void setValue(Object partition, PartitionFieldNode node, Object value) } catch (Exception e) { LOG.error("Exception received while getting partitions using projected fields", e); throw new MetaException(e.getMessage()); + } finally { + query.closeAll(); } }