diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs index 6836713d8016..bf3bd07949ce 100644 --- a/datafusion/expr/src/type_coercion/functions.rs +++ b/datafusion/expr/src/type_coercion/functions.rs @@ -44,7 +44,9 @@ pub fn data_types_with_scalar_udf( current_types: &[DataType], func: &ScalarUDF, ) -> Result> { + println!("func - {:?}", func); let signature = func.signature(); + println!("sig - {:?}", signature); if current_types.is_empty() { if signature.type_signature.supports_zero_argument() { @@ -56,6 +58,7 @@ pub fn data_types_with_scalar_udf( let valid_types = get_valid_types_with_scalar_udf(&signature.type_signature, current_types, func)?; + println!("validT - {:?}", valid_types); if valid_types .iter() @@ -544,11 +547,20 @@ fn get_valid_types( for (current_type, target_type) in current_types.iter().zip(target_types.iter()) { + println!("curT - {:?}", current_type); + println!("targetT - {:?}", target_type); let logical_type: NativeType = current_type.into(); let target_logical_type = target_type.native(); + println!("cur_logiT - {:?}", logical_type); + println!("target_logiT - {:?}", target_logical_type); if can_coerce_to(&logical_type, target_logical_type) { - let target_type = - target_logical_type.default_cast_for(current_type)?; + let target_type = if &logical_type == target_logical_type { + current_type.clone() + } else { + target_logical_type.default_cast_for(current_type)? + }; + // let target_type = target_logical_type.default_cast_for(current_type)?; + println!("new targetT - {:?}", target_type); new_types.push(target_type); } } diff --git a/datafusion/sqllogictest/test_files/jctest.slt b/datafusion/sqllogictest/test_files/jctest.slt new file mode 100644 index 000000000000..a3d6fb40ff1f --- /dev/null +++ b/datafusion/sqllogictest/test_files/jctest.slt @@ -0,0 +1,4 @@ +query T +SELECT left(arrow_cast('abcde', 'Dictionary(Int32, Utf8)'), -2) +---- +abc \ No newline at end of file diff --git a/datafusion/sqllogictest/test_files/scalar.slt b/datafusion/sqllogictest/test_files/scalar.slt index 3370bd854c7d..fe7d1a90c5bd 100644 --- a/datafusion/sqllogictest/test_files/scalar.slt +++ b/datafusion/sqllogictest/test_files/scalar.slt @@ -1864,10 +1864,10 @@ query TT EXPLAIN SELECT letter, letter = LEFT(letter2, 1) FROM simple_string; ---- logical_plan -01)Projection: simple_string.letter, simple_string.letter = left(CAST(simple_string.letter2 AS Utf8View), Int64(1)) +01)Projection: simple_string.letter, simple_string.letter = left(simple_string.letter2, Int64(1)) 02)--TableScan: simple_string projection=[letter, letter2] physical_plan -01)ProjectionExec: expr=[letter@0 as letter, letter@0 = left(CAST(letter2@1 AS Utf8View), 1) as simple_string.letter = left(simple_string.letter2,Int64(1))] +01)ProjectionExec: expr=[letter@0 as letter, letter@0 = left(letter2@1, 1) as simple_string.letter = left(simple_string.letter2,Int64(1))] 02)--MemoryExec: partitions=1, partition_sizes=[1] query TB diff --git a/datafusion/sqllogictest/test_files/string/string_view.slt b/datafusion/sqllogictest/test_files/string/string_view.slt index 75be03278df0..2f4af80a9257 100644 --- a/datafusion/sqllogictest/test_files/string/string_view.slt +++ b/datafusion/sqllogictest/test_files/string/string_view.slt @@ -663,7 +663,7 @@ EXPLAIN SELECT FROM test; ---- logical_plan -01)Projection: lpad(test.column1_utf8view, Int64(12), Utf8View(" ")) AS c1 +01)Projection: lpad(test.column1_utf8view, Int64(12), Utf8(" ")) AS c1 02)--TableScan: test projection=[column1_utf8view] query TT @@ -672,7 +672,7 @@ EXPLAIN SELECT FROM test; ---- logical_plan -01)Projection: lpad(test.column1_utf8view, Int64(12), CAST(test.column2_large_utf8 AS Utf8View)) AS c1 +01)Projection: lpad(test.column1_utf8view, Int64(12), test.column2_large_utf8) AS c1 02)--TableScan: test projection=[column2_large_utf8, column1_utf8view] query TT @@ -826,7 +826,7 @@ EXPLAIN SELECT FROM test; ---- logical_plan -01)Projection: rpad(test.column1_utf8view, Int64(12), CAST(test.column2_large_utf8 AS Utf8View)) AS c1 +01)Projection: rpad(test.column1_utf8view, Int64(12), test.column2_large_utf8) AS c1 02)--TableScan: test projection=[column2_large_utf8, column1_utf8view] query TT