Skip to content

Commit

Permalink
fix err msg
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Aug 26, 2023
1 parent ff0c107 commit a010854
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
1 change: 0 additions & 1 deletion datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ mod test {
}

#[test]
#[allow(clippy::unnecessary_literal_unwrap)]
fn test_make_error_parse_input() {
let res: Result<(), DataFusionError> = plan_err!("Err");
let res = res.unwrap_err();
Expand Down
26 changes: 20 additions & 6 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,17 +645,17 @@ fn replace_nulls_with_coerced_types(
}
}

// Coerce array arguments types for array functions
// Convert type or return error for incompatible types in this step
fn coerce_array_args(
fun: &BuiltinScalarFunction,
expressions: Vec<Expr>,
schema: &DFSchema,
) -> Result<Vec<Expr>> {
// Array function with indices don't need coercion for the indices
if *fun == BuiltinScalarFunction::ArrayElement
|| *fun == BuiltinScalarFunction::ArraySlice
|| *fun == BuiltinScalarFunction::ArrayRepeat
|| *fun == BuiltinScalarFunction::ArrayPosition
|| *fun == BuiltinScalarFunction::ArrayRemoveN
if *fun != BuiltinScalarFunction::MakeArray
&& *fun != BuiltinScalarFunction::ArrayAppend
&& *fun != BuiltinScalarFunction::ArrayPrepend
&& *fun != BuiltinScalarFunction::ArrayConcat
{
return Ok(expressions);
}
Expand All @@ -665,6 +665,20 @@ fn coerce_array_args(
.map(|e| e.get_type(schema))
.collect::<Result<Vec<_>>>()?;

// Check dimensions and align dimensions
// TODO: Move align array dimensions here. Function used in concat, append, prepend.
if *fun == BuiltinScalarFunction::ArrayConcat {
for expr_type in input_types.iter() {
if let DataType::List(_) = expr_type {
continue;
} else {
return plan_err!(
"The array_concat function can only accept list as the args"
);
}
}
}

// Get base type for each input type
// e.g List[Int64] -> Int64
// List[List[Int64]] -> Int64
Expand Down
1 change: 0 additions & 1 deletion datafusion/physical-expr/src/window/cume_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ mod tests {
}

#[test]
#[allow(clippy::single_range_in_vec_init)]
fn test_cume_dist() -> Result<()> {
let r = cume_dist("arr".into());

Expand Down
2 changes: 0 additions & 2 deletions datafusion/physical-expr/src/window/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ mod tests {
test_i32_result(expr, vec![0..2, 2..3, 3..6, 6..7, 7..8], expected)
}

#[allow(clippy::single_range_in_vec_init)]
fn test_without_rank(expr: &Rank, expected: Vec<u64>) -> Result<()> {
test_i32_result(expr, vec![0..8], expected)
}
Expand Down Expand Up @@ -276,7 +275,6 @@ mod tests {
}

#[test]
#[allow(clippy::single_range_in_vec_init)]
fn test_percent_rank() -> Result<()> {
let r = percent_rank("arr".into());

Expand Down
12 changes: 6 additions & 6 deletions datafusion/sql/src/expr/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let data_types = values.iter().map(|e| e.get_datatype()).collect::<Vec<_>>();
let seen_types: HashSet<DataType> =
values.iter().map(|e| e.get_datatype()).collect();
let coerced_type = data_types
.iter()
.skip(1)
.fold(data_types[0].clone(), |acc, d| {
comparison_coercion(&acc, d).unwrap_or(acc)
});

match seen_types.len() {
0 => Ok(lit(ScalarValue::new_list(None, DataType::Utf8))),
Expand All @@ -180,6 +174,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
Ok(lit(ScalarValue::new_list(Some(values), data_type)))
}
_ => {
let coerced_type = data_types
.iter()
.skip(1)
.fold(data_types[0].clone(), |acc, d| {
comparison_coercion(&acc, d).unwrap_or(acc)
});
let values = values
.iter()
.map(|e| {
Expand Down
25 changes: 11 additions & 14 deletions datafusion/sqllogictest/test_files/array.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,9 @@ select array_repeat([1], column3), array_repeat(column1, 3) from arrays_values_w
## array_concat (aliases: `array_cat`, `list_concat`, `list_cat`)

# array_concat error
query error DataFusion error: Error during planning: The array_concat function can only accept list as the args\.
query error DataFusion error: SQL error: ParserError\("Expected an SQL statement, found: caused"\)
caused by
Error during planning: The array_concat function can only accept list as the args\.
select array_concat(1, 2);

# array_concat scalar function #1
Expand Down Expand Up @@ -1293,21 +1295,16 @@ select array_concat(make_array(make_array(1, 2), make_array(3, 4)), make_array(n
----
[[1, 2], [3, 4], []]

query ?
query error DataFusion error: type_coercion\ncaused by\nError during planning: The array_concat function can only accept list as the args
select array_concat(make_array(make_array(1, 2), make_array(3, 4)), null);
----
[[1, 2], [3, 4]]

query ?
select array_concat(make_array(make_array(1, 2), make_array(3, 4)), make_array(5));
----
[[1, 2], [3, 4], [5]]

# TODO: Get error for this query
query ?
query error DataFusion error: type_coercion\ncaused by\nError during planning: The array_concat function can only accept list as the args
select array_concat(make_array(make_array(1, 2), make_array(3, 4)), 5);
----
[[1, 2], [3, 4]]

# array_concat scalar function #8 (with empty arrays)
query ?
Expand Down Expand Up @@ -1815,7 +1812,7 @@ select array_replace_all(make_array([1, 2, 3], [4, 5, 6], [4, 5, 6], [10, 11, 12
query TTT
select array_to_string(['h', 'e', 'l', 'l', 'o'], ','), array_to_string([1, 2, 3, 4, 5], '-'), array_to_string([1.0, 2.0, 3.0], '|');
----
h,e,l,l,o 1-2-3-4-5 1.0|2.0|3.0
h,e,l,l,o 1-2-3-4-5 1|2|3

# array_to_string scalar function #2
query TTT
Expand All @@ -1833,31 +1830,31 @@ select array_to_string(make_array(), ',')
query TTT
select list_to_string(['h', 'e', 'l', 'l', 'o'], ','), list_to_string([1, 2, 3, 4, 5], '-'), list_to_string([1.0, 2.0, 3.0], '|');
----
h,e,l,l,o 1-2-3-4-5 1.0|2.0|3.0
h,e,l,l,o 1-2-3-4-5 1|2|3

# array_join scalar function #5 (function alias `array_to_string`)
query TTT
select array_join(['h', 'e', 'l', 'l', 'o'], ','), array_join([1, 2, 3, 4, 5], '-'), array_join([1.0, 2.0, 3.0], '|');
----
h,e,l,l,o 1-2-3-4-5 1.0|2.0|3.0
h,e,l,l,o 1-2-3-4-5 1|2|3

# list_join scalar function #6 (function alias `list_join`)
query TTT
select list_join(['h', 'e', 'l', 'l', 'o'], ','), list_join([1, 2, 3, 4, 5], '-'), list_join([1.0, 2.0, 3.0], '|');
----
h,e,l,l,o 1-2-3-4-5 1.0|2.0|3.0
h,e,l,l,o 1-2-3-4-5 1|2|3

# array_to_string scalar function with nulls #1
query TTT
select array_to_string(make_array('h', NULL, 'l', NULL, 'o'), ','), array_to_string(make_array(1, NULL, 3, NULL, 5), '-'), array_to_string(make_array(NULL, 2.0, 3.0), '|');
----
h,l,o 1-3-5 2.0|3.0
h,l,o 1-3-5 2|3

# array_to_string scalar function with nulls #2
query TTT
select array_to_string(make_array('h', NULL, NULL, NULL, 'o'), ',', '-'), array_to_string(make_array(NULL, 2, NULL, 4, 5), '-', 'nil'), array_to_string(make_array(1.0, NULL, 3.0), '|', '0');
----
h,-,-,-,o nil-2-nil-4-5 1.0|0|3.0
h,-,-,-,o nil-2-nil-4-5 1|0|3

# array_to_string with columns #1

Expand Down

0 comments on commit a010854

Please sign in to comment.