Skip to content

Commit 4c7d253

Browse files
crm26claude
andcommitted
feat: add optional JSON functions support
Add `datafusion-functions-json` as an optional feature (`json`), giving Python users `json_get_str`, `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. Tested locally: json_get_str extracts values, nested paths work, GROUP BY on extracted JSON fields works. 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 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5be412b commit 4c7d253

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,16 @@ impl PySessionContext {
390390
.with_runtime_env(runtime)
391391
.with_default_features()
392392
.build();
393-
let ctx = Arc::new(SessionContext::new_with_state(session_state));
393+
let mut ctx = 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(&mut ctx)
398+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(
399+
format!("Failed to register JSON functions: {e}"),
400+
))?;
401+
402+
let ctx = Arc::new(ctx);
394403
let logical_codec = Self::default_logical_codec(&ctx);
395404
Ok(PySessionContext { ctx, logical_codec })
396405
}

0 commit comments

Comments
 (0)