Skip to content

Commit e3c4541

Browse files
authored
chore: remove unnecessary test helpers (#13317)
* chore: remove unnecessary test helpers * cargo fmt
1 parent cd013c7 commit e3c4541

File tree

1 file changed

+59
-99
lines changed

1 file changed

+59
-99
lines changed

datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs

Lines changed: 59 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,15 +2865,12 @@ mod tests {
28652865
);
28662866

28672867
// single character
2868-
assert_change(
2869-
regex_match(col("c1"), lit("x")),
2870-
like(col("c1"), lit("%x%")),
2871-
);
2868+
assert_change(regex_match(col("c1"), lit("x")), col("c1").like(lit("%x%")));
28722869

28732870
// single word
28742871
assert_change(
28752872
regex_match(col("c1"), lit("foo")),
2876-
like(col("c1"), lit("%foo%")),
2873+
col("c1").like(lit("%foo%")),
28772874
);
28782875

28792876
// regular expressions that match an exact literal
@@ -2963,48 +2960,53 @@ mod tests {
29632960
// regular expressions that match a partial literal
29642961
assert_change(
29652962
regex_match(col("c1"), lit("^foo")),
2966-
like(col("c1"), lit("foo%")),
2963+
col("c1").like(lit("foo%")),
29672964
);
29682965
assert_change(
29692966
regex_match(col("c1"), lit("foo$")),
2970-
like(col("c1"), lit("%foo")),
2967+
col("c1").like(lit("%foo")),
29712968
);
29722969
assert_change(
29732970
regex_match(col("c1"), lit("^foo|bar$")),
2974-
like(col("c1"), lit("foo%")).or(like(col("c1"), lit("%bar"))),
2971+
col("c1").like(lit("foo%")).or(col("c1").like(lit("%bar"))),
29752972
);
29762973

29772974
// OR-chain
29782975
assert_change(
29792976
regex_match(col("c1"), lit("foo|bar|baz")),
2980-
like(col("c1"), lit("%foo%"))
2981-
.or(like(col("c1"), lit("%bar%")))
2982-
.or(like(col("c1"), lit("%baz%"))),
2977+
col("c1")
2978+
.like(lit("%foo%"))
2979+
.or(col("c1").like(lit("%bar%")))
2980+
.or(col("c1").like(lit("%baz%"))),
29832981
);
29842982
assert_change(
29852983
regex_match(col("c1"), lit("foo|x|baz")),
2986-
like(col("c1"), lit("%foo%"))
2987-
.or(like(col("c1"), lit("%x%")))
2988-
.or(like(col("c1"), lit("%baz%"))),
2984+
col("c1")
2985+
.like(lit("%foo%"))
2986+
.or(col("c1").like(lit("%x%")))
2987+
.or(col("c1").like(lit("%baz%"))),
29892988
);
29902989
assert_change(
29912990
regex_not_match(col("c1"), lit("foo|bar|baz")),
2992-
not_like(col("c1"), lit("%foo%"))
2993-
.and(not_like(col("c1"), lit("%bar%")))
2994-
.and(not_like(col("c1"), lit("%baz%"))),
2991+
col("c1")
2992+
.not_like(lit("%foo%"))
2993+
.and(col("c1").not_like(lit("%bar%")))
2994+
.and(col("c1").not_like(lit("%baz%"))),
29952995
);
29962996
// both anchored expressions (translated to equality) and unanchored
29972997
assert_change(
29982998
regex_match(col("c1"), lit("foo|^x$|baz")),
2999-
like(col("c1"), lit("%foo%"))
2999+
col("c1")
3000+
.like(lit("%foo%"))
30003001
.or(col("c1").eq(lit("x")))
3001-
.or(like(col("c1"), lit("%baz%"))),
3002+
.or(col("c1").like(lit("%baz%"))),
30023003
);
30033004
assert_change(
30043005
regex_not_match(col("c1"), lit("foo|^bar$|baz")),
3005-
not_like(col("c1"), lit("%foo%"))
3006+
col("c1")
3007+
.not_like(lit("%foo%"))
30063008
.and(col("c1").not_eq(lit("bar")))
3007-
.and(not_like(col("c1"), lit("%baz%"))),
3009+
.and(col("c1").not_like(lit("%baz%"))),
30083010
);
30093011
// Too many patterns (MAX_REGEX_ALTERNATIONS_EXPANSION)
30103012
assert_no_change(regex_match(col("c1"), lit("foo|bar|baz|blarg|bozo|etc")));
@@ -3054,46 +3056,6 @@ mod tests {
30543056
})
30553057
}
30563058

