Skip to content

Commit

Permalink
Add support for custom types to DuckParser
Browse files Browse the repository at this point in the history
Summary: Enable parsing of expressions like "cast x as json".

Reviewed By: bikramSingh91

Differential Revision: D56544676

fbshipit-source-id: 74f3406bbef4c47d9c0f65ef75d53ebc1ebee66c
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Apr 25, 2024
1 parent 4e075a0 commit b1c993b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions velox/duckdb/conversion/DuckConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ TypePtr toVeloxType(LogicalType type, bool fileColumnNamesReadAsLowerCase) {
}
return ROW(std::move(names), std::move(types));
}
case LogicalTypeId::USER: {
const auto name = ::duckdb::UserType::GetTypeName(type);
if (auto customType = getCustomType(name)) {
return customType;
}
[[fallthrough]];
}
default:
throw std::runtime_error(
"unsupported type for duckdb -> velox conversion: " +
Expand Down
7 changes: 7 additions & 0 deletions velox/duckdb/conversion/tests/DuckParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "velox/duckdb/conversion/DuckParser.h"
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/core/PlanNode.h"
#include "velox/functions/prestosql/types/JsonType.h"
#include "velox/parse/Expressions.h"

using namespace facebook::velox;
Expand Down Expand Up @@ -367,6 +368,12 @@ TEST(DuckParserTest, cast) {
parseExpr("cast(c0 as struct(a bigint, b real, c varchar))")->toString());
}

TEST(DuckParserTest, castToJson) {
registerJsonType();
EXPECT_EQ("cast(\"c0\", JSON)", parseExpr("cast(c0 as json)")->toString());
EXPECT_EQ("cast(\"c0\", JSON)", parseExpr("cast(c0 as JSON)")->toString());
}

TEST(DuckParserTest, ifCase) {
EXPECT_EQ("if(99,1,0)", parseExpr("if(99, 1, 0)")->toString());
EXPECT_EQ(
Expand Down

0 comments on commit b1c993b

Please sign in to comment.