Skip to content

Commit

Permalink
feat: add support for varchar literals
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsilonPrime committed Jan 27, 2025
1 parent bada330 commit 8485a39
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/from_substrait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ Value TransformLiteralToValue(const substrait::Expression_Literal &literal) {
interval.micros = literal.interval_day_to_second().microseconds();

Check warning on line 167 in src/from_substrait.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

'microseconds' is deprecated [-Wdeprecated-declarations]
return Value::INTERVAL(interval);
}
case substrait::Expression_Literal::LiteralTypeCase::kVarChar:
return {literal.var_char().value()};
default:
throw InternalException(to_string(literal.literal_type_case()));
throw SyntaxException("literals of this type number are not implemented: " + to_string(literal.literal_type_case()));
}
}

Expand Down
101 changes: 101 additions & 0 deletions test/c/test_substrait_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,107 @@ TEST_CASE("Test C VirtualTable input Expression", "[substrait-api]") {
REQUIRE(CHECK_COLUMN(result, 1, {4, 8}));
}

TEST_CASE_METHOD(DataDirectoryFixture, "Test C Function Varchar Literal", "[substrait-api][literal]") {
DuckDB db(nullptr);
Connection con(db);

REQUIRE_NO_FAIL(con.Query("INSTALL iceberg;"));
REQUIRE_NO_FAIL(con.Query("LOAD iceberg;"));

const string plan_json = R"plan(
{
"version": {
"minorNumber": 53,
"producer": "substrait-go v3.5.0 darwin/arm64"
},
"extensionUris": [
{
"extensionUriAnchor": 1,
"uri": "https://github.com/substrait-io/substrait/blob/main/extensions/functions_comparison.yaml"
}
],
"extensions": [
{
"extensionFunction": {
"extensionUriReference": 1,
"functionAnchor": 1,
"name": "equal"
}
}
],
"relations": [
{
"root": {
"input": {
"project": {
"input": {
"read": {
"common": {
"direct": {}
},
"virtualTable": {
"values": [
{
"fields": [
{
"i32": 42
}
]
}
]
}
}
},
"expressions": [
{
"scalarFunction": {
"functionReference": 1,
"arguments": [
{
"value": {
"literal": {
"varChar": {
"value": "a",
"length": 1
}
}
}
},
{
"value": {
"literal": {
"varChar": {
"value": " a",
"length": 2
}
}
}
}
],
"outputType": {
"bool": {
"nullability": "NULLABILITY_REQUIRED"
}
}
}
}
]
}
},
"names": [
"result"
]
}
}
]
}
)plan";

auto result = con.FromSubstraitJSON(plan_json);

REQUIRE(CHECK_COLUMN(result, 0, {false}));
}

TEST_CASE_METHOD(DataDirectoryFixture, "Test C Iceberg Substrait with Substrait API", "[substrait-api][iceberg]") {
DuckDB db(nullptr);
Connection con(db);
Expand Down

0 comments on commit 8485a39

Please sign in to comment.