Support Substrait Round-Trip of EmptyRelation Including produce_one_row Semantics
#18842
+157
−48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
This change resolves a long‑standing gap in DataFusion’s Substrait round‑trip implementation where
EmptyRelationwithproduce_one_row=truecould not be encoded or decoded. This limitation caused ~1800 sqllogictest cases to fail, particularly those involving queries without a FROM clause (e.g.,SELECT 1).By adding full support for recognizing and producing the Substrait VirtualTable pattern representing a “phantom row,” DataFusion can now faithfully round‑trip logical plans that use empty relations to provide scalar evaluation contexts. This unblocks broader Substrait compatibility and improves consistency across logical plan conversions.
What changes are included in this PR?
Implement detection of the Substrait VirtualTable patterns representing
produce_one_rowand map them toLogicalPlan::EmptyRelation.Add
from_empty_relationencoding logic that emits a properly structured VirtualTable, including default literal values whenproduce_one_row=true.Refactor literal row conversion into a helper (
convert_literal_rows) for clarity and reuse.Improve field‑count validation for expression‑based VirtualTables.
Add comprehensive round‑trip test coverage:
Are these changes tested?
Yes. New integration tests exercise all permutations of EmptyRelation encoding and decoding, including edge cases related to schema handling and subqueries. These tests ensure round‑trip correctness and prevent regressions.
Are there any user-facing changes?
No user‑facing API changes. This PR improves Substrait interoperability internally.
LLM-generated code disclosure
This PR includes LLM‑generated code and comments. All generated content has been manually reviewed and tested.