Skip to content

Commit 5d5d0da

Browse files
committed
update test in sqllogictest
1 parent 73f3b06 commit 5d5d0da

3 files changed

Lines changed: 61 additions & 115 deletions

File tree

datafusion/common/src/scalar.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,20 +2071,20 @@ impl ScalarValue {
20712071
/// Example
20722072
/// ```
20732073
/// use datafusion_common::ScalarValue;
2074-
/// use arrow::array::{LargeListArray, Int64Array};
2075-
/// use arrow::datatypes::{DataType, Int64Type};
2074+
/// use arrow::array::{LargeListArray, Int32Array};
2075+
/// use arrow::datatypes::{DataType, Int32Type};
20762076
/// use datafusion_common::cast::as_large_list_array;
20772077
///
20782078
/// let scalars = vec![
2079-
/// ScalarValue::Int64(Some(1)),
2080-
/// ScalarValue::Int64(None),
2081-
/// ScalarValue::Int64(Some(2))
2079+
/// ScalarValue::Int32(Some(1)),
2080+
/// ScalarValue::Int32(None),
2081+
/// ScalarValue::Int32(Some(2))
20822082
/// ];
20832083
///
2084-
/// let array = ScalarValue::new_large_list(&scalars, &DataType::Int64);
2084+
/// let array = ScalarValue::new_large_list(&scalars, &DataType::Int32);
20852085
/// let result = as_large_list_array(&array).unwrap();
20862086
///
2087-
/// let expected = LargeListArray::from_iter_primitive::<Int64Type, _, _>(
2087+
/// let expected = LargeListArray::from_iter_primitive::<Int32Type, _, _>(
20882088
/// vec![
20892089
/// Some(vec![Some(1), None, Some(2)])
20902090
/// ]);

datafusion/physical-expr/src/array_expressions.rs

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,19 +2120,6 @@ mod tests {
21202120
);
21212121
}
21222122

