Skip to content

feat: support Placeholder <-> DynamicParameter in Substrait producer/consumer#20977

Open
bvolpato wants to merge 1 commit intoapache:mainfrom
bvolpato:bv/substrait-placeholder-dynamic-parameter
Open

feat: support Placeholder <-> DynamicParameter in Substrait producer/consumer#20977
bvolpato wants to merge 1 commit intoapache:mainfrom
bvolpato:bv/substrait-placeholder-dynamic-parameter

Conversation

@bvolpato
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

The Substrait producer previously returned not_impl_err! for Expr::Placeholder, meaning any query plan containing parameterized expressions (e.g. $1, $2) could not be serialized to Substrait. This gap prevented roundtripping prepared statement plans through the Substrait layer.

What changes are included in this PR?

Producer:

  • New placeholder.rs module with from_placeholder that converts Expr::Placeholder to DynamicParameter, mapping one-based $N DataFusion ids to zero-based Substrait parameter_reference values with optional type information.
  • handle_placeholder added to the SubstraitProducer trait.

Consumer:

  • consume_dynamic_parameter converts Substrait DynamicParameter back to Expr::Placeholder, reversing the index mapping and type conversion.

Are these changes tested?

Yes. Five new integration tests and one unit test:

  • roundtrip_placeholder_sql_filter — SQL-based, WHERE a > $1
  • roundtrip_placeholder_sql_projection — SQL-based, $1 in SELECT + $2 in WHERE
  • roundtrip_placeholder_typed_int64 — typed Int64 placeholder with proto-level DynamicParameter verification
  • roundtrip_placeholder_multiple_typed — two typed placeholders (Int64 + Decimal128)
  • roundtrip_placeholder_typed_utf8 — Utf8 typed placeholder
  • test_parse_placeholder_index — unit test for index parsing edge cases

All 190 integration tests, 28 unit tests, and 3 doc-tests pass. Clippy and fmt are clean.

Are there any user-facing changes?

Query plans containing Placeholder expressions can now be serialized to and deserialized from Substrait format. Previously this would return an error.

…consumer

Add support for converting DataFusion's Expr::Placeholder to Substrait's
DynamicParameter and back. This enables roundtripping query plans that
contain parameterized expressions (e.g. $1, $2) through the Substrait
serialization layer.

Producer: new from_placeholder function maps one-based $N placeholder ids
to zero-based Substrait parameter_reference values with optional type info.

Consumer: consume_dynamic_parameter converts back from Substrait
DynamicParameter to DataFusion Placeholder expressions.

Tests cover SQL-based roundtrips (untyped placeholders in filter and
projection), typed placeholders (Int64, Utf8, Decimal128), multiple
placeholders, and Substrait proto-level DynamicParameter verification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[substrait] Add Placeholder ↔ DynamicParameter support in producer and consumer

1 participant