@@ -870,37 +870,7 @@ impl LogicalPlan {
870
870
LogicalPlan :: Filter { .. } => {
871
871
assert_eq ! ( 1 , expr. len( ) ) ;
872
872
let predicate = expr. pop ( ) . unwrap ( ) ;
873
-
874
- // filter predicates should not contain aliased expressions so we remove any aliases
875
- // before this logic was added we would have aliases within filters such as for
876
- // benchmark q6:
877
- //
878
- // lineitem.l_shipdate >= Date32(\"8766\")
879
- // AND lineitem.l_shipdate < Date32(\"9131\")
880
- // AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount >=
881
- // Decimal128(Some(49999999999999),30,15)
882
- // AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount <=
883
- // Decimal128(Some(69999999999999),30,15)
884
- // AND lineitem.l_quantity < Decimal128(Some(2400),15,2)
885
-
886
- let predicate = predicate
887
- . transform_down ( |expr| {
888
- match expr {
889
- Expr :: Exists { .. }
890
- | Expr :: ScalarSubquery ( _)
891
- | Expr :: InSubquery ( _) => {
892
- // subqueries could contain aliases so we don't recurse into those
893
- Ok ( Transformed :: new ( expr, false , TreeNodeRecursion :: Jump ) )
894
- }
895
- Expr :: Alias ( _) => Ok ( Transformed :: new (
896
- expr. unalias ( ) ,
897
- true ,
898
- TreeNodeRecursion :: Jump ,
899
- ) ) ,
900
- _ => Ok ( Transformed :: no ( expr) ) ,
901
- }
902
- } )
903
- . data ( ) ?;
873
+ let predicate = Filter :: remove_aliases ( predicate) ?. data ;
904
874
905
875
Filter :: try_new ( predicate, Arc :: new ( inputs. swap_remove ( 0 ) ) )
906
876
. map ( LogicalPlan :: Filter )
@@ -2230,6 +2200,38 @@ impl Filter {
2230
2200
}
2231
2201
false
2232
2202
}
2203
+
2204
+ /// Remove aliases from a predicate for use in a `Filter`
2205
+ ///
2206
+ /// filter predicates should not contain aliased expressions so we remove
2207
+ /// any aliases.
2208
+ ///
2209
+ /// before this logic was added we would have aliases within filters such as
2210
+ /// for benchmark q6:
2211
+ ///
2212
+ /// ```sql
2213
+ /// lineitem.l_shipdate >= Date32(\"8766\")
2214
+ /// AND lineitem.l_shipdate < Date32(\"9131\")
2215
+ /// AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount >=
2216
+ /// Decimal128(Some(49999999999999),30,15)
2217
+ /// AND CAST(lineitem.l_discount AS Decimal128(30, 15)) AS lineitem.l_discount <=
2218
+ /// Decimal128(Some(69999999999999),30,15)
2219
+ /// AND lineitem.l_quantity < Decimal128(Some(2400),15,2)
2220
+ /// ```
2221
+ pub fn remove_aliases ( predicate : Expr ) -> Result < Transformed < Expr > > {
2222
+ predicate. transform_down ( |expr| {
2223
+ match expr {
2224
+ Expr :: Exists { .. } | Expr :: ScalarSubquery ( _) | Expr :: InSubquery ( _) => {
2225
+ // subqueries could contain aliases so we don't recurse into those
2226
+ Ok ( Transformed :: new ( expr, false , TreeNodeRecursion :: Jump ) )
2227
+ }
2228
+ Expr :: Alias ( Alias { expr, .. } ) => {
2229
+ Ok ( Transformed :: new ( * expr, true , TreeNodeRecursion :: Jump ) )
2230
+ }
2231
+ _ => Ok ( Transformed :: no ( expr) ) ,
2232
+ }
2233
+ } )
2234
+ }
2233
2235
}
2234
2236
2235
2237
/// Window its input based on a set of window spec and window function (e.g. SUM or RANK)
0 commit comments