@@ -719,7 +719,7 @@ impl BuiltinScalarFunction {
719
719
utf8_to_str_type ( & input_expr_types[ 0 ] , "initcap" )
720
720
}
721
721
BuiltinScalarFunction :: InStr => {
722
- utf8_to_int_type ( & input_expr_types[ 0 ] , "instr" )
722
+ utf8_to_int_type ( & input_expr_types[ 0 ] , "instr/position " )
723
723
}
724
724
BuiltinScalarFunction :: Left => utf8_to_str_type ( & input_expr_types[ 0 ] , "left" ) ,
725
725
BuiltinScalarFunction :: Lower => {
@@ -822,22 +822,22 @@ impl BuiltinScalarFunction {
822
822
BuiltinScalarFunction :: Upper => {
823
823
utf8_to_str_type ( & input_expr_types[ 0 ] , "upper" )
824
824
}
825
- BuiltinScalarFunction :: RegexpLike => Ok ( match input_expr_types[ 0 ] {
825
+ BuiltinScalarFunction :: RegexpLike => Ok ( match & input_expr_types[ 0 ] {
826
826
LargeUtf8 | Utf8 => Boolean ,
827
827
Null => Null ,
828
- _ => {
828
+ other => {
829
829
return plan_err ! (
830
- "The regexp_like function can only accept strings."
830
+ "The regexp_like function can only accept strings. Got {other} "
831
831
) ;
832
832
}
833
833
} ) ,
834
- BuiltinScalarFunction :: RegexpMatch => Ok ( match input_expr_types[ 0 ] {
834
+ BuiltinScalarFunction :: RegexpMatch => Ok ( match & input_expr_types[ 0 ] {
835
835
LargeUtf8 => List ( Arc :: new ( Field :: new ( "item" , LargeUtf8 , true ) ) ) ,
836
836
Utf8 => List ( Arc :: new ( Field :: new ( "item" , Utf8 , true ) ) ) ,
837
837
Null => Null ,
838
- _ => {
838
+ other => {
839
839
return plan_err ! (
840
- "The regexp_match function can only accept strings."
840
+ "The regexp_match function can only accept strings. Got {other} "
841
841
) ;
842
842
}
843
843
} ) ,
@@ -1644,54 +1644,51 @@ impl FromStr for BuiltinScalarFunction {
1644
1644
}
1645
1645
}
1646
1646
1647
- /// Creates a function that returns the return type of a string function given
1647
+ /// Creates a function to identify the optimal return type of a string function given
1648
1648
/// the type of its first argument.
1649
1649
///
1650
1650
/// If the input type is `LargeUtf8` or `LargeBinary` the return type is
1651
1651
/// `$largeUtf8Type`,
1652
1652
///
1653
1653
/// If the input type is `Utf8` or `Binary` the return type is `$utf8Type`,
1654
- macro_rules! make_utf8_to_return_type {
1654
+ macro_rules! get_optimal_return_type {
1655
1655
( $FUNC: ident, $largeUtf8Type: expr, $utf8Type: expr) => {
1656
1656
fn $FUNC( arg_type: & DataType , name: & str ) -> Result <DataType > {
1657
1657
Ok ( match arg_type {
1658
- DataType :: LargeUtf8 => $largeUtf8Type,
1659
1658
// LargeBinary inputs are automatically coerced to Utf8
1660
- DataType :: LargeBinary => $largeUtf8Type,
1661
- DataType :: Utf8 => $utf8Type,
1659
+ DataType :: LargeUtf8 | DataType :: LargeBinary => $largeUtf8Type,
1662
1660
// Binary inputs are automatically coerced to Utf8
1663
- DataType :: Binary => $utf8Type,
1661
+ DataType :: Utf8 | DataType :: Binary => $utf8Type,
1664
1662
DataType :: Null => DataType :: Null ,
1665
1663
DataType :: Dictionary ( _, value_type) => match * * value_type {
1666
- DataType :: LargeUtf8 => $largeUtf8Type,
1667
- DataType :: LargeBinary => $largeUtf8Type,
1668
- DataType :: Utf8 => $utf8Type,
1669
- DataType :: Binary => $utf8Type,
1664
+ DataType :: LargeUtf8 | DataType :: LargeBinary => $largeUtf8Type,
1665
+ DataType :: Utf8 | DataType :: Binary => $utf8Type,
1670
1666
DataType :: Null => DataType :: Null ,
1671
1667
_ => {
1672
1668
return plan_err!(
1673
- "The {:? } function can only accept strings, but got {:?}." ,
1674
- name,
1669
+ "The {} function can only accept strings, but got {:?}." ,
1670
+ name. to_uppercase ( ) ,
1675
1671
* * value_type
1676
1672
) ;
1677
1673
}
1678
1674
} ,
1679
1675
data_type => {
1680
1676
return plan_err!(
1681
- "The {:? } function can only accept strings, but got {:?}." ,
1682
- name,
1677
+ "The {} function can only accept strings, but got {:?}." ,
1678
+ name. to_uppercase ( ) ,
1683
1679
data_type
1684
1680
) ;
1685
1681
}
1686
1682
} )
1687
1683
}
1688
1684
} ;
1689
1685
}
1686
+
1690
1687
// `utf8_to_str_type`: returns either a Utf8 or LargeUtf8 based on the input type size.
1691
- make_utf8_to_return_type ! ( utf8_to_str_type, DataType :: LargeUtf8 , DataType :: Utf8 ) ;
1688
+ get_optimal_return_type ! ( utf8_to_str_type, DataType :: LargeUtf8 , DataType :: Utf8 ) ;
1692
1689
1693
1690
// `utf8_to_int_type`: returns either a Int32 or Int64 based on the input type size.
1694
- make_utf8_to_return_type ! ( utf8_to_int_type, DataType :: Int64 , DataType :: Int32 ) ;
1691
+ get_optimal_return_type ! ( utf8_to_int_type, DataType :: Int64 , DataType :: Int32 ) ;
1695
1692
1696
1693
fn utf8_or_binary_to_binary_type ( arg_type : & DataType , name : & str ) -> Result < DataType > {
1697
1694
Ok ( match arg_type {
0 commit comments