Skip to content

Commit

Permalink
Add parseIntegerAsBigint option to DuckParser (facebookincubator#4074)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebookincubator#4074

Reviewed By: xiaoxmeng

Differential Revision: D43416285

Pulled By: mbasmanova

fbshipit-source-id: 94129bccbbd59e0756dedc6d7bfeb7f3ce373589
  • Loading branch information
ViggoC authored and facebook-github-bot committed Feb 18, 2023
1 parent f064e6e commit 7915dea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion velox/duckdb/conversion/DuckParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ std::shared_ptr<const core::IExpr> parseConstantExpr(
// This is a hack to make DuckDB more compatible with the old Koski-based
// parser. By default literal integer constants in DuckDB parser are INTEGER,
// while in Koski parser they were BIGINT.
if (value.type().id() == LogicalTypeId::INTEGER) {
if (value.type().id() == LogicalTypeId::INTEGER &&
options.parseIntegerAsBigint) {
value = Value::BIGINT(value.GetValue<int32_t>());
}

Expand Down
1 change: 1 addition & 0 deletions velox/duckdb/conversion/DuckParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace facebook::velox::duckdb {
struct ParseOptions {
// Retain legacy behavior by default.
bool parseDecimalAsDouble = true;
bool parseIntegerAsBigint = true;
};

// Parses an input expression using DuckDB's internal postgresql-based parser,
Expand Down
12 changes: 12 additions & 0 deletions velox/duckdb/conversion/tests/DuckParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ TEST(DuckParserTest, parseDecimalConstant) {
}
}

TEST(DuckParserTest, parseInteger) {
ParseOptions options;
options.parseIntegerAsBigint = false;
auto expr = parseExpr("1234", options);
if (auto constant =
std::dynamic_pointer_cast<const core::ConstantExpr>(expr)) {
ASSERT_EQ(*constant->type(), *INTEGER());
} else {
FAIL() << expr->toString() << " is not a constant";
}
}

TEST(DuckParserTest, lambda) {
// There is a bug in DuckDB in parsing lambda expressions that use
// comparisons. This doesn't work: filter(a, x -> x = 10). This does:
Expand Down
3 changes: 3 additions & 0 deletions velox/parse/ExpressionsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ std::shared_ptr<const core::IExpr> parseExpr(
const ParseOptions& options) {
facebook::velox::duckdb::ParseOptions duckConversionOptions;
duckConversionOptions.parseDecimalAsDouble = options.parseDecimalAsDouble;
duckConversionOptions.parseIntegerAsBigint = options.parseIntegerAsBigint;

return facebook::velox::duckdb::parseExpr(expr, duckConversionOptions);
}

Expand All @@ -31,6 +33,7 @@ std::vector<std::shared_ptr<const core::IExpr>> parseMultipleExpressions(
const ParseOptions& options) {
facebook::velox::duckdb::ParseOptions duckConversionOptions;
duckConversionOptions.parseDecimalAsDouble = options.parseDecimalAsDouble;
duckConversionOptions.parseIntegerAsBigint = options.parseIntegerAsBigint;
return facebook::velox::duckdb::parseMultipleExpressions(
expr, duckConversionOptions);
}
Expand Down
1 change: 1 addition & 0 deletions velox/parse/ExpressionsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace facebook::velox::parse {
struct ParseOptions {
// Retain legacy behavior by default.
bool parseDecimalAsDouble = true;
bool parseIntegerAsBigint = true;
};

std::shared_ptr<const core::IExpr> parseExpr(
Expand Down

0 comments on commit 7915dea

Please sign in to comment.