Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ license = "Apache-2.0"
keywords = ["datafusion", "JSON", "SQL"]
categories = ["database-implementations", "parsing"]
repository = "https://github.com/datafusion-contrib/datafusion-functions-json/"
rust-version = "1.94.0"
rust-version = "1.95.0"

[dependencies]
datafusion = { version = "55", default-features = false, features = [
datafusion = { version = "56", default-features = false, features = [
"sql",
] }
jiter = "0.17.0"
Expand All @@ -21,7 +21,7 @@ serde_json = "1"

[dev-dependencies]
codspeed-criterion-compat = "5.0.2"
datafusion = { version = "55", default-features = false, features = [
datafusion = { version = "56", default-features = false, features = [
"nested_expressions",
"sql",
] }
Expand All @@ -40,6 +40,9 @@ pedantic = { level = "deny", priority = -1 }
name = "main"
harness = false

[patch.crates-io]
datafusion = { git = "https://github.com/apache/datafusion.git", branch = "branch-56" }

# [patch.crates-io]
# datafusion = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-common = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
Expand Down
7 changes: 5 additions & 2 deletions src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,14 @@ impl ExprPlanner for JsonExprPlanner {

let alias_name = format!("{left_repr} {op} {right_repr}");

// we put the alias in so that default column titles are `foo -> bar` instead of `json_get(foo, bar)`
// we put the alias in so that default column titles are `foo -> bar` instead of `json_get(foo, bar)`.
// An operand that is itself an operator, e.g. the `a ->> 'b'` in `a ->> 'b' ->> 0`, carries
// such an alias too; it has already gone into `alias_name`, and inside the call it would
// only clutter the plan, so it is dropped there.
Ok(PlannerResult::Planned(Expr::Alias(Alias::new(
Expr::ScalarFunction(ScalarFunction {
func: op.into(),
args: vec![expr.left, expr.right],
args: vec![expr.left.unalias(), expr.right.unalias()],
}),
None::<&str>,
alias_name,
Expand Down
6 changes: 4 additions & 2 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,9 +1793,11 @@ async fn test_double_arrow_double_nested_cast() {
async fn test_plan_double_arrow_double_nested_cast() {
let lines = logical_plan(r"explain select (json_data->>'foo'->>0)::int from test").await;

// NB: json_as_text(..)::int is NOT the same as `json_get_int(..)`, hence the cast is not rewritten
// NB: json_as_text(..)::int is NOT the same as `json_get_int(..)`, hence the cast is not rewritten.
// The cast is planned around the aliased `->>`, so the alias, and with it the column name, is
// inside the cast.
let expected = [
"Projection: CAST(json_as_text(json_as_text(test.json_data, Utf8(\"foo\")), Int64(0)) AS Int32) AS json_data ->> 'foo' ->> 0",
"Projection: CAST(json_as_text(json_as_text(test.json_data, Utf8(\"foo\")), Int64(0)) AS json_data ->> 'foo' ->> 0 AS Int32)",
" TableScan: test projection=[json_data]",
];

Expand Down
Loading