Skip to content

HIVE-28902: Fix unknown column PARTITION_NAME in aggrStatsUseDB #5768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ private List<ColumnStatisticsObj> aggrStatsUseDB(String catName, String dbName,
// Extrapolation is not needed.
if (areAllPartsFound) {
queryText = commonPrefix + " and \"COLUMN_NAME\" in (" + makeParams(colNames.size()) + ")"
+ " and \"PARTITION_NAME\" in (" + makeParams(partNames.size()) + ")"
+ " and " + PARTITIONS + ".\"PART_NAME\" in (" + makeParams(partNames.size()) + ")"
+ " and \"ENGINE\" = ? "
+ " group by \"COLUMN_NAME\", \"COLUMN_TYPE\"";
start = doTrace ? System.nanoTime() : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData;
import org.apache.hadoop.hive.metastore.api.AddPackageRequest;
import org.apache.hadoop.hive.metastore.api.AggrStats;
import org.apache.hadoop.hive.metastore.api.DropPackageRequest;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Function;
Expand Down Expand Up @@ -943,6 +944,31 @@ public void testPartitionStatisticsOps() throws Exception {
Assert.assertEquals(0, stat.size());
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified this test case would expectedly fail without the patch.

MetaException(message:See previous errors; Error executing SQL query "select "COLUMN_NAME", "COLUMN_TYPE", min("LONG_LOW_VALUE"), max("LONG_HIGH_VALUE"), min("DOUBLE_LOW_VALUE"), max("DOUBLE_HIGH_VALUE"), min(cast("BIG_DECIMAL_LOW_VALUE" as decimal)), max(cast("BIG_DECIMAL_HIGH_VALUE" as decimal)), sum("NUM_NULLS"), max("NUM_DISTINCTS"), max("AVG_COL_LEN"), max("MAX_COL_LEN"), sum("NUM_TRUES"), sum("NUM_FALSES"), avg(("LONG_HIGH_VALUE"-"LONG_LOW_VALUE")/cast("NUM_DISTINCTS" as decimal)),avg(("DOUBLE_HIGH_VALUE"-"DOUBLE_LOW_VALUE")/"NUM_DISTINCTS"),avg((cast("BIG_DECIMAL_HIGH_VALUE" as decimal)-cast("BIG_DECIMAL_LOW_VALUE" as decimal))/"NUM_DISTINCTS"),sum("NUM_DISTINCTS") from "PART_COL_STATS" inner join "PARTITIONS" on "PART_COL_STATS"."PART_ID" = "PARTITIONS"."PART_ID" inner join "TBLS" on "PARTITIONS"."TBL_ID" = "TBLS"."TBL_ID" inner join "DBS" on "TBLS"."DB_ID" = "DBS"."DB_ID" where "DBS"."CTLG_NAME" = ? and "DBS"."NAME" = ? and "TBLS"."TBL_NAME" = ?  and "COLUMN_NAME" in (?) and "PARTITION_NAME" in (?,?,?) and "ENGINE" = ?  group by "COLUMN_NAME", "COLUMN_TYPE"".Failed to execute [select "COLUMN_NAME", "COLUMN_TYPE", min("LONG_LOW_VALUE"), max("LONG_HIGH_VALUE"), min("DOUBLE_LOW_VALUE"), max("DOUBLE_HIGH_VALUE"), min(cast("BIG_DECIMAL_LOW_VALUE" as decimal)), max(cast("BIG_DECIMAL_HIGH_VALUE" as decimal)), sum("NUM_NULLS"), max("NUM_DISTINCTS"), max("AVG_COL_LEN"), max("MAX_COL_LEN"), sum("NUM_TRUES"), sum("NUM_FALSES"), avg(("LONG_HIGH_VALUE"-"LONG_LOW_VALUE")/cast("NUM_DISTINCTS" as decimal)),avg(("DOUBLE_HIGH_VALUE"-"DOUBLE_LOW_VALUE")/"NUM_DISTINCTS"),avg((cast("BIG_DECIMAL_HIGH_VALUE" as decimal)-cast("BIG_DECIMAL_LOW_VALUE" as decimal))/"NUM_DISTINCTS"),sum("NUM_DISTINCTS") from "PART_COL_STATS" inner join "PARTITIONS" on "PART_COL_STATS"."PART_ID" = "PARTITIONS"."PART_ID" inner join "TBLS" on "PARTITIONS"."TBL_ID" = "TBLS"."TBL_ID" inner join "DBS" on "TBLS"."DB_ID" = "DBS"."DB_ID" where "DBS"."CTLG_NAME" = ? and "DBS"."NAME" = ? and "TBLS"."TBL_NAME" = ?  and "COLUMN_NAME" in (?) and "PARTITION_NAME" in (?,?,?) and "ENGINE" = ?  group by "COLUMN_NAME", "COLUMN_TYPE"] with parameters [hive, testobjectstoredb1, testobjectstoretable1, test_part_col, test_part_col=a0, test_part_col=a1, test_part_col=a2, hive]
)
	at org.apache.hadoop.hive.metastore.MetastoreDirectSqlUtils.executeWithArray(MetastoreDirectSqlUtils.java:81)
	at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.executeWithArray(MetaStoreDirectSql.java:2417)
	at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.executeWithArray(MetaStoreDirectSql.java:2412)
	at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.aggrStatsUseDB(MetaStoreDirectSql.java:2002)
	at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.columnStatisticsObjForPartitionsBatch(MetaStoreDirectSql.java:1939)
	at org.apache.hadoop.hive.metastore.MetaStoreDirectSql.access$1800(MetaStoreDirectSql.java:134)

public void testAggrStatsUseDB() throws Exception {
Configuration conf2 = MetastoreConf.newMetastoreConf(conf);
MetastoreConf.setBoolVar(conf2, ConfVars.STATS_FETCH_BITVECTOR, false);
MetastoreConf.setBoolVar(conf2, ConfVars.STATS_FETCH_KLL, false);
objectStore.setConf(conf2);

createPartitionedTable(true, true);

AggrStats aggrStats;
try (AutoCloseable c = deadline()) {
aggrStats = objectStore.get_aggr_stats_for(DEFAULT_CATALOG_NAME, DB1, TABLE1,
Arrays.asList("test_part_col=a0", "test_part_col=a1", "test_part_col=a2"),
Collections.singletonList("test_part_col"), ENGINE);
}
List<ColumnStatisticsObj> stats = aggrStats.getColStats();
Assert.assertEquals(1, stats.size());
Assert.assertEquals(3, aggrStats.getPartsFound());

ColumnStatisticsData computedStats = aggrStats.getColStats().get(0).getStatsData();
ColumnStatisticsData expectedStats = new ColStatsBuilder<>(long.class).numNulls(3).numDVs(2)
.low(3L).high(4L).build();
assertEqualStatistics(expectedStats, computedStats);
}

/**
* Creates DB1 database, TABLE1 table with 3 partitions.
* @param withPrivileges Should we create privileges as well
Expand Down
Loading