diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java index 001156a913..2dd62e35b6 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/RelOptHiveTable.java @@ -515,10 +515,11 @@ private void updateColStats(Set projIndxLst, boolean allowMissingStats) computePartitionList(hiveConf, null, new HashSet()); } - ColumnStatsList colStatsCached = colStatsCache.get(partitionList.getKey()); + String partitionListKey = partitionList.getKey().orElse(null); + ColumnStatsList colStatsCached = colStatsCache.get(partitionListKey); if (colStatsCached == null) { colStatsCached = new ColumnStatsList(); - colStatsCache.put(partitionList.getKey(), colStatsCached); + colStatsCache.put(partitionListKey, colStatsCached); } // 2. Obtain Col Stats for Non Partition Cols @@ -749,7 +750,7 @@ public int hashCode() { } public String getPartitionListKey() { - return partitionList != null ? partitionList.getKey() : null; + return partitionList != null ? partitionList.getKey().orElse(null) : null; } } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java index 673d8580d5..709b2219c2 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ppr/PartitionPruner.java @@ -20,6 +20,7 @@ import java.util.AbstractSequentialList; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -207,7 +208,7 @@ public static PrunedPartitionList prune(Table tab, ExprNodeDesc prunerExpr, if (compactExpr == null || isBooleanExpr(compactExpr)) { if (isFalseExpr(compactExpr)) { return new PrunedPartitionList(tab, key + compactExpr.getExprString(true), - new LinkedHashSet(0), new ArrayList(0), false); + Collections.emptySet(), Collections.emptyList(), false); } // For null and true values, return every partition return getAllPartsFromCacheOrServer(tab, key, true, prunedPartitionsMap); @@ -242,7 +243,7 @@ private static PrunedPartitionList getAllPartsFromCacheOrServer(Table tab, Strin } catch (HiveException e) { throw new SemanticException(e); } - ppList = new PrunedPartitionList(tab, key, parts, null, unknownPartitions); + ppList = new PrunedPartitionList(tab, key, parts, Collections.emptyList(), unknownPartitions); if (partsCache != null) { partsCache.put(key, ppList); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseContext.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseContext.java index 91bdbfd67d..dc570e8e8c 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseContext.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ParseContext.java @@ -444,7 +444,7 @@ public void setOpToSamplePruner( * @return col stats */ public ColumnStatsList getColStatsCached(PrunedPartitionList partList) { - return ctx.getOpContext().getColStatsCache().get(partList.getKey()); + return ctx.getOpContext().getColStatsCache().get(partList.getKey().orElse(null)); } /** diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/PrunedPartitionList.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/PrunedPartitionList.java index 406873528c..398dbf555d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/PrunedPartitionList.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/PrunedPartitionList.java @@ -19,7 +19,10 @@ package org.apache.hadoop.hive.ql.parse; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import org.apache.hadoop.hive.ql.metadata.Partition; @@ -30,36 +33,32 @@ */ public class PrunedPartitionList { - /** Key to identify this partition list. */ - private final String ppListKey; - /** Source table. */ private final Table source; + /** Key to identify this partition list. */ + private final Optional ppListKey; + /** Partitions that either satisfy the partition criteria, or may satisfy it. */ - private Set partitions; + private final Set partitions; /** partition columns referred by pruner expr */ - private List referred; + private final List referred; /** Whether there are partitions in the list that may or may not satisfy the criteria. */ - private boolean hasUnknowns; + private final boolean hasUnknowns; public PrunedPartitionList(Table source, Set partitions, List referred, boolean hasUnknowns) { - this.source = source; - this.ppListKey = null; - this.referred = referred; - this.partitions = partitions; - this.hasUnknowns = hasUnknowns; + this(source, null, partitions, referred, hasUnknowns); } public PrunedPartitionList(Table source, String key, Set partitions, List referred, boolean hasUnknowns) { - this.source = source; - this.ppListKey = key; - this.referred = referred; - this.partitions = partitions; + this.source = Objects.requireNonNull(source); + this.ppListKey = Optional.ofNullable(key); + this.referred = Objects.requireNonNull(referred); + this.partitions = Objects.requireNonNull(partitions); this.hasUnknowns = hasUnknowns; } @@ -67,7 +66,7 @@ public Table getSourceTable() { return source; } - public String getKey() { + public Optional getKey() { return ppListKey; } @@ -75,7 +74,7 @@ public String getKey() { * @return partitions */ public Set getPartitions() { - return partitions; + return Collections.unmodifiableSet(partitions); } @@ -83,7 +82,7 @@ public String getKey() { * @return all partitions. */ public List getNotDeniedPartns() { - return new ArrayList(partitions); + return Collections.unmodifiableList(new ArrayList<>(partitions)); } /** @@ -94,6 +93,6 @@ public boolean hasUnknownPartitions() { } public List getReferredPartCols() { - return referred; + return Collections.unmodifiableList(referred); } }