Skip to content

Commit

Permalink
Avoid writing to Hive an empty list of column stats because Hive 2.x …
Browse files Browse the repository at this point in the history
…fails
  • Loading branch information
guyco33 authored and findepi committed Aug 9, 2022
1 parent 5c1da02 commit 760615f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ private void setColumnStatistics(String objectName, List<ColumnStatisticsObj> st
verify(!dateStatistics.isEmpty() && metastoreSupportsDateStatistics.equals(Optional.empty()));

try (ThriftMetastoreClient client = createMetastoreClient()) {
saveColumnStatistics.call(client, statisticsExceptDate);
if (!statisticsExceptDate.isEmpty()) {
saveColumnStatistics.call(client, statisticsExceptDate);
}

try {
saveColumnStatistics.call(client, dateStatistics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,30 @@ public Object[][] testComputeFloatingPointStatisticsDataProvider()
};
}

@Test
public void testComputeStatisticsForTableWithOnlyDateColumns()
{
String tableName = "test_compute_statistics_with_only_date_columns";
onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName);
try {
onTrino().executeQuery(format("CREATE TABLE %s AS SELECT date'2019-12-02' c_date", tableName));

List<Row> expectedStatistics = ImmutableList.of(
isHiveVersionBefore12()
? row("c_date", null, null, null, null, null, null)
: row("c_date", null, 1.0, 0.0, null, "2019-12-02", "2019-12-02"),
row(null, null, null, null, 1.0, null, null));

assertThat(onTrino().executeQuery("SHOW STATS FOR " + tableName)).containsOnly(expectedStatistics);

onTrino().executeQuery("ANALYZE " + tableName);
assertThat(onTrino().executeQuery("SHOW STATS FOR " + tableName)).containsOnly(expectedStatistics);
}
finally {
onTrino().executeQuery("DROP TABLE IF EXISTS " + tableName);
}
}

@Test
@Flaky(issue = ERROR_COMMITTING_WRITE_TO_HIVE_ISSUE, match = ERROR_COMMITTING_WRITE_TO_HIVE_MATCH)
public void testMixedHiveAndPrestoStatistics()
Expand Down

0 comments on commit 760615f

Please sign in to comment.