Skip to content

Commit 0ab5da2

Browse files
committed
resolve merge conflict
2 parents 7ea7f9b + 9d72f5d commit 0ab5da2

24 files changed

+1219
-223
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ jobs:
7070
- id: cache-rust
7171
uses: Swatinem/rust-cache@v2
7272

73-
- run: cargo test --all-features
74-
# - uses: taiki-e/install-action@cargo-llvm-cov
75-
#
76-
# - run: cargo llvm-cov --all-features --codecov --output-path codecov.json
77-
#
78-
# - uses: codecov/codecov-action@v3
79-
# with:
80-
# files: codecov.json
81-
# env_vars: RUST_VERSION
73+
- uses: taiki-e/install-action@cargo-llvm-cov
74+
75+
- run: cargo llvm-cov --all-features --codecov --output-path codecov.json
76+
77+
- uses: codecov/codecov-action@v3
78+
with:
79+
token: ${{ secrets.CODECOV_TOKEN }}
80+
files: codecov.json
81+
env_vars: RUST_VERSION
8282

8383
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
8484
check:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.idea

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
pass_filenames: false
2121
- id: clippy
2222
name: Clippy
23-
entry: cargo clippy
23+
entry: cargo clippy -- -D warnings
2424
types: [rust]
2525
language: system
2626
pass_filenames: false

Cargo.toml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
[package]
22
name = "datafusion-functions-json"
3-
version = "0.41.0"
3+
version = "0.43.0"
44
edition = "2021"
55
description = "JSON functions for DataFusion"
66
readme = "README.md"
77
license = "Apache-2.0"
88
keywords = ["datafusion", "JSON", "SQL"]
99
categories = ["database-implementations", "parsing"]
1010
repository = "https://github.com/datafusion-contrib/datafusion-functions-json/"
11-
rust-version = "1.76.0"
11+
rust-version = "1.79.0"
1212

1313
[dependencies]
14-
arrow = "52.2"
15-
arrow-schema = "52.2"
16-
datafusion-common = "41"
17-
datafusion-expr = "41"
18-
datafusion-execution = "41"
14+
datafusion = "43"
1915
jiter = "0.5"
2016
paste = "1"
2117
log = "0.4"
2218

2319
[dev-dependencies]
24-
codspeed-criterion-compat = "2.3"
20+
codspeed-criterion-compat = "2.6"
2521
criterion = "0.5.1"
26-
datafusion = "41"
2722
clap = "4"
28-
tokio = { version = "1.37", features = ["full"] }
23+
tokio = { version = "1.38", features = ["full"] }
2924

3025
[lints.clippy]
3126
dbg_macro = "deny"

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,47 @@ To use these functions, you'll just need to call:
1212
```rust
1313
datafusion_functions_json::register_all(&mut ctx)?;
1414
```
15-
1615
To register the below JSON functions in your `SessionContext`.
1716

17+
# Examples
18+
19+
```sql
20+
-- Create a table with a JSON column stored as a string
21+
CREATE TABLE test_table (id INT, json_col VARCHAR) AS VALUES
22+
(1, '{}'),
23+
(2, '{ "a": 1 }'),
24+
(3, '{ "a": 2 }'),
25+
(4, '{ "a": 1, "b": 2 }'),
26+
(5, '{ "a": 1, "b": 2, "c": 3 }');
27+
28+
-- Check if each document contains the key 'b'
29+
SELECT id, json_contains(json_col, 'b') as json_contains FROM test_table;
30+
-- Results in
31+
-- +----+---------------+
32+
-- | id | json_contains |
33+
-- +----+---------------+
34+
-- | 1 | false |
35+
-- | 2 | false |
36+
-- | 3 | false |
37+
-- | 4 | true |
38+
-- | 5 | true |
39+
-- +----+---------------+
40+
41+
-- Get the value of the key 'a' from each document
42+
SELECT id, json_col->'a' as json_col_a FROM test_table
43+
44+
-- +----+------------+
45+
-- | id | json_col_a |
46+
-- +----+------------+
47+
-- | 1 | {null=} |
48+
-- | 2 | {int=1} |
49+
-- | 3 | {int=2} |
50+
-- | 4 | {int=1} |
51+
-- | 5 | {int=1} |
52+
-- +----+------------+
53+
```
54+
55+
1856
## Done
1957

2058
* [x] `json_contains(json: str, *keys: str | int) -> bool` - true if a JSON string has a specific key (used for the `?` operator)
@@ -27,6 +65,11 @@ To register the below JSON functions in your `SessionContext`.
2765
* [x] `json_as_text(json: str, *keys: str | int) -> str` - Get any value from a JSON string by its "path", represented as a string (used for the `->>` operator)
2866
* [x] `json_length(json: str, *keys: str | int) -> int` - get the length of a JSON string or array
2967

68+
- [x] `->` operator - alias for `json_get`
69+
- [x] `->>` operator - alias for `json_as_text`
70+
- [x] `?` operator - alias for `json_contains`
71+
72+
### Notes
3073
Cast expressions with `json_get` are rewritten to the appropriate method, e.g.
3174

3275
```sql

benches/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use codspeed_criterion_compat::{criterion_group, criterion_main, Bencher, Criterion};
22

3-
use datafusion_common::ScalarValue;
4-
use datafusion_expr::ColumnarValue;
3+
use datafusion::common::ScalarValue;
4+
use datafusion::logical_expr::ColumnarValue;
55
use datafusion_functions_json::udfs::{json_contains_udf, json_get_str_udf};
66

77
fn bench_json_contains(b: &mut Bencher) {
@@ -14,7 +14,7 @@ fn bench_json_contains(b: &mut Bencher) {
1414
ColumnarValue::Scalar(ScalarValue::Utf8(Some("aa".to_string()))),
1515
];
1616

17-
b.iter(|| json_contains.invoke(args).unwrap());
17+
b.iter(|| json_contains.invoke_batch(args, 1).unwrap());
1818
}
1919

2020
fn bench_json_get_str(b: &mut Bencher) {
@@ -27,7 +27,7 @@ fn bench_json_get_str(b: &mut Bencher) {
2727
ColumnarValue::Scalar(ScalarValue::Utf8(Some("aa".to_string()))),
2828
];
2929

30-
b.iter(|| json_get_str.invoke(args).unwrap());
30+
b.iter(|| json_get_str.invoke_batch(args, 1).unwrap());
3131
}
3232

3333
fn criterion_benchmark(c: &mut Criterion) {

0 commit comments

Comments
 (0)