Skip to content

Commit

Permalink
misc: Add support for row_constructor and dereference expressions in …
Browse files Browse the repository at this point in the history
…ToSqlUtil (facebookincubator#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
  • Loading branch information
Kevin Wilfong authored and facebook-github-bot committed Dec 17, 2024
1 parent e46cb76 commit 5911773
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions velox/exec/fuzzer/ToSQLUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ void toCallInputsSql(
auto concatArg =
std::dynamic_pointer_cast<const core::ConcatTypedExpr>(input)) {
sql << toConcatSql(concatArg);
} else if (
auto dereferenceArg =
std::dynamic_pointer_cast<const core::DereferenceTypedExpr>(
input)) {
sql << toDereferenceSql(dereferenceArg);
} else {
VELOX_NYI("Unsupported input expression: {}.", input->toString());
}
Expand Down Expand Up @@ -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() << "(";
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions velox/exec/fuzzer/ToSQLUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5911773

Please sign in to comment.