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 b10e7b07b1..e5e475e192 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 @@ -401,7 +401,7 @@ public void computePartitionList(HiveConf conf, RexNode pruneNode, Set } } - private void updateColStats(Set projIndxLst, boolean allowNullColumnForMissingStats) { + private void updateColStats(Set projIndxLst, boolean allowMissingStats) { List nonPartColNamesThatRqrStats = new ArrayList(); List nonPartColIndxsThatRqrStats = new ArrayList(); List partColNamesThatRqrStats = new ArrayList(); @@ -574,7 +574,7 @@ private void updateColStats(Set projIndxLst, boolean allowNullColumnFor String logMsg = "No Stats for " + hiveTblMetadata.getCompleteName() + ", Columns: " + getColNamesForLogging(colNamesFailedStats); noColsMissingStats.getAndAdd(colNamesFailedStats.size()); - if (allowNullColumnForMissingStats) { + if (allowMissingStats) { LOG.warn(logMsg); HiveConf conf = SessionState.getSessionConf(); if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CBO_SHOW_WARNINGS)) { @@ -589,10 +589,13 @@ private void updateColStats(Set projIndxLst, boolean allowNullColumnFor } public List getColStat(List projIndxLst) { - return getColStat(projIndxLst, false); + // If we allow estimated stats for the columns, then we shall set the boolean to true, + // since otherwise we will throw an exception because columns with estimated stats are + // actually added to the list of columns that do not contain stats. + return getColStat(projIndxLst, HiveConf.getBoolVar(hiveConf, HiveConf.ConfVars.HIVE_STATS_ESTIMATE_STATS)); } - public List getColStat(List projIndxLst, boolean allowNullColumnForMissingStats) { + public List getColStat(List projIndxLst, boolean allowMissingStats) { List colStatsBldr = Lists.newArrayList(); Set projIndxSet = new HashSet(projIndxLst); if (projIndxLst != null) { @@ -603,7 +606,7 @@ private void updateColStats(Set projIndxLst, boolean allowNullColumnFor } } if (!projIndxSet.isEmpty()) { - updateColStats(projIndxSet, allowNullColumnForMissingStats); + updateColStats(projIndxSet, allowMissingStats); for (Integer i : projIndxSet) { colStatsBldr.add(hiveColStatsMap.get(i)); } @@ -616,7 +619,7 @@ private void updateColStats(Set projIndxLst, boolean allowNullColumnFor } } if (!pILst.isEmpty()) { - updateColStats(new HashSet(pILst), allowNullColumnForMissingStats); + updateColStats(new HashSet(pILst), allowMissingStats); for (Integer pi : pILst) { colStatsBldr.add(hiveColStatsMap.get(pi)); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveReduceExpressionsWithStatsRule.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveReduceExpressionsWithStatsRule.java index 1edef98ea9..7d426bd978 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveReduceExpressionsWithStatsRule.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveReduceExpressionsWithStatsRule.java @@ -295,7 +295,7 @@ private ColStatistics extractColStats(RexInputRef ref) { RelOptHiveTable table = (RelOptHiveTable) columnOrigin.getOriginTable(); if (table != null) { ColStatistics colStats = - table.getColStat(Lists.newArrayList(columnOrigin.getOriginColumnOrdinal())).get(0); + table.getColStat(Lists.newArrayList(columnOrigin.getOriginColumnOrdinal()), false).get(0); if (colStats != null && StatsSetupConst.areColumnStatsUptoDate( table.getHiveTableMD().getParameters(), colStats.getColumnName())) { return colStats; diff --git a/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveReduceExpressionsWithStatsRule.java b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveReduceExpressionsWithStatsRule.java index a0ce7a04fc..146aa81a9c 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveReduceExpressionsWithStatsRule.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/rules/TestHiveReduceExpressionsWithStatsRule.java @@ -86,7 +86,7 @@ public void before() { Mockito.doReturn(rowTypeMock).when(tableMock).getRowType(); Mockito.doReturn(tableMock).when(schemaMock).getTableForMember(Matchers.any()); statObj = new ColStatistics("_int", "int"); - Mockito.doReturn(Lists.newArrayList(statObj)).when(tableMock).getColStat(Matchers.anyListOf(Integer.class)); + Mockito.doReturn(Lists.newArrayList(statObj)).when(tableMock).getColStat(Matchers.anyListOf(Integer.class), false); Mockito.doReturn(hiveTableMDMock).when(tableMock).getHiveTableMD(); Mockito.doReturn(tableParams).when(hiveTableMDMock).getParameters();