3057-
fn like(expr: Expr, pattern: impl Into<Expr>) -> Expr {
3058-
Expr::Like(Like {
3059-
negated: false,
3060-
expr: Box::new(expr),
3061-
pattern: Box::new(pattern.into()),
3062-
escape_char: None,
3063-
case_insensitive: false,
3064-
})
3065-
}
3066-
3067-
fn not_like(expr: Expr, pattern: impl Into<Expr>) -> Expr {
3068-
Expr::Like(Like {
3069-
negated: true,
3070-
expr: Box::new(expr),
3071-
pattern: Box::new(pattern.into()),
3072-
escape_char: None,
3073-
case_insensitive: false,
3074-
})
3075-
}
3076-
3077-
fn ilike(expr: Expr, pattern: impl Into<Expr>) -> Expr {
3078-
Expr::Like(Like {
3079-
negated: false,
3080-
expr: Box::new(expr),
3081-
pattern: Box::new(pattern.into()),
3082-
escape_char: None,
3083-
case_insensitive: true,
3084-
})
3085-
}
3086-
3087-
fn not_ilike(expr: Expr, pattern: impl Into<Expr>) -> Expr {
3088-
Expr::Like(Like {
3089-
negated: true,
3090-
expr: Box::new(expr),
3091-
pattern: Box::new(pattern.into()),
3092-
escape_char: None,
3093-
case_insensitive: true,
3094-
})
3095-
}
3096-
30973059
// ------------------------------
30983060
// ----- Simplifier tests -------
30993061
// ------------------------------
@@ -3703,119 +3665,117 @@ mod tests {
37033665
let null = lit(ScalarValue::Utf8(None));
37043666

37053667
// expr [NOT] [I]LIKE NULL
3706-
let expr = like(col("c1"), null.clone());
3668+
let expr = col("c1").like(null.clone());
37073669
assert_eq!(simplify(expr), lit_bool_null());
37083670

3709-
let expr = not_like(col("c1"), null.clone());
3671+
let expr = col("c1").not_like(null.clone());
37103672
assert_eq!(simplify(expr), lit_bool_null());
37113673

3712-
let expr = ilike(col("c1"), null.clone());
3674+
let expr = col("c1").ilike(null.clone());
37133675
assert_eq!(simplify(expr), lit_bool_null());
37143676

3715-
let expr = not_ilike(col("c1"), null.clone());
3677+
let expr = col("c1").not_ilike(null.clone());
37163678
assert_eq!(simplify(expr), lit_bool_null());
37173679

37183680
// expr [NOT] [I]LIKE '%'
3719-
let expr = like(col("c1"), lit("%"));
3681+
let expr = col("c1").like(lit("%"));
37203682
assert_eq!(simplify(expr), if_not_null(col("c1"), true));
37213683

3722-
let expr = not_like(col("c1"), lit("%"));
3684+
let expr = col("c1").not_like(lit("%"));
37233685
assert_eq!(simplify(expr), if_not_null(col("c1"), false));
37243686

3725-
let expr = ilike(col("c1"), lit("%"));
3687+
let expr = col("c1").ilike(lit("%"));
37263688
assert_eq!(simplify(expr), if_not_null(col("c1"), true));
37273689

3728-
let expr = not_ilike(col("c1"), lit("%"));
3690+
let expr = col("c1").not_ilike(lit("%"));
37293691
assert_eq!(simplify(expr), if_not_null(col("c1"), false));
37303692

37313693
// expr [NOT] [I]LIKE '%%'
3732-
let expr = like(col("c1"), lit("%%"));
3694+
let expr = col("c1").like(lit("%%"));
37333695
assert_eq!(simplify(expr), if_not_null(col("c1"), true));
37343696

3735-
let expr = not_like(col("c1"), lit("%%"));
3697+
let expr = col("c1").not_like(lit("%%"));
37363698
assert_eq!(simplify(expr), if_not_null(col("c1"), false));
37373699

3738-
let expr = ilike(col("c1"), lit("%%"));
3700+
let expr = col("c1").ilike(lit("%%"));
37393701
assert_eq!(simplify(expr), if_not_null(col("c1"), true));
37403702

3741-
let expr = not_ilike(col("c1"), lit("%%"));
3703+
let expr = col("c1").not_ilike(lit("%%"));
37423704
assert_eq!(simplify(expr), if_not_null(col("c1"), false));
37433705

37443706
// not_null_expr [NOT] [I]LIKE '%'
3745-
let expr = like(col("c1_non_null"), lit("%"));
3707+
let expr = col("c1_non_null").like(lit("%"));
37463708
assert_eq!(simplify(expr), lit(true));
37473709

3748-
let expr = not_like(col("c1_non_null"), lit("%"));
3710+
let expr = col("c1_non_null").not_like(lit("%"));
37493711
assert_eq!(simplify(expr), lit(false));
37503712

3751-
let expr = ilike(col("c1_non_null"), lit("%"));
3713+
let expr = col("c1_non_null").ilike(lit("%"));
37523714
assert_eq!(simplify(expr), lit(true));
37533715

3754-
let expr = not_ilike(col("c1_non_null"), lit("%"));
3716+
let expr = col("c1_non_null").not_ilike(lit("%"));
37553717
assert_eq!(simplify(expr), lit(false));
37563718

37573719
// not_null_expr [NOT] [I]LIKE '%%'
3758-
let expr = like(col("c1_non_null"), lit("%%"));
3720+
let expr = col("c1_non_null").like(lit("%%"));
37593721
assert_eq!(simplify(expr), lit(true));
37603722

3761-
let expr = not_like(col("c1_non_null"), lit("%%"));
3723+
let expr = col("c1_non_null").not_like(lit("%%"));
37623724
assert_eq!(simplify(expr), lit(false));
37633725

3764-
let expr = ilike(col("c1_non_null"), lit("%%"));
3726+
let expr = col("c1_non_null").ilike(lit("%%"));
37653727
assert_eq!(simplify(expr), lit(true));
37663728

3767-
let expr = not_ilike(col("c1_non_null"), lit("%%"));
3729+
let expr = col("c1_non_null").not_ilike(lit("%%"));
37683730
assert_eq!(simplify(expr), lit(false));
37693731

37703732
// null_constant [NOT] [I]LIKE '%'
3771-
let expr = like(null.clone(), lit("%"));
3733+
let expr = null.clone().like(lit("%"));
37723734
assert_eq!(simplify(expr), lit_bool_null());
37733735

3774-
let expr = not_like(null.clone(), lit("%"));
3736+
let expr = null.clone().not_like(lit("%"));
37753737
assert_eq!(simplify(expr), lit_bool_null());
37763738

3777-
let expr = ilike(null.clone(), lit("%"));
3739+
let expr = null.clone().ilike(lit("%"));
37783740
assert_eq!(simplify(expr), lit_bool_null());
37793741

3780-
let expr = not_ilike(null, lit("%"));
3742+
let expr = null.clone().not_ilike(lit("%"));
37813743
assert_eq!(simplify(expr), lit_bool_null());
37823744

37833745
// null_constant [NOT] [I]LIKE '%%'
3784-
let null = lit(ScalarValue::Utf8(None));
3785-
let expr = like(null.clone(), lit("%%"));
3746+
let expr = null.clone().like(lit("%%"));
37863747
assert_eq!(simplify(expr), lit_bool_null());
37873748

3788-
let expr = not_like(null.clone(), lit("%%"));
3749+
let expr = null.clone().not_like(lit("%%"));
37893750
assert_eq!(simplify(expr), lit_bool_null());
37903751

3791-
let expr = ilike(null.clone(), lit("%%"));
3752+
let expr = null.clone().ilike(lit("%%"));
37923753
assert_eq!(simplify(expr), lit_bool_null());
37933754

3794-
let expr = not_ilike(null, lit("%%"));
3755+
let expr = null.clone().not_ilike(lit("%%"));
37953756
assert_eq!(simplify(expr), lit_bool_null());
37963757

37973758
// null_constant [NOT] [I]LIKE 'a%'
3798-
let null = lit(ScalarValue::Utf8(None));
3799-
let expr = like(null.clone(), lit("a%"));
3759+
let expr = null.clone().like(lit("a%"));
38003760
assert_eq!(simplify(expr), lit_bool_null());
38013761

3802-
let expr = not_like(null.clone(), lit("a%"));
3762+
let expr = null.clone().not_like(lit("a%"));
38033763
assert_eq!(simplify(expr), lit_bool_null());
38043764

3805-
let expr = ilike(null.clone(), lit("a%"));
3765+
let expr = null.clone().ilike(lit("a%"));
38063766
assert_eq!(simplify(expr), lit_bool_null());
38073767

3808-
let expr = not_ilike(null, lit("a%"));
3768+
let expr = null.clone().not_ilike(lit("a%"));
38093769
assert_eq!(simplify(expr), lit_bool_null());
38103770

38113771
// expr [NOT] [I]LIKE with pattern without wildcards
3812-
let expr = like(col("c1"), lit("a"));
3772+
let expr = col("c1").like(lit("a"));
38133773
assert_eq!(simplify(expr), col("c1").eq(lit("a")));
3814-
let expr = not_like(col("c1"), lit("a"));
3774+
let expr = col("c1").not_like(lit("a"));
38153775
assert_eq!(simplify(expr), col("c1").not_eq(lit("a")));
3816-
let expr = like(col("c1"), lit("a_"));
3776+
let expr = col("c1").like(lit("a_"));
38173777
assert_eq!(simplify(expr), col("c1").like(lit("a_")));
3818-
let expr = not_like(col("c1"), lit("a_"));
3778+
let expr = col("c1").not_like(lit("a_"));
38193779
assert_eq!(simplify(expr), col("c1").not_like(lit("a_")));
38203780
}
38213781

0 commit comments

Comments
 (0)