diff --git a/datafusion/expr/src/built_in_function.rs b/datafusion/expr/src/built_in_function.rs index e8b4654b97bd9..fe1fc98db92e1 100644 --- a/datafusion/expr/src/built_in_function.rs +++ b/datafusion/expr/src/built_in_function.rs @@ -525,7 +525,7 @@ impl BuiltinScalarFunction { } } _ => { - return internal_err!( + return plan_err!( "The {self} function can only accept list as the args." ) } @@ -542,7 +542,7 @@ impl BuiltinScalarFunction { } BuiltinScalarFunction::ArrayElement => match &input_expr_types[0] { List(field) => Ok(field.data_type().clone()), - _ => internal_err!( + _ => plan_err!( "The {self} function can only accept list as the first argument" ), }, @@ -608,7 +608,7 @@ impl BuiltinScalarFunction { Timestamp(Microsecond, _) => Ok(Timestamp(Microsecond, None)), Timestamp(Millisecond, _) => Ok(Timestamp(Millisecond, None)), Timestamp(Second, _) => Ok(Timestamp(Second, None)), - _ => internal_err!( + _ => plan_err!( "The {self} function can only accept timestamp as the second arg." ), } @@ -677,8 +677,7 @@ impl BuiltinScalarFunction { LargeBinary => LargeUtf8, Null => Null, _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( + return plan_err!( "The encode function can only accept utf8 or binary." ); } @@ -690,8 +689,7 @@ impl BuiltinScalarFunction { LargeBinary => LargeBinary, Null => Null, _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( + return plan_err!( "The decode function can only accept utf8 or binary." ); } @@ -709,10 +707,7 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::ToHex => Ok(match input_expr_types[0] { Int8 | Int16 | Int32 | Int64 => Utf8, _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( - "The to_hex function can only accept integers." - ); + return plan_err!("The to_hex function can only accept integers."); } }), BuiltinScalarFunction::ToTimestamp => Ok(Timestamp(Nanosecond, None)), @@ -737,8 +732,7 @@ impl BuiltinScalarFunction { Utf8 => List(Arc::new(Field::new("item", Utf8, true))), Null => Null, _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( + return plan_err!( "The regexp_extract function can only accept strings." ); } @@ -1400,7 +1394,6 @@ macro_rules! make_utf8_to_return_type { DataType::Utf8 => $utf8Type, DataType::Null => DataType::Null, _ => { - // this error is internal as `data_types` should have captured this. return plan_err!( "The {:?} function can only accept strings, but got {:?}.", name, @@ -1409,7 +1402,6 @@ macro_rules! make_utf8_to_return_type { } }, data_type => { - // this error is internal as `data_types` should have captured this. return plan_err!( "The {:?} function can only accept strings, but got {:?}.", name, @@ -1432,8 +1424,7 @@ fn utf8_or_binary_to_binary_type(arg_type: &DataType, name: &str) -> Result DataType::Binary, DataType::Null => DataType::Null, _ => { - // this error is internal as `data_types` should have captured this. - return internal_err!( + return plan_err!( "The {name:?} function can only accept strings or binary arrays." ); } diff --git a/datafusion/sqllogictest/test_files/array.slt b/datafusion/sqllogictest/test_files/array.slt index eb949c4f8693b..3b958524a8786 100644 --- a/datafusion/sqllogictest/test_files/array.slt +++ b/datafusion/sqllogictest/test_files/array.slt @@ -600,6 +600,11 @@ from arrays_values_without_nulls; ## array_element (aliases: array_extract, list_extract, list_element) +# array_element error +query error DataFusion error: Error during planning: The array_element function can only accept list as the first argument +select array_element(1, 2); + + # array_element scalar function #1 (with positive index) query IT select array_element(make_array(1, 2, 3, 4, 5), 2), array_element(make_array('h', 'e', 'l', 'l', 'o'), 3); @@ -1098,6 +1103,10 @@ 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\. +select array_concat(1, 2); + # array_concat scalar function #1 query ?? select array_concat(make_array(1, 2, 3), make_array(4, 5, 6), make_array(7, 8, 9)), array_concat(make_array([1], [2]), make_array([3], [4])); @@ -2008,6 +2017,11 @@ NULL 10 ## array_dims (aliases: `list_dims`) +# array dims error +# TODO this is a separate bug +query error Internal error: could not cast value to arrow_array::array::list_array::GenericListArray\. +select array_dims(1); + # array_dims scalar function query ??? select array_dims(make_array(1, 2, 3)), array_dims(make_array([1, 2], [3, 4])), array_dims(make_array([[[[1], [2]]]])); diff --git a/datafusion/sqllogictest/test_files/encoding.slt b/datafusion/sqllogictest/test_files/encoding.slt index b16ceebd6debf..dcbf238b5f25b 100644 --- a/datafusion/sqllogictest/test_files/encoding.slt +++ b/datafusion/sqllogictest/test_files/encoding.slt @@ -27,6 +27,24 @@ CREATE TABLE test( (2, NULL, NULL, NULL) ; +# errors +query error DataFusion error: Error during planning: The encode function can only accept utf8 or binary\. +select encode(12, 'hex') + +query error DataFusion error: Error during planning: There is no built\-in encoding named 'non_encoding', currently supported encodings are: base64, hex +select encode(bin_field, 'non_encoding') from test; + +query error DataFusion error: Error during planning: The decode function can only accept utf8 or binary\. +select decode(12, 'hex') + +query error DataFusion error: Error during planning: There is no built\-in encoding named 'non_encoding', currently supported encodings are: base64, hex +select decode(hex_field, 'non_encoding') from test; + +query error DataFusion error: SQL error: ParserError\("Expected an SQL statement, found: Candidate"\) + Candidate functions: + to_hex\(Int64\) +select to_hex(hex_field) from test; + # Arrays tests query T SELECT encode(bin_field, 'hex') FROM test ORDER BY num; @@ -48,3 +66,10 @@ SELECT arrow_cast(decode(hex_field, 'hex'), 'Utf8') FROM test ORDER BY num; abc qweqwe NULL + +query T +select to_hex(num) from test ORDER BY num; +---- +0 +1 +2 diff --git a/datafusion/sqllogictest/test_files/predicates.slt b/datafusion/sqllogictest/test_files/predicates.slt index 2bd20b8106855..aa233115b5221 100644 --- a/datafusion/sqllogictest/test_files/predicates.slt +++ b/datafusion/sqllogictest/test_files/predicates.slt @@ -192,6 +192,10 @@ statement ok CREATE TABLE IF NOT EXISTS test AS VALUES('foo'),('Barrr'),('Bazzz'),('ZZZZZ'); # async fn test_regexp_is_match +query error Error during planning: Cannot infer common argument type for regex operation Int64 \~ Utf8 +SELECT * FROM test WHERE 12 ~ 'z' + + query T SELECT * FROM test WHERE column1 ~ 'z' ---- diff --git a/datafusion/sqllogictest/test_files/timestamps.slt b/datafusion/sqllogictest/test_files/timestamps.slt index 72f168e014120..abb74b468e8f5 100644 --- a/datafusion/sqllogictest/test_files/timestamps.slt +++ b/datafusion/sqllogictest/test_files/timestamps.slt @@ -390,6 +390,10 @@ select to_timestamp_seconds(cast (1 as int)); ## test date_bin function ########## +# invalid second arg type +query error DataFusion error: Error during planning: No function matches the given name and argument types 'date_bin\(Interval\(MonthDayNano\), Int64, Timestamp\(Nanosecond, None\)\)'\. +SELECT DATE_BIN(INTERVAL '0 second', 25, TIMESTAMP '1970-01-01T00:00:00Z') + # not support interval 0 statement error Execution error: DATE_BIN stride must be non-zero SELECT DATE_BIN(INTERVAL '0 second', TIMESTAMP '2022-08-03 14:38:50.000000006Z', TIMESTAMP '1970-01-01T00:00:00Z')