2123-
#[test]
2124-
fn test_return_large_array() {
2125-
let list_array = return_large_array();
2126-
let result = as_large_list_array(&list_array);
2127-
assert_eq!(result.len(), 1);
2128-
assert_eq!(
2129-
&[1, 2, 3, 4],
2130-
as_int64_array(&result.value(0))
2131-
.expect("failed to cast to primitive array")
2132-
.values()
2133-
);
2134-
}
2135-
21362123
#[test]
21372124
fn test_array_element() {
21382125
// array_element([1, 2, 3, 4], 1) = 1
@@ -2894,25 +2881,6 @@ mod tests {
28942881
as_uint64_array(&array).expect("failed to initialize function array_ndims");
28952882

28962883
assert_eq!(result, &UInt64Array::from_value(4, 1));
2897-
2898-
// for LargeList
2899-
// array_length([1, 2, 3, 4]) = 4
2900-
let list_array = return_large_array();
2901-
let arr = array_length(&[list_array.clone()])
2902-
.expect("failed to initialize function array_ndims");
2903-
let result =
2904-
as_uint64_array(&arr).expect("failed to initialize function array_ndims");
2905-
2906-
assert_eq!(result, &UInt64Array::from_value(4, 1));
2907-
2908-
// array_length([1, 2, 3, 4], 1) = 4
2909-
let array =
2910-
array_length(&[list_array.clone(), Arc::new(Int64Array::from_value(1, 1))])
2911-
.expect("failed to initialize function array_ndims");
2912-
let result =
2913-
as_uint64_array(&array).expect("failed to initialize function array_ndims");
2914-
2915-
assert_eq!(result, &UInt64Array::from_value(4, 1));
29162884
}
29172885

29182886
#[test]
@@ -2952,43 +2920,6 @@ mod tests {
29522920
as_uint64_array(&arr).expect("failed to initialize function array_length");
29532921

29542922
assert_eq!(result, &UInt64Array::from(vec![None]));
2955-
2956-
// for LargeList
2957-
let list_array = return_nested_large_array();
2958-
2959-
// array_length([[1, 2, 3, 4], [5, 6, 7, 8]]) = 2
2960-
let arr = array_length(&[list_array.clone()])
2961-
.expect("failed to initialize function array_length");
2962-
let result =
2963-
as_uint64_array(&arr).expect("failed to initialize function array_length");
2964-
2965-
assert_eq!(result, &UInt64Array::from_value(2, 1));
2966-
2967-
// array_length([[1, 2, 3, 4], [5, 6, 7, 8]], 1) = 2
2968-
let arr =
2969-
array_length(&[list_array.clone(), Arc::new(Int64Array::from_value(1, 1))])
2970-
.expect("failed to initialize function array_length");
2971-
let result =
2972-
as_uint64_array(&arr).expect("failed to initialize function array_length");
2973-
2974-
assert_eq!(result, &UInt64Array::from_value(2, 1));
2975-
2976-
// array_length([[1, 2, 3, 4], [5, 6, 7, 8]], 2) = 4
2977-
let arr =
2978-
array_length(&[list_array.clone(), Arc::new(Int64Array::from_value(2, 1))])
2979-
.expect("failed to initialize function array_length");
2980-
let result =
2981-
as_uint64_array(&arr).expect("failed to initialize function array_length");
2982-
2983-
assert_eq!(result, &UInt64Array::from_value(4, 1));
2984-
2985-
// array_length([[1, 2, 3, 4], [5, 6, 7, 8]], 3) = NULL
2986-
let arr = array_length(&[list_array, Arc::new(Int64Array::from_value(3, 1))])
2987-
.expect("failed to initialize function array_length");
2988-
let result =
2989-
as_uint64_array(&arr).expect("failed to initialize function array_length");
2990-
2991-
assert_eq!(result, &UInt64Array::from(vec![None]));
29922923
}
29932924

29942925
#[test]
@@ -3084,18 +3015,6 @@ mod tests {
30843015
make_array(&args).expect("failed to initialize function array")
30853016
}
30863017

3087-
fn return_large_array() -> ArrayRef {
3088-
// Returns: [1, 2, 3, 4]
3089-
let args = [
3090-
Arc::new(Int64Array::from(vec![Some(1)])) as ArrayRef,
3091-
Arc::new(Int64Array::from(vec![Some(2)])) as ArrayRef,
3092-
Arc::new(Int64Array::from(vec![Some(3)])) as ArrayRef,
3093-
Arc::new(Int64Array::from(vec![Some(4)])) as ArrayRef,
3094-
];
3095-
let data_type = DataType::Int64;
3096-
array_array::<i64>(&args, data_type).expect("failed to initialize function array")
3097-
}
3098-
30993018
fn return_nested_array() -> ArrayRef {
31003019
// Returns: [[1, 2, 3, 4], [5, 6, 7, 8]]
31013020
let args = [
@@ -3117,33 +3036,6 @@ mod tests {
31173036
make_array(&[arr1, arr2]).expect("failed to initialize function array")
31183037
}
31193038

3120-
fn return_nested_large_array() -> ArrayRef {
3121-
// Returns: [[1, 2, 3, 4], [5, 6, 7, 8]]
3122-
let args = [
3123-
Arc::new(Int64Array::from(vec![Some(1)])) as ArrayRef,
3124-
Arc::new(Int64Array::from(vec![Some(2)])) as ArrayRef,
3125-
Arc::new(Int64Array::from(vec![Some(3)])) as ArrayRef,
3126-
Arc::new(Int64Array::from(vec![Some(4)])) as ArrayRef,
3127-
];
3128-
let data_type = DataType::Int64;
3129-
let arr1 = array_array::<i64>(&args, data_type.clone())
3130-
.expect("failed to initialize function array");
3131-
3132-
let args = [
3133-
Arc::new(Int64Array::from(vec![Some(5)])) as ArrayRef,
3134-
Arc::new(Int64Array::from(vec![Some(6)])) as ArrayRef,
3135-
Arc::new(Int64Array::from(vec![Some(7)])) as ArrayRef,
3136-
Arc::new(Int64Array::from(vec![Some(8)])) as ArrayRef,
3137-
];
3138-
let arr2 = array_array::<i64>(&args, data_type)
3139-
.expect("failed to initialize function array");
3140-
let data_type =
3141-
DataType::LargeList(Arc::new(Field::new("item", DataType::Int64, true)));
3142-
3143-
array_array::<i64>(&[arr1, arr2], data_type)
3144-
.expect("failed to initialize function array")
3145-
}
3146-
31473039
fn return_array_with_nulls() -> ArrayRef {
31483040
// Returns: [1, NULL, 3, NULL]
31493041
let args = [

datafusion/sqllogictest/test_files/array.slt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,36 +2371,66 @@ select array_length(make_array(1, 2, 3, 4, 5)), array_length(make_array(1, 2, 3)
23712371
----
23722372
5 3 3
23732373

2374+
query III
2375+
select array_length(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)')), array_length(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), array_length(arrow_cast(make_array([1, 2], [3, 4], [5, 6]), 'LargeList(List(Int64))'));
2376+
----
2377+
5 3 3
2378+
23742379
# array_length scalar function #2
23752380
query III
23762381
select array_length(make_array(1, 2, 3, 4, 5), 1), array_length(make_array(1, 2, 3), 1), array_length(make_array([1, 2], [3, 4], [5, 6]), 1);
23772382
----
23782383
5 3 3
23792384

2385+
query III
2386+
select array_length(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 1), array_length(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)'), 1), array_length(arrow_cast(make_array([1, 2], [3, 4], [5, 6]), 'LargeList(List(Int64))'), 1);
2387+
----
2388+
5 3 3
2389+
23802390
# array_length scalar function #3
23812391
query III
23822392
select array_length(make_array(1, 2, 3, 4, 5), 2), array_length(make_array(1, 2, 3), 2), array_length(make_array([1, 2], [3, 4], [5, 6]), 2);
23832393
----
23842394
NULL NULL 2
23852395

2396+
query III
2397+
select array_length(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)'), 2), array_length(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)'), 2), array_length(arrow_cast(make_array([1, 2], [3, 4], [5, 6]), 'LargeList(List(Int64))'), 2);
2398+
----
2399+
NULL NULL 2
2400+
23862401
# array_length scalar function #4
23872402
query II
23882403
select array_length(array_repeat(array_repeat(array_repeat(3, 5), 2), 3), 1), array_length(array_repeat(array_repeat(array_repeat(3, 5), 2), 3), 2);
23892404
----
23902405
3 2
23912406

2407+
query II
2408+
select array_length(arrow_cast(array_repeat(array_repeat(array_repeat(3, 5), 2), 3), 'LargeList(List(List(Int64)))'), 1), array_length(arrow_cast(array_repeat(array_repeat(array_repeat(3, 5), 2), 3), 'LargeList(List(List(Int64)))'), 2);
2409+
----
2410+
3 2
2411+
23922412
# array_length scalar function #5
23932413
query III
23942414
select array_length(make_array()), array_length(make_array(), 1), array_length(make_array(), 2)
23952415
----
23962416
0 0 NULL
23972417

2418+
query III
2419+
select array_length(arrow_cast(make_array(), 'LargeList(Null)')), array_length(arrow_cast(make_array(), 'LargeList(Null)'), 1), array_length(arrow_cast(make_array(), 'LargeList(Null)'), 2)
2420+
----
2421+
0 0 NULL
2422+
23982423
# list_length scalar function #6 (function alias `array_length`)
23992424
query III
24002425
select list_length(make_array(1, 2, 3, 4, 5)), list_length(make_array(1, 2, 3)), list_length(make_array([1, 2], [3, 4], [5, 6]));
24012426
----
24022427
5 3 3
24032428

2429+
query III
2430+
select list_length(arrow_cast(make_array(1, 2, 3, 4, 5), 'LargeList(Int64)')), list_length(arrow_cast(make_array(1, 2, 3), 'LargeList(Int64)')), list_length(arrow_cast(make_array([1, 2], [3, 4], [5, 6]), 'LargeList(List(Int64))'));
2431+
----
2432+
5 3 3
2433+
24042434
# array_length with columns
24052435
query I
24062436
select array_length(column1, column3) from arrays_values;
@@ -2414,6 +2444,18 @@ NULL
24142444
NULL
24152445
NULL
24162446

2447+
query I
2448+
select array_length(arrow_cast(column1, 'LargeList(Int64)'), column3) from arrays_values;
2449+
----
2450+
10
2451+
NULL
2452+
NULL
2453+
NULL
2454+
NULL
2455+
NULL
2456+
NULL
2457+
NULL
2458+
24172459
# array_length with columns and scalars
24182460
query II
24192461
select array_length(array[array[1, 2], array[3, 4]], column3), array_length(column1, 1) from arrays_values;
@@ -2427,6 +2469,18 @@ NULL 10
24272469
NULL 10
24282470
NULL 10
24292471

2472+
query II
2473+
select array_length(arrow_cast(array[array[1, 2], array[3, 4]], 'LargeList(List(Int64))'), column3), array_length(arrow_cast(column1, 'LargeList(Int64)'), 1) from arrays_values;
2474+
----
2475+
2 10
2476+
2 10
2477+
NULL 10
2478+
NULL 10
2479+
NULL NULL
2480+
NULL 10
2481+
NULL 10
2482+
NULL 10
2483+
24302484
## array_dims (aliases: `list_dims`)
24312485

24322486
# array dims error

0 commit comments

Comments
 (0)