Skip to content

Commit 3e563db

Browse files
authored
feat(cubesql): Holistics - string not contains filter (cube-js#5307)
1 parent 427e846 commit 3e563db

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11023,6 +11023,48 @@ ORDER BY \"COUNT(count)\" DESC"
1102311023
);
1102411024
}
1102511025

11026+
#[tokio::test]
11027+
async fn test_holistics_str_not_contains_filter() {
11028+
init_logger();
11029+
11030+
let logical_plan = convert_select_to_query_plan(
11031+
"SELECT COUNT(\"table\".\"count\") AS \"c_pu_c_d4696e\"
11032+
FROM \"public\".\"KibanaSampleDataEcommerce\" \"table\"
11033+
WHERE NOT(\"table\".\"customer_gender\" ILIKE ('%' || CAST ( 'test' AS text ) || '%'))
11034+
ORDER BY 1 DESC
11035+
LIMIT 100000"
11036+
.to_string(),
11037+
DatabaseProtocol::PostgreSQL,
11038+
)
11039+
.await
11040+
.as_logical_plan();
11041+
11042+
let cube_scan = logical_plan.find_cube_scan();
11043+
11044+
assert_eq!(
11045+
cube_scan.request,
11046+
V1LoadRequestQuery {
11047+
measures: Some(vec!["KibanaSampleDataEcommerce.count".to_string(),]),
11048+
dimensions: Some(vec![]),
11049+
segments: Some(vec![]),
11050+
time_dimensions: None,
11051+
order: Some(vec![vec![
11052+
"KibanaSampleDataEcommerce.count".to_string(),
11053+
"desc".to_string()
11054+
]]),
11055+
limit: Some(50000),
11056+
offset: None,
11057+
filters: Some(vec![V1LoadRequestQueryFilterItem {
11058+
member: Some("KibanaSampleDataEcommerce.customer_gender".to_string()),
11059+
operator: Some("notContains".to_string()),
11060+
values: Some(vec!["test".to_string()]),
11061+
or: None,
11062+
and: None,
11063+
}]),
11064+
}
11065+
);
11066+
}
11067+
1102611068
#[tokio::test]
1102711069
async fn test_select_column_with_same_name_as_table() -> Result<(), CubeError> {
1102811070
init_logger();

rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ impl RewriteRules for FilterRules {
714714
),
715715
self.unwrap_datetrunc("?granularity", "second"),
716716
),
717+
rewrite(
718+
"not-expt-ilike-to-expr-not-ilike",
719+
not_expr(binary_expr("?left", "ILIKE", "?right")),
720+
binary_expr("?left", "NOT_ILIKE", "?right"),
721+
),
717722
rewrite(
718723
"not-expt-like-to-expr-not-like",
719724
not_expr(binary_expr("?left", "LIKE", "?right")),
@@ -1162,6 +1167,7 @@ impl FilterRules {
11621167
Operator::Like => "contains",
11631168
Operator::ILike => "contains",
11641169
Operator::NotLike => "notContains",
1170+
Operator::NotILike => "notContains",
11651171
// TODO: support regex totally
11661172
Operator::RegexMatch => "startsWith",
11671173
_ => {

0 commit comments

Comments
 (0)