diff --git a/presto-native-execution/presto_cpp/main/types/VeloxToPrestoExpr.cpp b/presto-native-execution/presto_cpp/main/types/VeloxToPrestoExpr.cpp index 91e1c309d8a7e..fba82342384e8 100644 --- a/presto-native-execution/presto_cpp/main/types/VeloxToPrestoExpr.cpp +++ b/presto-native-execution/presto_cpp/main/types/VeloxToPrestoExpr.cpp @@ -319,7 +319,7 @@ SpecialFormExpressionPtr VeloxToPrestoExprConverter::getDereferenceExpression( const auto dereferenceInputs = std::vector{ dereferenceExpr->inputs().at(0), std::make_shared( - velox::BIGINT(), static_cast(dereferenceExpr->index()))}; + velox::INTEGER(), static_cast(dereferenceExpr->index()))}; for (const auto& input : dereferenceInputs) { const auto rowExpr = getRowExpression(input); protocol::to_json(j, rowExpr); diff --git a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java index 20fedd32722de..1c0b1b253c79a 100644 --- a/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java +++ b/presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java @@ -689,6 +689,20 @@ public void testNativeExpressionOptimizer() assertQuerySucceeds(session, "SELECT table_name, COALESCE(abs(ordinal_position), 0) as abs_pos FROM information_schema.columns WHERE table_catalog = 'hive' AND table_name IN ('nation', 'region') ORDER BY table_name, ordinal_position"); assertQuerySucceeds(session, "SELECT table_name, ordinal_position FROM information_schema.columns WHERE abs(ordinal_position) IN (1, 2, 3) AND table_catalog = 'hive' AND table_name != 'roles' ORDER BY table_name, ordinal_position"); assertQuerySucceeds(session, "select lower(table_name) from information_schema.tables where table_name = 'lineitem' or table_name = 'LINEITEM'"); + + // Test dereference expression. + assertQuerySucceeds(session, + "select cast(row(row(row(random(10), if(random(10) >= 0, 2)), random(10)), random(100)) AS row(x row(y row(a int, b int), c int), d int))[1][1][2]"); + assertQuerySucceeds(session, + "select cast(row(row(row(random(10), if(random(10) < 0, 2)), random(10)), random(100)) AS row(x row(y row(a int, b int), c int), d int))[1][2]"); + assertQuerySucceeds(session, + "select cast(row(row(null, random(10)), random(100)) AS row(x row(y row(a int, b int), c int), d int))[1][1][1]"); + assertQuerySucceeds(session, + "select cast(row(row(null, if(random(100) >= 0, 4)), random(10)) AS row(x row(y row(a int, b int), c int), d int))[2]"); + + // Test dereference expression with SQL invoked function, array_least_frequent. + assertQuerySucceeds(session, "SELECT array_least_frequent(array_agg(orderkey)) from orders"); + assertQuerySucceeds(session, "SELECT array_least_frequent(array_agg(nationkey)) from nation"); } @Test