@@ -39,7 +39,7 @@ use datafusion_common::{
39
39
use datafusion_functions_window_common:: field:: WindowUDFFieldArgs ;
40
40
use sqlparser:: ast:: {
41
41
display_comma_separated, ExceptSelectItem , ExcludeSelectItem , IlikeSelectItem ,
42
- NullTreatment , OrderByExpr , OrderByOptions , RenameSelectItem , ReplaceSelectElement ,
42
+ NullTreatment , RenameSelectItem , ReplaceSelectElement ,
43
43
} ;
44
44
45
45
/// Represents logical expressions such as `A + 1`, or `CAST(c1 AS int)`.
@@ -701,24 +701,6 @@ impl TryCast {
701
701
}
702
702
}
703
703
704
- /// OrderBy Expressions
705
- pub enum OrderByExprs {
706
- OrderByExprVec ( Vec < OrderByExpr > ) ,
707
- All {
708
- exprs : Vec < Expr > ,
709
- options : OrderByOptions ,
710
- } ,
711
- }
712
-
713
- impl OrderByExprs {
714
- pub fn is_empty ( & self ) -> bool {
715
- match self {
716
- OrderByExprs :: OrderByExprVec ( exprs) => exprs. is_empty ( ) ,
717
- OrderByExprs :: All { exprs, .. } => exprs. is_empty ( ) ,
718
- }
719
- }
720
- }
721
-
722
704
/// SORT expression
723
705
#[ derive( Clone , PartialEq , Eq , PartialOrd , Hash , Debug ) ]
724
706
pub struct Sort {
@@ -1765,38 +1747,23 @@ impl Expr {
1765
1747
pub fn infer_placeholder_types ( self , schema : & DFSchema ) -> Result < ( Expr , bool ) > {
1766
1748
let mut has_placeholder = false ;
1767
1749
self . transform ( |mut expr| {
1768
- match & mut expr {
1769
- // Default to assuming the arguments are the same type
1770
- Expr :: BinaryExpr ( BinaryExpr { left, op : _, right } ) => {
1771
- rewrite_placeholder ( left. as_mut ( ) , right. as_ref ( ) , schema) ?;
1772
- rewrite_placeholder ( right. as_mut ( ) , left. as_ref ( ) , schema) ?;
1773
- }
1774
- Expr :: Between ( Between {
1775
- expr,
1776
- negated : _,
1777
- low,
1778
- high,
1779
- } ) => {
1780
- rewrite_placeholder ( low. as_mut ( ) , expr. as_ref ( ) , schema) ?;
1781
- rewrite_placeholder ( high. as_mut ( ) , expr. as_ref ( ) , schema) ?;
1782
- }
1783
- Expr :: InList ( InList {
1784
- expr,
1785
- list,
1786
- negated : _,
1787
- } ) => {
1788
- for item in list. iter_mut ( ) {
1789
- rewrite_placeholder ( item, expr. as_ref ( ) , schema) ?;
1790
- }
1791
- }
1792
- Expr :: Like ( Like { expr, pattern, .. } )
1793
- | Expr :: SimilarTo ( Like { expr, pattern, .. } ) => {
1794
- rewrite_placeholder ( pattern. as_mut ( ) , expr. as_ref ( ) , schema) ?;
1795
- }
1796
- Expr :: Placeholder ( _) => {
1797
- has_placeholder = true ;
1798
- }
1799
- _ => { }
1750
+ // Default to assuming the arguments are the same type
1751
+ if let Expr :: BinaryExpr ( BinaryExpr { left, op : _, right } ) = & mut expr {
1752
+ rewrite_placeholder ( left. as_mut ( ) , right. as_ref ( ) , schema) ?;
1753
+ rewrite_placeholder ( right. as_mut ( ) , left. as_ref ( ) , schema) ?;
1754
+ } ;
1755
+ if let Expr :: Between ( Between {
1756
+ expr,
1757
+ negated : _,
1758
+ low,
1759
+ high,
1760
+ } ) = & mut expr
1761
+ {
1762
+ rewrite_placeholder ( low. as_mut ( ) , expr. as_ref ( ) , schema) ?;
1763
+ rewrite_placeholder ( high. as_mut ( ) , expr. as_ref ( ) , schema) ?;
1764
+ }
1765
+ if let Expr :: Placeholder ( _) = & expr {
1766
+ has_placeholder = true ;
1800
1767
}
1801
1768
Ok ( Transformed :: yes ( expr) )
1802
1769
} )
@@ -3218,117 +3185,10 @@ mod test {
3218
3185
case, lit, qualified_wildcard, wildcard, wildcard_with_options, ColumnarValue ,
3219
3186
ScalarFunctionArgs , ScalarUDF , ScalarUDFImpl , Volatility ,
3220
3187
} ;
3221
- use arrow:: datatypes:: { Field , Schema } ;
3222
3188
use sqlparser:: ast;
3223
3189
use sqlparser:: ast:: { Ident , IdentWithAlias } ;
3224
3190
use std:: any:: Any ;
3225
3191
3226
- #[ test]
3227
- fn infer_placeholder_in_clause ( ) {
3228
- // SELECT * FROM employees WHERE department_id IN ($1, $2, $3);
3229
- let column = col ( "department_id" ) ;
3230
- let param_placeholders = vec ! [
3231
- Expr :: Placeholder ( Placeholder {
3232
- id: "$1" . to_string( ) ,
3233
- data_type: None ,
3234
- } ) ,
3235
- Expr :: Placeholder ( Placeholder {
3236
- id: "$2" . to_string( ) ,
3237
- data_type: None ,
3238
- } ) ,
3239
- Expr :: Placeholder ( Placeholder {
3240
- id: "$3" . to_string( ) ,
3241
- data_type: None ,
3242
- } ) ,
3243
- ] ;
3244
- let in_list = Expr :: InList ( InList {
3245
- expr : Box :: new ( column) ,
3246
- list : param_placeholders,
3247
- negated : false ,
3248
- } ) ;
3249
-
3250
- let schema = Arc :: new ( Schema :: new ( vec ! [
3251
- Field :: new( "name" , DataType :: Utf8 , true ) ,
3252
- Field :: new( "department_id" , DataType :: Int32 , true ) ,
3253
- ] ) ) ;
3254
- let df_schema = DFSchema :: try_from ( schema) . unwrap ( ) ;
3255
-
3256
- let ( inferred_expr, contains_placeholder) =
3257
- in_list. infer_placeholder_types ( & df_schema) . unwrap ( ) ;
3258
-
3259
- assert ! ( contains_placeholder) ;
3260
-
3261
- match inferred_expr {
3262
- Expr :: InList ( in_list) => {
3263
- for expr in in_list. list {
3264
- match expr {
3265
- Expr :: Placeholder ( placeholder) => {
3266
- assert_eq ! (
3267
- placeholder. data_type,
3268
- Some ( DataType :: Int32 ) ,
3269
- "Placeholder {} should infer Int32" ,
3270
- placeholder. id
3271
- ) ;
3272
- }
3273
- _ => panic ! ( "Expected Placeholder expression" ) ,
3274
- }
3275
- }
3276
- }
3277
- _ => panic ! ( "Expected InList expression" ) ,
3278
- }
3279
- }
3280
-
3281
- #[ test]
3282
- fn infer_placeholder_like_and_similar_to ( ) {
3283
- // name LIKE $1
3284
- let schema =
3285
- Arc :: new ( Schema :: new ( vec ! [ Field :: new( "name" , DataType :: Utf8 , true ) ] ) ) ;
3286
- let df_schema = DFSchema :: try_from ( schema) . unwrap ( ) ;
3287
-
3288
- let like = Like {
3289
- expr : Box :: new ( col ( "name" ) ) ,
3290
- pattern : Box :: new ( Expr :: Placeholder ( Placeholder {
3291
- id : "$1" . to_string ( ) ,
3292
- data_type : None ,
3293
- } ) ) ,
3294
- negated : false ,
3295
- case_insensitive : false ,
3296
- escape_char : None ,
3297
- } ;
3298
-
3299
- let expr = Expr :: Like ( like. clone ( ) ) ;
3300
-
3301
- let ( inferred_expr, _) = expr. infer_placeholder_types ( & df_schema) . unwrap ( ) ;
3302
- match inferred_expr {
3303
- Expr :: Like ( like) => match * like. pattern {
3304
- Expr :: Placeholder ( placeholder) => {
3305
- assert_eq ! ( placeholder. data_type, Some ( DataType :: Utf8 ) ) ;
3306
- }
3307
- _ => panic ! ( "Expected Placeholder" ) ,
3308
- } ,
3309
- _ => panic ! ( "Expected Like" ) ,
3310
- }
3311
-
3312
- // name SIMILAR TO $1
3313
- let expr = Expr :: SimilarTo ( like) ;
3314
-
3315
- let ( inferred_expr, _) = expr. infer_placeholder_types ( & df_schema) . unwrap ( ) ;
3316
- match inferred_expr {
3317
- Expr :: SimilarTo ( like) => match * like. pattern {
3318
- Expr :: Placeholder ( placeholder) => {
3319
- assert_eq ! (
3320
- placeholder. data_type,
3321
- Some ( DataType :: Utf8 ) ,
3322
- "Placeholder {} should infer Utf8" ,
3323
- placeholder. id
3324
- ) ;
3325
- }
3326
- _ => panic ! ( "Expected Placeholder expression" ) ,
3327
- } ,
3328
- _ => panic ! ( "Expected SimilarTo expression" ) ,
3329
- }
3330
- }
3331
-
3332
3192
#[ test]
3333
3193
#[ allow( deprecated) ]
3334
3194
fn format_case_when ( ) -> Result < ( ) > {
0 commit comments