Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions crates/polars-plan/src/plans/aexpr/predicates/column_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pub fn aexpr_to_column_predicates(
options: _,
} if matches!(
str_function,
crate::plans::IRStringFunction::Contains { literal: _, strict: true } |
crate::plans::IRStringFunction::Contains { literal: false, strict: true } |
crate::plans::IRStringFunction::Contains { literal: true, strict: _ } |
crate::plans::IRStringFunction::EndsWith |
crate::plans::IRStringFunction::StartsWith
) => {
Expand Down Expand Up @@ -364,7 +365,7 @@ mod tests {
use polars_error::PolarsResult;

use super::*;
use crate::dsl::{Expr, col};
use crate::dsl::{Expr, col, lit};
use crate::plans::{ExprToIRContext, to_expr_ir, typed_lit};

/// Given a single-column `Expr`, call `aexpr_to_column_predicates()` and
Expand Down Expand Up @@ -420,6 +421,28 @@ mod tests {
Ok(())
}

#[test]
fn column_predicates_string_contains() -> PolarsResult<()> {
let col_name = "testcol";
let test_values: [(Expr, &str); _] = [
(col(col_name).str().contains(lit("x.*y"), true), "x.*y"),
(col(col_name).str().contains_literal(lit("abc")), "abc"),
(
col(col_name).str().contains_literal(lit("x.*y")),
"x\\.\\*y",
),
];
for (expr, expected_regex_string) in test_values {
let predicate = column_predicate_for_expr(DataType::String, col_name, expr.clone())?;
if let Some(SpecializedColumnPredicate::RegexMatch(regex)) = predicate {
assert_eq!(&format!("{regex}"), expected_regex_string);
} else {
panic!("{predicate:?} is unexpected for {expr:?}");
}
}
Ok(())
}

#[test]
fn column_predicate_is_between() -> PolarsResult<()> {
let col_name = "testcol";
Expand Down
Loading