Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: Add support for row_constructor and dereference expressions in ToSqlUtil #11883

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading