Skip to content
Merged
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ license = "Apache-2.0"
keywords = ["datafusion", "JSON", "SQL"]
categories = ["database-implementations", "parsing"]
repository = "https://github.com/datafusion-contrib/datafusion-functions-json/"
rust-version = "1.81.0"
rust-version = "1.82.0"

[dependencies]
datafusion = { version = "45", default-features = false }
jiter = "0.8"
datafusion = { version = "46", default-features = false }
jiter = "0.9"
paste = "1"
log = "0.4"

[dev-dependencies]
datafusion = { version = "45", default-features = false, features = ["nested_expressions"] }
datafusion = { version = "46", default-features = false, features = ["nested_expressions"] }
codspeed-criterion-compat = "2.6"
criterion = "0.5.1"
clap = "4"
tokio = { version = "1.38", features = ["full"] }
tokio = { version = "1.43", features = ["full"] }

[lints.clippy]
dbg_macro = "deny"
Expand Down
2 changes: 1 addition & 1 deletion src/json_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ make_udf_function!(
JsonLength,
json_length,
json_data path,
r#"Get the length of the array or object at the given path."#
r"Get the length of the array or object at the given path."
);

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/json_object_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ make_udf_function!(
JsonObjectKeys,
json_object_keys,
json_data path,
r#"Get the keys of a JSON object as an array."#
r"Get the keys of a JSON object as an array."
);

#[derive(Debug)]
Expand Down
6 changes: 5 additions & 1 deletion src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ impl std::fmt::Display for JsonOperator {
/// Convert an Expr to a String representatiion for use in alias names.
fn expr_to_sql_repr(expr: &Expr) -> String {
match expr {
Expr::Column(Column { name, relation }) => relation
Expr::Column(Column {
name,
relation,
spans: _,
}) => relation
.as_ref()
.map_or_else(|| name.clone(), |r| format!("{r}.{name}")),
Expr::Alias(alias) => alias.name.clone(),
Expand Down
13 changes: 8 additions & 5 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,12 @@ fn check_for_null_dictionary_values(array: &dyn Array) {
if values_array.is_null(i) {
// keys should not contain
if keys.contains(&i) {
println!("keys: {:?}", keys);
println!("values: {:?}", values_array);
panic!("keys should not contain null values");
#[allow(clippy::print_stdout)]
{
println!("keys: {keys:?}");
println!("values: {values_array:?}");
panic!("keys should not contain null values");
}
}
}
}
Expand Down Expand Up @@ -1341,7 +1344,7 @@ async fn test_dict_get_no_null_values() {
"| |",
"+------------+",
];
let batches = ctx.sql(&sql).await.unwrap().collect().await.unwrap();
let batches = ctx.sql(sql).await.unwrap().collect().await.unwrap();
assert_batches_eq!(expected, &batches);
for batch in batches {
check_for_null_dictionary_values(batch.column(0).as_ref());
Expand All @@ -1352,7 +1355,7 @@ async fn test_dict_get_no_null_values() {
"+------+", "| v |", "+------+", "| |", "| fizz |", "| |", "| abcd |", "| |", "| fizz |",
"| fizz |", "| fizz |", "| fizz |", "| |", "+------+",
];
let batches = ctx.sql(&sql).await.unwrap().collect().await.unwrap();
let batches = ctx.sql(sql).await.unwrap().collect().await.unwrap();
assert_batches_eq!(expected, &batches);
for batch in batches {
check_for_null_dictionary_values(batch.column(0).as_ref());
Expand Down
35 changes: 29 additions & 6 deletions tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub async fn create_context() -> Result<SessionContext> {
Ok(ctx)
}

#[expect(clippy::too_many_lines)]
async fn create_test_table(large_utf8: bool, dict_encoded: bool) -> Result<SessionContext> {
let ctx = create_context().await?;

Expand All @@ -42,7 +43,7 @@ async fn create_test_table(large_utf8: bool, dict_encoded: bool) -> Result<Sessi
if dict_encoded {
json_data_type = DataType::Dictionary(DataType::Int32.into(), json_data_type.into());
json_array = Arc::new(DictionaryArray::<Int32Type>::new(
Int32Array::from_iter_values(0..(json_array.len() as i32)),
Int32Array::from_iter_values(0..(i32::try_from(json_array.len()).expect("fits in a i32"))),
json_array,
));
}
Expand Down Expand Up @@ -160,13 +161,23 @@ async fn create_test_table(large_utf8: bool, dict_encoded: bool) -> Result<Sessi
])),
vec![
Arc::new(DictionaryArray::<UInt32Type>::new(
UInt32Array::from_iter_values(dict_data.iter().enumerate().map(|(id, _)| id as u32)),
UInt32Array::from_iter_values(
dict_data
.iter()
.enumerate()
.map(|(id, _)| u32::try_from(id).expect("fits in a u32")),
),
Arc::new(StringArray::from(
dict_data.iter().map(|(json, _, _, _)| *json).collect::<Vec<_>>(),
)),
)),
Arc::new(DictionaryArray::<UInt8Type>::new(
UInt8Array::from_iter_values(dict_data.iter().enumerate().map(|(id, _)| id as u8)),
UInt8Array::from_iter_values(
dict_data
.iter()
.enumerate()
.map(|(id, _)| u8::try_from(id).expect("fits in a u8")),
),
Arc::new(LargeStringArray::from(
dict_data
.iter()
Expand All @@ -175,7 +186,12 @@ async fn create_test_table(large_utf8: bool, dict_encoded: bool) -> Result<Sessi
)),
)),
Arc::new(DictionaryArray::<UInt8Type>::new(
UInt8Array::from_iter_values(dict_data.iter().enumerate().map(|(id, _)| id as u8)),
UInt8Array::from_iter_values(
dict_data
.iter()
.enumerate()
.map(|(id, _)| u8::try_from(id).expect("fits in a u8")),
),
Arc::new(StringViewArray::from(
dict_data
.iter()
Expand All @@ -184,9 +200,16 @@ async fn create_test_table(large_utf8: bool, dict_encoded: bool) -> Result<Sessi
)),
)),
Arc::new(DictionaryArray::<Int64Type>::new(
Int64Array::from_iter_values(dict_data.iter().enumerate().map(|(id, _)| id as i64)),
Int64Array::from_iter_values(
dict_data
.iter()
.enumerate()
.map(|(id, _)| i64::try_from(id).expect("fits in a i64")),
),
Arc::new(UInt64Array::from_iter_values(
dict_data.iter().map(|(_, _, _, int_key)| *int_key as u64),
dict_data
.iter()
.map(|(_, _, _, int_key)| u64::try_from(*int_key).expect("not negative")),
)),
)),
],
Expand Down