@@ -23,22 +23,20 @@ pub fn unresolved_to_daft_expr(f: &UnresolvedFunction) -> eyre::Result<daft_dsl:
23
23
}
24
24
25
25
match function_name. as_str ( ) {
26
- "count" => handle_count ( arguments) . wrap_err ( "Failed to handle count function" ) ,
27
- "<" => handle_binary_op ( arguments, daft_dsl:: Operator :: Lt )
28
- . wrap_err ( "Failed to handle < function" ) ,
29
- ">" => handle_binary_op ( arguments, daft_dsl:: Operator :: Gt )
30
- . wrap_err ( "Failed to handle > function" ) ,
31
- "<=" => handle_binary_op ( arguments, daft_dsl:: Operator :: LtEq )
32
- . wrap_err ( "Failed to handle <= function" ) ,
33
- ">=" => handle_binary_op ( arguments, daft_dsl:: Operator :: GtEq )
34
- . wrap_err ( "Failed to handle >= function" ) ,
35
- "%" => handle_binary_op ( arguments, daft_dsl:: Operator :: Modulus )
36
- . wrap_err ( "Failed to handle % function" ) ,
37
- "sum" => handle_sum ( arguments) . wrap_err ( "Failed to handle sum function" ) ,
38
- "isnotnull" => handle_isnotnull ( arguments) . wrap_err ( "Failed to handle isnotnull function" ) ,
39
- "isnull" => handle_isnull ( arguments) . wrap_err ( "Failed to handle isnull function" ) ,
40
- n => bail ! ( "Unresolved function {n} not yet supported" ) ,
26
+ "%" => handle_binary_op ( arguments, daft_dsl:: Operator :: Modulus ) ,
27
+ "<" => handle_binary_op ( arguments, daft_dsl:: Operator :: Lt ) ,
28
+ "<=" => handle_binary_op ( arguments, daft_dsl:: Operator :: LtEq ) ,
29
+ "==" => handle_binary_op ( arguments, daft_dsl:: Operator :: Eq ) ,
30
+ ">" => handle_binary_op ( arguments, daft_dsl:: Operator :: Gt ) ,
31
+ ">=" => handle_binary_op ( arguments, daft_dsl:: Operator :: GtEq ) ,
32
+ "count" => handle_count ( arguments) ,
33
+ "isnotnull" => handle_isnotnull ( arguments) ,
34
+ "isnull" => handle_isnull ( arguments) ,
35
+ "not" => not ( arguments) ,
36
+ "sum" => handle_sum ( arguments) ,
37
+ n => bail ! ( "Unresolved function {n:?} not yet supported" ) ,
41
38
}
39
+ . wrap_err_with ( || format ! ( "Failed to handle function {function_name:?}" ) )
42
40
}
43
41
44
42
pub fn handle_sum ( arguments : Vec < daft_dsl:: ExprRef > ) -> eyre:: Result < daft_dsl:: ExprRef > {
@@ -53,6 +51,25 @@ pub fn handle_sum(arguments: Vec<daft_dsl::ExprRef>) -> eyre::Result<daft_dsl::E
53
51
Ok ( arg. sum ( ) )
54
52
}
55
53
54
+ /// If the arguments are exactly one, return it. Otherwise, return an error.
55
+ pub fn to_single ( arguments : Vec < daft_dsl:: ExprRef > ) -> eyre:: Result < daft_dsl:: ExprRef > {
56
+ let arguments: [ daft_dsl:: ExprRef ; 1 ] = match arguments. try_into ( ) {
57
+ Ok ( arguments) => arguments,
58
+ Err ( arguments) => {
59
+ bail ! ( "requires exactly one argument; got {arguments:?}" ) ;
60
+ }
61
+ } ;
62
+
63
+ let [ arg] = arguments;
64
+
65
+ Ok ( arg)
66
+ }
67
+
68
+ pub fn not ( arguments : Vec < daft_dsl:: ExprRef > ) -> eyre:: Result < daft_dsl:: ExprRef > {
69
+ let arg = to_single ( arguments) ?;
70
+ Ok ( arg. not ( ) )
71
+ }
72
+
56
73
pub fn handle_binary_op (
57
74
arguments : Vec < daft_dsl:: ExprRef > ,
58
75
op : daft_dsl:: Operator ,
0 commit comments