@@ -22,7 +22,7 @@ use std::iter::FromIterator;
22
22
use std:: net:: { SocketAddr , ToSocketAddrs } ;
23
23
use url:: Url ;
24
24
25
- use crate :: dataflow:: func:: { AggregateFunc , BinaryFunc , UnaryFunc } ;
25
+ use crate :: dataflow:: func:: { AggregateFunc , BinaryFunc , UnaryFunc , VariadicFunc } ;
26
26
use crate :: dataflow:: {
27
27
Aggregate , Dataflow , Expr , KafkaSinkConnector , KafkaSourceConnector , LocalSourceConnector ,
28
28
Plan , Sink , SinkConnector , Source , SourceConnector , View ,
@@ -1100,7 +1100,7 @@ impl Planner {
1100
1100
}
1101
1101
let ( i, typ) = plan. resolve_func ( name) ;
1102
1102
let expr = Expr :: Column ( i, Box :: new ( Expr :: Ambient ) ) ;
1103
- return Ok ( ( expr, typ. clone ( ) ) )
1103
+ return Ok ( ( expr, typ. clone ( ) ) ) ;
1104
1104
}
1105
1105
1106
1106
match ident. as_str ( ) {
@@ -1116,11 +1116,45 @@ impl Planner {
1116
1116
FType :: Float64 => UnaryFunc :: AbsFloat64 ,
1117
1117
_ => bail ! ( "abs does not accept arguments of type {:?}" , typ) ,
1118
1118
} ;
1119
- Ok ( ( Expr :: CallUnary {
1119
+ let expr = Expr :: CallUnary {
1120
1120
func,
1121
1121
expr : Box :: new ( expr) ,
1122
- } , typ) )
1122
+ } ;
1123
+ Ok ( ( expr, typ) )
1123
1124
}
1125
+
1126
+ "coalesce" => {
1127
+ if args. is_empty ( ) {
1128
+ bail ! ( "coalesce requires at least one argument" ) ;
1129
+ }
1130
+ let mut exprs = Vec :: new ( ) ;
1131
+ let mut result_type: Option < Type > = None ;
1132
+ for arg in args {
1133
+ let ( expr, typ) = self . plan_expr ( ctx, arg, plan) ?;
1134
+ match & result_type {
1135
+ Some ( result_type) => {
1136
+ if result_type. ftype != typ. ftype {
1137
+ bail ! (
1138
+ "COALESCE does not have uniform argument type: {:?} vs {:?}" ,
1139
+ result_type. ftype,
1140
+ typ. ftype
1141
+ )
1142
+ }
1143
+ }
1144
+ None => result_type = Some ( typ) ,
1145
+ }
1146
+ exprs. push ( expr) ;
1147
+ }
1148
+ // args is known to be non-empty, and therefore result_type must
1149
+ // be non-None after the loop above.
1150
+ let result_type = result_type. unwrap ( ) ;
1151
+ let expr = Expr :: CallVariadic {
1152
+ func : VariadicFunc :: Coalesce ,
1153
+ exprs,
1154
+ } ;
1155
+ Ok ( ( expr, result_type) )
1156
+ }
1157
+
1124
1158
_ => bail ! ( "unsupported function: {}" , ident) ,
1125
1159
}
1126
1160
}
0 commit comments