Skip to content

feat: add a custom ExprPlanner to support colon operator - #57

Merged
sdf-jkl merged 5 commits into
datafusion-contrib:mainfrom
Samyak2:colon-operator
Sep 24, 2026
Merged

sdf-jkl merged 5 commits into
datafusion-contrib:mainfrom
Samyak2:colon-operator

Conversation

@Samyak2

@Samyak2 Samyak2 commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Closes #26

  • Add a custom ExprPlanner that handles : as an operator and re-writes it to variant_get.

Closes datafusion-contrib#26

- Add a custom `ExprPlanner` that handles `:` as an operator and
  re-writes it to `variant_get`.
@Samyak2

Samyak2 commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

TODO:

  • This handles the 2-arg version. The 3-arg version (with cast) is yet to be converted
  • Tests

@friendlymatthew friendlymatthew left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Samyak2

Can we add some tests as well please

Comment thread src/expr_planner.rs
Comment on lines +17 to +18
#[derive(Debug)]
pub struct VariantExprPlanner;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add some comments here that explain what this does

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Please take a look

@Samyak2

Samyak2 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

There seems to a bug in the sql parser. These are failing:

select variant_pretty(json_to_variant(json_str):[1]) from json_data;

and

select variant_pretty(json_to_variant(json_str):['name']) from json_data;

fails with:

SQL error: ParserError("Expected: variant object key name, found: [ at Line: 1, Column: 49")

@Samyak2

Samyak2 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Another problem. Cast does not get parsed as a BinaryOperator. It's a separate variant of Expr: https://docs.rs/sqlparser/0.61.0/sqlparser/ast/enum.Expr.html#variant.Cast

ExprPlanner currently does not support custom parsing for cast.

So we won't be able to support 3-arg version like variant_col:name::string, etc.

@Samyak2
Samyak2 marked this pull request as ready for review March 31, 2026 08:47
@sdf-jkl

sdf-jkl commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

There seems to a bug in the sql parser. These are failing:

select variant_pretty(json_to_variant(json_str):[1]) from json_data;

and

select variant_pretty(json_to_variant(json_str):['name']) from json_data;

fails with:

SQL error: ParserError("Expected: variant object key name, found: [ at Line: 1, Column: 49")

Is this a bug though? It seems like a Databricks dialect specifics.

Another problem. Cast does not get parsed as a BinaryOperator. It's a separate variant of Expr: https://docs.rs/sqlparser/0.61.0/sqlparser/ast/enum.Expr.html#variant.Cast

ExprPlanner currently does not support custom parsing for cast.

So we won't be able to support 3-arg version like variant_col:name::string, etc.

Another issue to work on in sqlparser-rs?

@Samyak2

Samyak2 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor Author

Is this a bug though? It seems like a Databricks dialect specifics.

I don't see any reason not to support variant_col:['name'] when variant_col:something['name'] is supported.

Another issue to work on in sqlparser-rs?

This would be something to add in datafusion's ExprPlanner. We need something like ExprPlanner::plan_cast.


Both of these are not blocking issues. I think we can merge without them. What do you think?

@sdf-jkl

sdf-jkl commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

Sounds good to me. @friendlymatthew?

@Samyak2 Samyak2 mentioned this pull request Jun 5, 2026
4 tasks done
@alamb

alamb commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

@sdf-jkl sdf-jkl left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Samyak2!

There are still some cases that might not work as expected in parity with Spark:

{
  "name": "Alice",
  "field-name": "hyphen",
  "field name": "space",
  "a]b": "bracket"
}
Expression Spark This crate + #57
v:`name` "Alice" SQL NULL
v:`field-name` "hyphen" SQL NULL
v:`field name` "space" SQL NULL
v:['a]b'] Expected "bracket" from parser logic; runtime verification pending Path-parser error

But I'd defer this to later work for syntax hardening

@sdf-jkl
sdf-jkl merged commit 0b58831 into datafusion-contrib:main Sep 24, 2026
3 checks passed
@alamb

alamb commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

amazing!
excited-ronpaul

@sdf-jkl

sdf-jkl commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

I added the syntax support SLT suite here #68

@sdf-jkl sdf-jkl mentioned this pull request Sep 24, 2026
18 of 27 tasks
@Samyak2

Samyak2 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for merging!

Sorry, I had not been keeping up with the progress around variant, but looks like this crate is finally picking up steam again 🚀

@alamb

alamb commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Thank you for merging!

Sorry, I had not been keeping up with the progress around variant, but looks like this crate is finally picking up steam again 🚀

Indeed, we have recruited @sdf-jkl (well, really he volunteered) and I have a good feeling about the future of this crate

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

colon : operator - initial implementation

5 participants