Skip to content

feat: parse JsonAccess as a binary operator, add Operator::Colon#20628

Open
Samyak2 wants to merge 1 commit intoapache:mainfrom
Samyak2:json-access-support
Open

feat: parse JsonAccess as a binary operator, add Operator::Colon#20628
Samyak2 wants to merge 1 commit intoapache:mainfrom
Samyak2:json-access-support

Conversation

@Samyak2
Copy link
Contributor

@Samyak2 Samyak2 commented Mar 1, 2026

Which issue does this PR close?

Needed in datafusion-contrib/datafusion-variant#26

Rationale for this change

  • sqlparser-rs currently exposes the colon operator (:) as a special JsonAccess expression. So it fails in datafusion's parsing before an ExprPlanner is even invoked.
  • Add Operator::Colon. Currently it's not used/implemented in datafusion.

What changes are included in this PR?

  • Fixes the above problem by converting JsonAccess to a normal binary expr, on which the ExprPlanner is invoked and custom parsing can be done.

Are these changes tested?

Added tests.

Also did a prototype of a custom ExprPlanner in datafusion-variant using this to convert colon operator to variant_get function - datafusion-contrib/datafusion-variant#31

Are there any user-facing changes?

Add Operator::Colon

Alternatives considered

I have arrived at this solution iteratively to solve datafusion-contrib/datafusion-variant#26. Some alternatives I considered (but NOT IMPLEMENTED):

  • Add a new Expr::JsonAccess instead of re-using BinaryExpr. Alongside this, we could also introduce datafusion's version of a JsonPath struct. Expr::JsonAccess could also contain the optional cast that usually comes after it (like in col_a:field_b::int). The cast might be needed for performance optimizations. This is a much bigger change, so I have not done it.

If this makes sense to do at this time, please let me know and I will do those changes.

@github-actions github-actions bot added the sql SQL Planner label Mar 1, 2026
@Samyak2 Samyak2 force-pushed the json-access-support branch from dba0816 to cc55a52 Compare March 1, 2026 11:15
@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates substrait Changes to the substrait crate labels Mar 1, 2026
- Needed in datafusion-contrib/datafusion-variant#26
- `sqlparser-rs` currently exposes the colon operator (`:`) as a
  special `JsonAccess` expression. So it fails in datafusion's parsing
  before an `ExprPlanner` is even invoked.
- Fix it by converting `JsonAccess` to a normal binary expr, on which
  the `ExprPlanner` is invoked and custom parsing can be done.

I have arrived at this solution iteratively to solve
datafusion-contrib/datafusion-variant#26.
Some alternatives I considered (but NOT IMPLEMENTED):
- Add a new `Expr::JsonAccess` instead of re-using `BinaryExpr`.
  Alongside this, we could also introduce datafusion's version of
  a `JsonPath` struct. `Expr::JsonAccess` could also contain the
  optional cast that usually comes after it (like in
  `col_a:field_b::int`). The cast might be needed for performance
  optimizations. This is a much bigger change, so I have not done it.
@Samyak2 Samyak2 force-pushed the json-access-support branch from cc55a52 to da2c0b8 Compare March 1, 2026 11:29
@Samyak2 Samyak2 changed the title feat: parse JsonAccess as a custom binary operator feat: parse JsonAccess as a binary operator Mar 1, 2026
@Samyak2 Samyak2 marked this pull request as ready for review March 1, 2026 11:38
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Samyak2

@alamb alamb added the api change Changes the API exposed to users of the crate label Mar 1, 2026
@alamb alamb changed the title feat: parse JsonAccess as a binary operator feat: parse JsonAccess as a binary operator, add Operator::Colon Mar 1, 2026
@alamb
Copy link
Contributor

alamb commented Mar 1, 2026

This PR introduces a breaking public API change (adding Opeartor::Colon) so marking the PR as API change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates sql SQL Planner substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants