@@ -219,7 +219,7 @@ impl<R> Operation<R> {
219
219
F : Fn ( & ExprContext , Vec < ScalarExpr > ) -> Result < R , anyhow:: Error > + Send + Sync + ' static ,
220
220
{
221
221
Self :: new ( move |ecx, spec, cexprs, params| {
222
- let exprs = coerce_args_to_type ( ecx, spec, cexprs, params) ?;
222
+ let exprs = coerce_args_to_types ( ecx, spec, cexprs, params) ?;
223
223
f ( ecx, exprs)
224
224
} )
225
225
}
@@ -894,59 +894,47 @@ fn find_match<'a, R: std::fmt::Debug>(
894
894
)
895
895
}
896
896
897
- /// Generates `ScalarExpr` necessary to coerce `Expr` into the `ScalarType`
898
- /// corresponding to `ParameterType`; errors if not possible. This can only
899
- /// work within the `func` module because it relies on `ParameterType`.
900
- fn coerce_arg_to_type (
897
+ fn coerce_args_to_types (
901
898
ecx : & ExprContext ,
902
899
spec : FuncSpec ,
903
- arg : CoercibleScalarExpr ,
904
- param : & ParamType ,
905
- ) -> Result < ScalarExpr , anyhow:: Error > {
900
+ args : Vec < CoercibleScalarExpr > ,
901
+ params : ParamList ,
902
+ ) -> Result < Vec < ScalarExpr > , anyhow:: Error > {
906
903
use ParamType :: * ;
907
904
use ScalarType :: * ;
908
905
909
- match param {
910
- // Concrete parameter type. Coerce then cast to that type.
911
- Plain ( ty) => {
912
- let arg = typeconv:: plan_coerce ( ecx, arg, ty) ?;
913
- if matches ! ( ty, Decimal ( ..) ) && matches ! ( ecx. scalar_type( & arg) , Decimal ( ..) ) {
914
- // Suppress decimal -> decimal casts, to avoid casting to
915
- // the default decimal scale of 0.
916
- Ok ( arg)
917
- } else {
918
- typeconv:: plan_cast ( spec, ecx, CastContext :: Implicit , arg, ty)
906
+ let mut exprs = Vec :: new ( ) ;
907
+ for ( i, arg) in args. into_iter ( ) . enumerate ( ) {
908
+ let expr = match & params[ i] {
909
+ // Concrete parameter type. Coerce then cast to that type.
910
+ Plain ( ty) => {
911
+ let arg = typeconv:: plan_coerce ( ecx, arg, ty) ?;
912
+ if matches ! ( ty, Decimal ( ..) ) && matches ! ( ecx. scalar_type( & arg) , Decimal ( ..) ) {
913
+ // Suppress decimal -> decimal casts, to avoid casting to
914
+ // the default decimal scale of 0.
915
+ arg
916
+ } else {
917
+ typeconv:: plan_cast ( spec, ecx, CastContext :: Implicit , arg, ty) ?
918
+ }
919
919
}
920
- }
921
920
922
- // Polymorphic pseudotypes. As in PostgreSQL, these bail on
923
- // uncoerced arguments.
924
- ArrayAny | ListAny | ListElementAny | NonVecAny | MapAny => match arg {
925
- CoercibleScalarExpr :: Coerced ( arg) => Ok ( arg) ,
926
- _ => bail ! ( "could not determine polymorphic type because input has type unknown" ) ,
927
- } ,
928
-
929
- // Special "any" psuedotype. Per PostgreSQL, uncoerced literals
930
- // are acceptable, but uncoerced parameters are not.
931
- Any => match arg {
932
- CoercibleScalarExpr :: Parameter ( n) => {
933
- bail ! ( "could not determine data type of parameter ${}" , n)
934
- }
935
- _ => arg. type_as_any ( ecx) ,
936
- } ,
937
- }
938
- }
921
+ // Polymorphic pseudotypes. As in PostgreSQL, these bail on
922
+ // uncoerced arguments.
923
+ ArrayAny | ListAny | ListElementAny | NonVecAny | MapAny => match arg {
924
+ CoercibleScalarExpr :: Coerced ( arg) => arg,
925
+ _ => bail ! ( "could not determine polymorphic type because input has type unknown" ) ,
926
+ } ,
939
927
940
- /// Batch version of `coerce_arg_to_type`.
941
- fn coerce_args_to_type (
942
- ecx : & ExprContext ,
943
- spec : FuncSpec ,
944
- cexprs : Vec < CoercibleScalarExpr > ,
945
- params : ParamList ,
946
- ) -> Result < Vec < ScalarExpr > , anyhow :: Error > {
947
- let mut exprs = Vec :: new ( ) ;
948
- for ( i , cexpr ) in cexprs . into_iter ( ) . enumerate ( ) {
949
- exprs. push ( coerce_arg_to_type ( ecx , spec , cexpr , & params [ i ] ) ? ) ;
928
+ // Special "any" psuedotype. Per PostgreSQL, uncoerced literals
929
+ // are acceptable, but uncoerced parameters are not.
930
+ Any => match arg {
931
+ CoercibleScalarExpr :: Parameter ( n ) => {
932
+ bail ! ( "could not determine data type of parameter ${}" , n )
933
+ }
934
+ _ => arg . type_as_any ( ecx ) ? ,
935
+ } ,
936
+ } ;
937
+ exprs. push ( expr ) ;
950
938
}
951
939
Ok ( exprs)
952
940
}
@@ -1180,7 +1168,7 @@ lazy_static! {
1180
1168
// For consistency with other functions, verify that
1181
1169
// coercion is possible, though we don't actually care about
1182
1170
// the coerced results.
1183
- coerce_args_to_type ( ecx, spec, exprs, params) ?;
1171
+ coerce_args_to_types ( ecx, spec, exprs, params) ?;
1184
1172
1185
1173
// TODO(benesch): make this function have return type
1186
1174
// regtype, when we support that type. Document the function
0 commit comments