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
30 changes: 18 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ license = "Apache-2.0"
keywords = ["datafusion", "JSON", "SQL"]
categories = ["database-implementations", "parsing"]
repository = "https://github.com/datafusion-contrib/datafusion-functions-json/"
rust-version = "1.88.0"
# TEMPORARY: raised from 1.88.0 to match the MSRV of `apache/datafusion` main
rust-version = "1.94.0"

[dependencies]
datafusion = { version = "54", default-features = false, features = [
# TEMPORARY: track unreleased DataFusion, see the note at the bottom of this file
datafusion = { git = "https://github.com/apache/datafusion.git", branch = "main", default-features = false, features = [
"sql",
] }
jiter = "0.15.0"
Expand All @@ -21,7 +23,8 @@ serde_json = "1"

[dev-dependencies]
codspeed-criterion-compat = "2.6"
datafusion = { version = "54", default-features = false, features = [
# TEMPORARY: track unreleased DataFusion, see the note at the bottom of this file
datafusion = { git = "https://github.com/apache/datafusion.git", branch = "main", default-features = false, features = [
"nested_expressions",
"sql",
] }
Expand All @@ -39,12 +42,15 @@ pedantic = { level = "deny", priority = -1 }
name = "main"
harness = false

# [patch.crates-io]
# datafusion = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-common = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-expr = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-execution = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-sql = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-proto = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-datasource = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# datafusion-physical-expr-adapter = { git = "https://github.com/apache/datafusion.git", rev = "d47bd599ee911eb4be018595b860341ff437ccb1" }
# TEMPORARY — do not release from this branch.
#
# The `datafusion` dependencies above point at `apache/datafusion` main rather than a published
# version, so breakage from unreleased DataFusion changes shows up here instead of during the
# upgrade after a release. `cargo publish` rejects git dependencies, so this branch cannot be
# released as-is: when the next DataFusion is out, swap both entries back to
# `{ version = "<next>", default-features = false, features = [...] }` and restore `rust-version`.
#
# A `[patch.crates-io]` entry (as previously stubbed out here) is deliberately not used: a patch
# only applies while the git version still satisfies the `version = "..."` requirement, so the
# moment main bumps its major the patch would be silently dropped and CI would go back to testing
# the released version.
39 changes: 33 additions & 6 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,41 @@ fn assert_json_field_metadata(metadata: &HashMap<String, String>) {

#[tokio::test]
async fn test_json_get_equals() {
let e = run_query(r"select name, json_get(json_data, 'foo')='abc' from test")
// this used to fail to plan, see https://github.com/apache/datafusion/issues/10180, DataFusion
// now coerces the union to a string, so the comparison is equivalent to `json_get(...)::string`
// and yields null for any value that isn't a JSON string
let batches = run_query(r"select name, json_get(json_data, 'foo')='abc' from test")
.await
.unwrap_err();
.unwrap();

// see https://github.com/apache/datafusion/issues/10180
assert!(e
.to_string()
.starts_with("Error during planning: Cannot infer common argument type for comparison operation Union"));
let expected = [
"+------------------+----------------------------------------------------+",
"| name | json_get(test.json_data,Utf8(\"foo\")) = Utf8(\"abc\") |",
"+------------------+----------------------------------------------------+",
"| object_foo | true |",
"| object_foo_array | |",
"| object_foo_obj | |",
"| object_foo_null | |",
"| object_bar | |",
"| list_foo | |",
"| invalid_json | |",
"+------------------+----------------------------------------------------+",
];
assert_batches_eq!(expected, &batches);
}

#[tokio::test]
async fn test_plan_json_get_equals() {
// the implicit cast inserted by type coercion is not rewritten to `json_get_str`, unlike the
// explicit cast in `test_plan_arrow_cast_int` and friends
let lines = logical_plan(r"explain select name, json_get(json_data, 'foo')='abc' from test").await;

let expected = [
"Projection: test.name, CAST(json_get(test.json_data, Utf8(\"foo\")) AS Utf8) = Utf8(\"abc\")",
" TableScan: test projection=[name, json_data]",
];

assert_eq!(lines, expected);
}

#[tokio::test]
Expand Down
Loading