Skip to content

Commit 4dcd319

Browse files
authored
fix zero column virtual_table handling to check expressions also (#155)
1 parent c7615b2 commit 4dcd319

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/from_substrait.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,13 @@ SubstraitToDuckDB::TransformProjectOp(const substrait::Rel &sop,
575575
size_t num_input_columns = 0;
576576
if (sop.project().input().rel_type_case() == substrait::Rel::RelTypeCase::kRead) {
577577
auto &sget = sop.project().input().read();
578-
if (sget.has_virtual_table() && sget.virtual_table().values().empty()) {
579-
hasZeroColumnVirtualTable = true;
580-
input_rel = GetValueRelationWithSingleBoolColumn();
578+
if (sget.has_virtual_table()) {
579+
auto virtual_table = sget.virtual_table();
580+
if ((virtual_table.values().empty() && virtual_table.expressions().empty()) ||
581+
(virtual_table.expressions().size() > 0 && virtual_table.expressions(0).fields().empty())) {
582+
hasZeroColumnVirtualTable = true;
583+
input_rel = GetValueRelationWithSingleBoolColumn();
584+
}
581585
}
582586
}
583587
if (!hasZeroColumnVirtualTable) {

test/c/test_substrait_c_api.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,13 @@ TEST_CASE("Test C VirtualTable with bad input Literal", "[substrait-api]") {
658658

659659
auto json_plan = R"({"version":{"minorNumber":29, "producer":"substrait-go"}, "relations":[{"root":{"input":{"project":{"common":{"direct":{}}, "input":{"read":{"common":{"direct":{}}, "baseSchema":{"struct":{"nullability":"NULLABILITY_REQUIRED"}}, "virtualTable":{"expressions":[{}]}}}, "expressions":[{"literal":{"decimal":{"value":"AQ==", "precision":1}, "nullable":true}}]}}, "names":["?column?"]}}]})";
660660
REQUIRE_THROWS(FromSubstraitJSON(con,json_plan));
661+
}
662+
663+
TEST_CASE("Test C Project with VirtualTable", "[substrait-api]") {
664+
DuckDB db(nullptr);
665+
Connection con(db);
666+
667+
auto json_plan = R"({"version":{"minorNumber":29, "producer":"substrait-go darwin/arm64"}, "relations":[{"root":{"input":{"project":{"common":{"emit":{"outputMapping":[2]}}, "input":{"read":{"common":{"direct":{}}, "baseSchema":{"names":["c1", "c2"], "struct":{"types":[{"fp64":{"nullability":"NULLABILITY_NULLABLE"}}, {"fp64":{"nullability":"NULLABILITY_NULLABLE"}}], "nullability":"NULLABILITY_REQUIRED"}}, "virtualTable":{"expressions":[{"fields":[{"literal":{"fp64":1, "nullable":true}}, {"literal":{"fp64":2, "nullable":true}}]}]}}}, "expressions":[{"literal":{"fp64":42}}]}}, "names":["p1"]}}]})";
668+
auto result = FromSubstraitJSON(con,json_plan);
669+
REQUIRE(CHECK_COLUMN(result, 0, {42}));
661670
}

0 commit comments

Comments
 (0)