diff --git a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp index f883d21c287e3..6e08614f240cf 100644 --- a/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp +++ b/presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp @@ -67,7 +67,18 @@ std::string mapScalarFunction(const std::string& name) { } std::string mapAggregateOrWindowFunction(const std::string& name) { - return boost::to_lower_copy(name); + static const std::unordered_map kFunctionNames = { + {"presto.default.$internal$max_data_size_for_stats", + "presto.default.max_data_size_for_stats"}, + {"presto.default.$internal$sum_data_size_for_stats", + "presto.default.sum_data_size_for_stats"}, + }; + std::string lowerCaseName = boost::to_lower_copy(name); + auto it = kFunctionNames.find(name); + if (it != kFunctionNames.end()) { + return it->second; + } + return lowerCaseName; } std::string getFunctionName(const protocol::Signature& signature) { 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 48f4bf1f54c8b..c914e40c87fc3 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() + { + assertUpdate("ANALYZE region", 5); + + // Show stats returns the following stats for each column in region table: + // column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value + assertQuery("SHOW STATS FOR region", + "SELECT * FROM (VALUES" + + "('regionkey', NULL, 5.0, 0.0, NULL, '0', '4')," + + "('name', 54.0, 5.0, 0.0, NULL, NULL, NULL)," + + "('comment', 350.0, 5.0, 0.0, NULL, NULL, NULL)," + + "(NULL, NULL, NULL, NULL, 5.0, NULL, NULL))"); + + // Create a partitioned table and run analyze on it. + String tmpTableName = generateRandomTableName(); + try { + Session writeSession = buildSessionForTableWrite(); + getQueryRunner().execute(writeSession, String.format("CREATE TABLE %s (name VARCHAR, regionkey BIGINT," + + "nationkey BIGINT) WITH (partitioned_by = ARRAY['regionkey','nationkey'])", tmpTableName)); + 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"); + assertUpdate(String.format("ANALYZE %s", tmpTableName), 25); + assertQuery(String.format("SHOW STATS for %s", tmpTableName), + "SELECT * FROM (VALUES" + + "('name', 277.0, 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))"); + // @TODO Add test for Analyze on table partitions. Refer: https://github.com/prestodb/presto/issues/20232 + } + finally { + dropTableIfExists(tmpTableName); + } + } + @Test public void testDateFilter() { diff --git a/presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeGeneralQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeGeneralQueries.java index 10621645341ec..0a9985e34806b 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeGeneralQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeGeneralQueries.java @@ -69,4 +69,9 @@ public void testTopN() {} @Override @Ignore public void testInsertIntoSpecialPartitionName(){} + + // @TODO Refer https://github.com/prestodb/presto/issues/20294 + @Override + @Ignore + public void testAnalyzeStats() {} }