Skip to content

Commit

Permalink
Fix expression fuzzer with PrestoQueryRunner (#11276)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #11276

Fix the set-up of Hive connector and Dwrf reader in
ExpressionFuzzerVerifier. Also fix the handling of unsupported
function signaure and constant literals in PrestoQueryRunner.

Reviewed By: kgpai

Differential Revision: D64484741

fbshipit-source-id: e70ae269d1e9b739d31349946dcaf9fe3e7d62c2
  • Loading branch information
kagamiori authored and facebook-github-bot committed Oct 21, 2024
1 parent 838b486 commit 9531f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions velox/exec/fuzzer/PrestoQueryRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,7 @@ std::optional<std::string> PrestoQueryRunner::toSql(
auto constant =
std::dynamic_pointer_cast<const core::ConstantTypedExpr>(
projection)) {
if (constant->type()->isPrimitiveType()) {
sql << toConstantSql(constant);
} else {
// TODO: support complex-typed constant literals.
VELOX_NYI();
}
sql << toConstantSql(constant);
} else {
VELOX_NYI();
}
Expand Down Expand Up @@ -434,9 +429,11 @@ bool PrestoQueryRunner::isConstantExprSupported(
// used as the type of constant literals in SQL, Presto implicitly invoke
// json_parse() on it, which makes the behavior of Presto different from
// Velox. Timestamp constant literals require further investigation to
// ensure Presto uses the same timezone as Velox.
// ensure Presto uses the same timezone as Velox. Interval type cannot be
// used as the type of constant literals in Presto SQL.
auto& type = expr->type();
return type->isPrimitiveType() && !type->isTimestamp() && !isJsonType(type);
return type->isPrimitiveType() && !type->isTimestamp() &&
!isJsonType(type) && !type->isIntervalDayTime();
}
return true;
}
Expand All @@ -447,11 +444,14 @@ bool PrestoQueryRunner::isSupported(const exec::FunctionSignature& signature) {
// cast-to or constant literals. Hyperloglog can only be casted from varbinary
// and cannot be used as the type of constant literals. Interval year to month
// can only be casted from NULL and cannot be used as the type of constant
// literals.
// literals. Json requires special handling, because Presto requires Json
// literals to be valid Json strings, and doesn't allow creation of Json-typed
// HIVE columns.
return !(
usesTypeName(signature, "interval year to month") ||
usesTypeName(signature, "hugeint") ||
usesTypeName(signature, "hyperloglog"));
usesTypeName(signature, "hyperloglog") ||
usesTypeName(signature, "json"));
}

std::optional<std::string> PrestoQueryRunner::toSql(
Expand Down
4 changes: 4 additions & 0 deletions velox/expression/fuzzer/ExpressionFuzzerVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "velox/common/base/Exceptions.h"
#include "velox/common/file/FileSystems.h"
#include "velox/connectors/hive/HiveConnector.h"
#include "velox/dwio/dwrf/RegisterDwrfWriter.h"
#include "velox/exec/fuzzer/FuzzerUtil.h"
#include "velox/expression/Expr.h"
#include "velox/expression/FunctionSignature.h"
Expand Down Expand Up @@ -109,7 +110,10 @@ ExpressionFuzzerVerifier::ExpressionFuzzerVerifier(
referenceQueryRunner_{
options_.expressionFuzzerOptions.referenceQueryRunner} {
filesystems::registerLocalFileSystem();
connector::registerConnectorFactory(
std::make_shared<connector::hive::HiveConnectorFactory>());
exec::test::registerHiveConnector({});
dwrf::registerDwrfWriterFactory();

seed(initialSeed);

Expand Down

0 comments on commit 9531f65

Please sign in to comment.