@@ -24,6 +24,8 @@ use vortex_array::Array;
2424use vortex_dtype:: field:: Field ;
2525use vortex_error:: { VortexExpect , VortexResult } ;
2626
27+ pub type ExprRef = Arc < dyn VortexExpr > ;
28+
2729/// Represents logical operation on [`Array`]s
2830pub trait VortexExpr : Debug + Send + Sync + PartialEq < dyn Any > + Display {
2931 /// Convert expression reference to reference of [`Any`] type
@@ -44,13 +46,13 @@ pub trait VortexExpr: Debug + Send + Sync + PartialEq<dyn Any> + Display {
4446}
4547
4648/// Splits top level and operations into separate expressions
47- pub fn split_conjunction ( expr : & Arc < dyn VortexExpr > ) -> Vec < Arc < dyn VortexExpr > > {
49+ pub fn split_conjunction ( expr : & ExprRef ) -> Vec < ExprRef > {
4850 let mut conjunctions = vec ! [ ] ;
4951 split_inner ( expr, & mut conjunctions) ;
5052 conjunctions
5153}
5254
53- fn split_inner ( expr : & Arc < dyn VortexExpr > , exprs : & mut Vec < Arc < dyn VortexExpr > > ) {
55+ fn split_inner ( expr : & ExprRef , exprs : & mut Vec < ExprRef > ) {
5456 match expr. as_any ( ) . downcast_ref :: < BinaryExpr > ( ) {
5557 Some ( bexp) if bexp. op ( ) == Operator :: And => {
5658 split_inner ( bexp. lhs ( ) , exprs) ;
@@ -64,9 +66,9 @@ fn split_inner(expr: &Arc<dyn VortexExpr>, exprs: &mut Vec<Arc<dyn VortexExpr>>)
6466
6567// Taken from apache-datafusion, necessary since you can't require VortexExpr implement PartialEq<dyn VortexExpr>
6668pub fn unbox_any ( any : & dyn Any ) -> & dyn Any {
67- if any. is :: < Arc < dyn VortexExpr > > ( ) {
68- any. downcast_ref :: < Arc < dyn VortexExpr > > ( )
69- . vortex_expect ( "any.is::<Arc<dyn VortexExpr> > returned true but downcast_ref failed" )
69+ if any. is :: < ExprRef > ( ) {
70+ any. downcast_ref :: < ExprRef > ( )
71+ . vortex_expect ( "any.is::<ExprRef > returned true but downcast_ref failed" )
7072 . as_any ( )
7173 } else if any. is :: < Box < dyn VortexExpr > > ( ) {
7274 any. downcast_ref :: < Box < dyn VortexExpr > > ( )
@@ -87,75 +89,78 @@ mod tests {
8789
8890 #[ test]
8991 fn basic_expr_split_test ( ) {
90- let lhs = Arc :: new ( Column :: new ( Field :: Name ( "a" . to_string ( ) ) ) ) as _ ;
91- let rhs = Arc :: new ( Literal :: new ( 1 . into ( ) ) ) as _ ;
92- let expr = Arc :: new ( BinaryExpr :: new ( lhs, Operator :: Eq , rhs) ) as _ ;
92+ let lhs = Column :: new_expr ( Field :: Name ( "a" . to_string ( ) ) ) ;
93+ let rhs = Literal :: new_expr ( 1 . into ( ) ) ;
94+ let expr = BinaryExpr :: new_expr ( lhs, Operator :: Eq , rhs) ;
9395 let conjunction = split_conjunction ( & expr) ;
9496 assert_eq ! ( conjunction. len( ) , 1 ) ;
9597 }
9698
9799 #[ test]
98100 fn basic_conjunction_split_test ( ) {
99- let lhs = Arc :: new ( Column :: new ( Field :: Name ( "a" . to_string ( ) ) ) ) as _ ;
100- let rhs = Arc :: new ( Literal :: new ( 1 . into ( ) ) ) as _ ;
101- let expr = Arc :: new ( BinaryExpr :: new ( lhs, Operator :: And , rhs) ) as _ ;
101+ let lhs = Column :: new_expr ( Field :: Name ( "a" . to_string ( ) ) ) ;
102+ let rhs = Literal :: new_expr ( 1 . into ( ) ) ;
103+ let expr = BinaryExpr :: new_expr ( lhs, Operator :: And , rhs) ;
102104 let conjunction = split_conjunction ( & expr) ;
103105 assert_eq ! ( conjunction. len( ) , 2 , "Conjunction is {conjunction:?}" ) ;
104106 }
105107
106108 #[ test]
107109 fn expr_display ( ) {
108- assert_eq ! ( Column :: new( Field :: Name ( "a" . to_string( ) ) ) . to_string( ) , "$a" ) ;
109- assert_eq ! ( Column :: new( Field :: Index ( 1 ) ) . to_string( ) , "[1]" ) ;
110+ assert_eq ! (
111+ Column :: new_expr( Field :: Name ( "a" . to_string( ) ) ) . to_string( ) ,
112+ "$a"
113+ ) ;
114+ assert_eq ! ( Column :: new_expr( Field :: Index ( 1 ) ) . to_string( ) , "[1]" ) ;
110115 assert_eq ! ( Identity . to_string( ) , "[]" ) ;
111116 assert_eq ! ( Identity . to_string( ) , "[]" ) ;
112117
113- let col1: Arc < dyn VortexExpr > = Arc :: new ( Column :: new ( Field :: Name ( "col1" . to_string ( ) ) ) ) ;
114- let col2: Arc < dyn VortexExpr > = Arc :: new ( Column :: new ( Field :: Name ( "col2" . to_string ( ) ) ) ) ;
118+ let col1: Arc < dyn VortexExpr > = Column :: new_expr ( Field :: Name ( "col1" . to_string ( ) ) ) ;
119+ let col2: Arc < dyn VortexExpr > = Column :: new_expr ( Field :: Name ( "col2" . to_string ( ) ) ) ;
115120 assert_eq ! (
116- BinaryExpr :: new ( col1. clone( ) , Operator :: And , col2. clone( ) ) . to_string( ) ,
121+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: And , col2. clone( ) ) . to_string( ) ,
117122 "($col1 and $col2)"
118123 ) ;
119124 assert_eq ! (
120- BinaryExpr :: new ( col1. clone( ) , Operator :: Or , col2. clone( ) ) . to_string( ) ,
125+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Or , col2. clone( ) ) . to_string( ) ,
121126 "($col1 or $col2)"
122127 ) ;
123128 assert_eq ! (
124- BinaryExpr :: new ( col1. clone( ) , Operator :: Eq , col2. clone( ) ) . to_string( ) ,
129+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Eq , col2. clone( ) ) . to_string( ) ,
125130 "($col1 = $col2)"
126131 ) ;
127132 assert_eq ! (
128- BinaryExpr :: new ( col1. clone( ) , Operator :: NotEq , col2. clone( ) ) . to_string( ) ,
133+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: NotEq , col2. clone( ) ) . to_string( ) ,
129134 "($col1 != $col2)"
130135 ) ;
131136 assert_eq ! (
132- BinaryExpr :: new ( col1. clone( ) , Operator :: Gt , col2. clone( ) ) . to_string( ) ,
137+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Gt , col2. clone( ) ) . to_string( ) ,
133138 "($col1 > $col2)"
134139 ) ;
135140 assert_eq ! (
136- BinaryExpr :: new ( col1. clone( ) , Operator :: Gte , col2. clone( ) ) . to_string( ) ,
141+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Gte , col2. clone( ) ) . to_string( ) ,
137142 "($col1 >= $col2)"
138143 ) ;
139144 assert_eq ! (
140- BinaryExpr :: new ( col1. clone( ) , Operator :: Lt , col2. clone( ) ) . to_string( ) ,
145+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Lt , col2. clone( ) ) . to_string( ) ,
141146 "($col1 < $col2)"
142147 ) ;
143148 assert_eq ! (
144- BinaryExpr :: new ( col1. clone( ) , Operator :: Lte , col2. clone( ) ) . to_string( ) ,
149+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Lte , col2. clone( ) ) . to_string( ) ,
145150 "($col1 <= $col2)"
146151 ) ;
147152
148153 assert_eq ! (
149- BinaryExpr :: new (
150- Arc :: new ( BinaryExpr :: new ( col1. clone( ) , Operator :: Lt , col2. clone( ) ) ) ,
154+ BinaryExpr :: new_expr (
155+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: Lt , col2. clone( ) ) ,
151156 Operator :: Or ,
152- Arc :: new ( BinaryExpr :: new ( col1. clone( ) , Operator :: NotEq , col2. clone( ) ) )
157+ BinaryExpr :: new_expr ( col1. clone( ) , Operator :: NotEq , col2. clone( ) )
153158 )
154159 . to_string( ) ,
155160 "(($col1 < $col2) or ($col1 != $col2))"
156161 ) ;
157162
158- assert_eq ! ( Not :: new ( col1. clone( ) ) . to_string( ) , "!$col1" ) ;
163+ assert_eq ! ( Not :: new_expr ( col1. clone( ) ) . to_string( ) , "!$col1" ) ;
159164
160165 assert_eq ! (
161166 Select :: include( vec![ Field :: Name ( "col1" . to_string( ) ) ] ) . to_string( ) ,
@@ -179,20 +184,23 @@ mod tests {
179184 "Exclude($col1,$col2,[1])"
180185 ) ;
181186
182- assert_eq ! ( Literal :: new( Scalar :: from( 0_u8 ) ) . to_string( ) , "0_u8" ) ;
183- assert_eq ! ( Literal :: new( Scalar :: from( 0.0_f32 ) ) . to_string( ) , "0_f32" ) ;
187+ assert_eq ! ( Literal :: new_expr( Scalar :: from( 0_u8 ) ) . to_string( ) , "0_u8" ) ;
188+ assert_eq ! (
189+ Literal :: new_expr( Scalar :: from( 0.0_f32 ) ) . to_string( ) ,
190+ "0_f32"
191+ ) ;
184192 assert_eq ! (
185- Literal :: new ( Scalar :: from( i64 :: MAX ) ) . to_string( ) ,
193+ Literal :: new_expr ( Scalar :: from( i64 :: MAX ) ) . to_string( ) ,
186194 "9223372036854775807_i64"
187195 ) ;
188- assert_eq ! ( Literal :: new ( Scalar :: from( true ) ) . to_string( ) , "true" ) ;
196+ assert_eq ! ( Literal :: new_expr ( Scalar :: from( true ) ) . to_string( ) , "true" ) ;
189197 assert_eq ! (
190- Literal :: new ( Scalar :: null( DType :: Bool ( Nullability :: Nullable ) ) ) . to_string( ) ,
198+ Literal :: new_expr ( Scalar :: null( DType :: Bool ( Nullability :: Nullable ) ) ) . to_string( ) ,
191199 "null"
192200 ) ;
193201
194202 assert_eq ! (
195- Literal :: new ( Scalar :: new(
203+ Literal :: new_expr ( Scalar :: new(
196204 DType :: Struct (
197205 StructDType :: new(
198206 Arc :: from( [ Arc :: from( "dog" ) , Arc :: from( "cat" ) ] ) ,
0 commit comments