Skip to content

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

Merged
alamb merged 1 commit intoapache:mainfrom
Samyak2:json-access-support
Mar 4, 2026
Merged

feat: parse JsonAccess as a binary operator, add Operator::Colon#20628
alamb merged 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

Copy link
Contributor

@sdf-jkl sdf-jkl left a comment

Choose a reason for hiding this comment

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

I'm not very familiar with this part of the codebase, but I’ve reviewed it and everything LGTM.

@alamb alamb added this pull request to the merge queue Mar 4, 2026
Merged via the queue into apache:main with commit 5d27860 Mar 4, 2026
38 checks passed
@alamb
Copy link
Contributor

alamb commented Mar 4, 2026

Thanks @Samyak2 and @sdf-jkl -- note this will be released as part of DataFusion 54

If we want it in datafusion-53 we'll have to backport it soon to branch-53

Samyak2 added a commit to Samyak2/datafusion that referenced this pull request Mar 5, 2026
…tor::Colon` (apache#20628)

Backport of apache#20628 on v53
branch.

- Convert `JsonAccess` from sqlparser as a normal binary operator
- Add `Operator::Colon`
- Needed for datafusion-contrib/datafusion-variant#26
@Samyak2
Copy link
Contributor Author

Samyak2 commented Mar 5, 2026

I'm not sure about the criteria a PR needs to meet to be backported. In case this PR does qualify, I have opened a PR here: #20717

@alamb
Copy link
Contributor

alamb commented Mar 5, 2026

Given we haven't released branch-53 this is fine as it is a major release. When doing minor releases we can't backport API changes

alamb pushed a commit that referenced this pull request Mar 5, 2026
…tor::Colon` (#20717)

## Which issue does this PR close?

- part of #19692  
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->

- Needed in
datafusion-contrib/datafusion-variant#26

- Backport of #20628 on v53
branch.

## Rationale for this change

<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->

- `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?

<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes 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?

<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->

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?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->

<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->

Add `Operator::Colon`
@Samyak2
Copy link
Contributor Author

Samyak2 commented Mar 6, 2026

Got it, thank you!

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.

3 participants