diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeGeneralQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeGeneralQueries.java index ab19165a21e47..8c3734642deae 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeGeneralQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeGeneralQueries.java @@ -190,6 +190,44 @@ public void testFiltersAndProjections() assertQuery("SELECT if(orderkey % 2 = 0, quantity_by_linenumber) FROM orders_ex"); } + @Test + public void testAnalyzeStats() + { + assertQuery("ANALYZE region"); + // presto:tpch> show stats for region; + // column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value + // -------------+-----------+-----------------------+----------------+-----------+-----------+------------ + // regionkey | NULL | 5.0 | 0.0 | NULL | 0 | 4 + // name | 34.0 | 5.0 | 0.0 | NULL | NULL | NULL + // comment | 330.0 | 5.0 | 0.0 | NULL | NULL | NULL + // NULL | NULL | NULL | NULL | 5.0 | NULL | NULL + // (4 rows) + assertQuery("SHOW STATS FOR region"); + // Create a partitioned table and run analyze on it. + String tmpTableName = generateRandomTableName(); + try { + getQueryRunner().execute(getSession(), String.format("CREATE TABLE %s (name VARCHAR, regionkey BIGINT," + + "nationkey BIGINT) WITH (partitioned_by = ARRAY['regionkey','nationkey'])", tmpTableName)); + Session writeSession = buildSessionForTableWrite(); + getQueryRunner().execute(writeSession, + String.format("INSERT INTO %s SELECT name, regionkey, nationkey FROM nation", tmpTableName)); + assertQuery(String.format("SELECT * FROM %s", tmpTableName), + "SELECT name, regionkey, nationkey FROM nation"); + assertQuery("ANALYZE %s WITH (partitions = ARRAY[ARRAY['0','0'],ARRAY['4', '11']])", tmpTableName); + // column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value + //-------------+-----------+-----------------------+----------------+-----------+-----------+------------ + // name | 137.5 | 1.0 | 0.0 | NULL | NULL | NULL + // regionkey | NULL | 5.0 | 0.0 | NULL | 0 | 4 + // nationkey | NULL | 25.0 | 0.0 | NULL | 0 | 24 + // NULL | NULL | NULL | NULL | 25.0 | NULL | NULL + // (4 rows) + assertQuery("SHOW STATS for %s", tmpTableName); + } + finally { + dropTableIfExists(tmpTableName); + } + } + @Test public void testDateFilter() {