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
1 change: 0 additions & 1 deletion src/cast_to_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl CastToVariantUdf {
}

impl ScalarUDFImpl for CastToVariantUdf {

fn name(&self) -> &str {
"cast_to_variant"
}
Expand Down
1 change: 0 additions & 1 deletion src/is_variant_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ impl Default for IsVariantNullUdf {
}

impl ScalarUDFImpl for IsVariantNullUdf {

fn name(&self) -> &str {
"is_variant_null"
}
Expand Down
1 change: 0 additions & 1 deletion src/json_to_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ impl Default for JsonToVariantUdf {
}

impl ScalarUDFImpl for JsonToVariantUdf {

fn name(&self) -> &str {
"json_to_variant"
}
Expand Down
26 changes: 14 additions & 12 deletions src/variant_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ impl Default for VariantGetUdf {
}

impl ScalarUDFImpl for VariantGetUdf {

fn name(&self) -> &str {
"variant_get"
}
Expand Down Expand Up @@ -389,7 +388,6 @@ impl Default for VariantGetFieldUdf {
}

impl ScalarUDFImpl for VariantGetFieldUdf {

fn name(&self) -> &str {
"variant_get_field"
}
Expand Down Expand Up @@ -998,7 +996,7 @@ mod tests {
}

#[test]
fn test_int_scalar_float_value_returns_null() {
fn test_int_scalar_float_value_coerces() {
let variant_input = variant_scalar_from_json(serde_json::json!({
"price": 10.5
}));
Expand All @@ -1013,8 +1011,10 @@ mod tests {

let result = udf.invoke_with_args(args).unwrap();

let ColumnarValue::Scalar(ScalarValue::Int64(None)) = result else {
panic!("expected NULL Int64 scalar");
// parquet-variant 59 coerces numeric variants to the requested type,
// truncating floats toward zero (10.5 -> 10) rather than returning NULL.
let ColumnarValue::Scalar(ScalarValue::Int64(Some(10))) = result else {
panic!("expected Int64(10) from float coercion, got {result:?}");
};
}

Expand Down Expand Up @@ -1406,7 +1406,7 @@ mod tests {
}

#[test]
fn test_bool_scalar_int_value_returns_null() {
fn test_bool_scalar_int_value_coerces() {
let variant_input = variant_scalar_from_json(serde_json::json!({
"count": 1
}));
Expand All @@ -1421,8 +1421,10 @@ mod tests {

let result = udf.invoke_with_args(args).unwrap();

let ColumnarValue::Scalar(ScalarValue::Boolean(None)) = result else {
panic!("expected NULL Boolean scalar");
// parquet-variant 59 coerces numeric variants to boolean (nonzero -> true)
// rather than returning NULL.
let ColumnarValue::Scalar(ScalarValue::Boolean(Some(true))) = result else {
panic!("expected Boolean(true) from int coercion, got {result:?}");
};
}

Expand Down Expand Up @@ -1534,10 +1536,10 @@ mod tests {

let bool_arr = arr.as_any().downcast_ref::<BooleanArray>().unwrap();
assert_eq!(bool_arr.len(), 4);
assert!(bool_arr.value(0));
assert!(bool_arr.is_null(1));
assert!(bool_arr.is_null(2));
assert!(bool_arr.is_null(3));
assert!(bool_arr.value(0)); // active = true
assert!(bool_arr.value(1)); // count = 3 coerces to true (parquet-variant 59)
assert!(bool_arr.is_null(2)); // name = "alice" is not boolean-castable
assert!(bool_arr.is_null(3)); // missing path
}

fn string_list_scalar(values: &[&str]) -> ScalarValue {
Expand Down
1 change: 0 additions & 1 deletion src/variant_list_construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl Default for VariantListConstruct {
}

impl ScalarUDFImpl for VariantListConstruct {

fn name(&self) -> &str {
"variant_list_construct"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_list_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fn delete_list_element(variant_list: Variant, index: usize) -> Result<(Vec<u8>,
}

impl ScalarUDFImpl for VariantListDelete {

fn name(&self) -> &str {
"variant_list_delete"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_list_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Default for VariantListInsert {
}

impl ScalarUDFImpl for VariantListInsert {

fn name(&self) -> &str {
"variant_list_insert"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ impl Default for VariantNormalizeUdf {
}

impl ScalarUDFImpl for VariantNormalizeUdf {

fn name(&self) -> &str {
"variant_normalize"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_object_construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Default for VariantObjectConstruct {
}

impl ScalarUDFImpl for VariantObjectConstruct {

fn name(&self) -> &str {
"variant_object_construct"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_object_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Default for VariantObjectDelete {
}

impl ScalarUDFImpl for VariantObjectDelete {

fn name(&self) -> &str {
"variant_object_delete"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_object_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Default for VariantObjectInsert {
}

impl ScalarUDFImpl for VariantObjectInsert {

fn name(&self) -> &str {
"variant_object_insert"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_object_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn append_keys_from_variant(v_opt: Option<Variant>, builder: &mut ListBuilder<St
}

impl ScalarUDFImpl for VariantObjectKeys {

fn name(&self) -> &str {
"variant_object_keys"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ impl Default for VariantPretty {
}

impl ScalarUDFImpl for VariantPretty {

fn name(&self) -> &str {
"variant_pretty"
}
Expand Down
1 change: 0 additions & 1 deletion src/variant_to_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl Default for VariantToJsonUdf {
}

impl ScalarUDFImpl for VariantToJsonUdf {

fn name(&self) -> &str {
"variant_to_json"
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_files/variant_get_bool.slt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ NULL
NULL
NULL

# non-boolean values return null (integer field)
# integer fields coerce to boolean (nonzero -> true); rows without `age` are null
query B
select variant_get_bool(json_to_variant(json_str), 'age') from json_data;
----
NULL
NULL
true
true
NULL
NULL
NULL
Expand All @@ -79,11 +79,11 @@ select variant_get_bool(json_to_variant('{"greeting": "hello world"}'), 'greetin
----
NULL

# scalar variant with numeric value returns null
# scalar variant with numeric value coerces to boolean (nonzero -> true)
query B
select variant_get_bool(json_to_variant('{"count": 42}'), 'count');
----
NULL
true

# nested boolean path
query B
Expand Down
3 changes: 2 additions & 1 deletion tests/test_files/variant_get_int.slt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ NULL
NULL
NULL

# float values coerce to Int64 (truncated toward zero); rows without `pi` are null
query I
select variant_get_int(json_to_variant(json_str), 'pi') from json_data;
----
Expand All @@ -58,7 +59,7 @@ NULL
NULL
NULL
NULL
NULL
3

# Scalar variant with integer value
query I
Expand Down