Skip to content

Commit 7bac57e

Browse files
committed
feat: add optional JSON functions support
Add `datafusion-functions-json` as an optional feature (`json`), giving Python users `json_extract`, `json_get`, `->`, `->>` and other JSON operators in SQL queries. When built with `--features json`, JSON functions are automatically registered with every SessionContext. Default builds are unaffected. Changes: - Add `datafusion-functions-json` to workspace dependencies - Add optional dependency and `json` feature flag to core crate - Register JSON functions in SessionContext creation when feature is enabled
1 parent 5be412b commit 7bac57e

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ datafusion-common = { version = "53", default-features = false }
4848
datafusion-functions-aggregate = { version = "53" }
4949
datafusion-functions-window = { version = "53" }
5050
datafusion-expr = { version = "53" }
51+
datafusion-functions-json = { version = "0.53" }
5152
prost = "0.14.3"
5253
serde_json = "1"
5354
uuid = { version = "1.23" }

crates/core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ datafusion = { workspace = true, features = ["avro", "unicode_expressions"] }
5353
datafusion-substrait = { workspace = true, optional = true }
5454
datafusion-proto = { workspace = true }
5555
datafusion-ffi = { workspace = true }
56+
datafusion-functions-json = { workspace = true, optional = true }
5657
prost = { workspace = true } # keep in line with `datafusion-substrait`
5758
serde_json = { workspace = true }
5859
uuid = { workspace = true, features = ["v4"] }
@@ -74,6 +75,7 @@ pyo3-build-config = { workspace = true }
7475

7576
[features]
7677
default = ["mimalloc"]
78+
json = ["dep:datafusion-functions-json"]
7779
protoc = ["datafusion-substrait/protoc"]
7880
substrait = ["dep:datafusion-substrait"]
7981

crates/core/src/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ impl PySessionContext {
391391
.with_default_features()
392392
.build();
393393
let ctx = Arc::new(SessionContext::new_with_state(session_state));
394+
395+
// Register JSON functions (json_extract, json_get, ->, ->>) when feature is enabled
396+
#[cfg(feature = "json")]
397+
datafusion_functions_json::register_all(ctx.as_ref())
398+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
399+
format!("Failed to register JSON functions: {e}"),
400+
))?;
401+
394402
let logical_codec = Self::default_logical_codec(&ctx);
395403
Ok(PySessionContext { ctx, logical_codec })
396404
}

0 commit comments

Comments
 (0)