From bb273600fd93ebba0cc1782d168aafdb1d42c061 Mon Sep 17 00:00:00 2001 From: Kevin Wilfong Date: Tue, 17 Dec 2024 12:51:43 -0800 Subject: [PATCH] misc: Add support for row_constructor and dereference expressions in ToSqlUtil (#11883) Summary: Support for row_constructor and dereference expressions were never added to ToSqlUtil. This file is used by Fuzzer QueryRunners (particularly Presto) to generate SQL to execute. I'm guessing these features were never used. This is needed as part of enabling support for custom types not supported in DWRF files in Fuzzers comparing agains Presto. Differential Revision: D67310284 --- velox/exec/fuzzer/ToSQLUtil.cpp | 16 ++++++++++++++++ velox/exec/fuzzer/ToSQLUtil.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/velox/exec/fuzzer/ToSQLUtil.cpp b/velox/exec/fuzzer/ToSQLUtil.cpp index e2f601475836..18c8bfecf625 100644 --- a/velox/exec/fuzzer/ToSQLUtil.cpp +++ b/velox/exec/fuzzer/ToSQLUtil.cpp @@ -107,6 +107,11 @@ void toCallInputsSql( auto concatArg = std::dynamic_pointer_cast(input)) { sql << toConcatSql(concatArg); + } else if ( + auto dereferenceArg = + std::dynamic_pointer_cast( + input)) { + sql << toDereferenceSql(dereferenceArg); } else { VELOX_NYI("Unsupported input expression: {}.", input->toString()); } @@ -196,6 +201,10 @@ std::string toCallSql(const core::CallTypedExprPtr& call) { toCallInputsSql({inputs[1]}, sql); sql << " and "; toCallInputsSql({inputs[2]}, sql); + } else if (call->name() == "row_constructor") { + sql << "row("; + toCallInputsSql(call->inputs(), sql); + sql << ")"; } else { // Regular function call syntax. sql << call->name() << "("; @@ -226,6 +235,13 @@ std::string toConcatSql(const core::ConcatTypedExprPtr& concat) { return sql.str(); } +std::string toDereferenceSql(const core::DereferenceTypedExprPtr& dereference) { + std::stringstream sql; + toCallInputsSql(dereference->inputs(), sql); + sql << "." << dereference->name(); + return sql.str(); +} + // Constant expressions of complex types, timestamp with timezone, interval, and // decimal types are not supported yet. std::string toConstantSql(const core::ConstantTypedExprPtr& constant) { diff --git a/velox/exec/fuzzer/ToSQLUtil.h b/velox/exec/fuzzer/ToSQLUtil.h index a8b20bcb47c9..b22a726be389 100644 --- a/velox/exec/fuzzer/ToSQLUtil.h +++ b/velox/exec/fuzzer/ToSQLUtil.h @@ -41,6 +41,9 @@ std::string toCastSql(const core::CastTypedExprPtr& cast); /// Convert a concat expression into a SQL string. std::string toConcatSql(const core::ConcatTypedExprPtr& concat); +/// Convert a dereference expression into a SQL string. +std::string toDereferenceSql(const core::DereferenceTypedExprPtr& dereference); + /// Convert a constant expression into a SQL string. std::string toConstantSql(const core::ConstantTypedExprPtr& constant);