alamb commented on code in PR #12978:
URL: https://github.com/apache/datafusion/pull/12978#discussion_r1806976558
##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -3443,6 +3545,115 @@ mod tests {
);
}
+ /// Creates a setup for chunk pruning, modeling a utf8 column "s1"
+ /// with 5 different containers (e.g. RowGroups). They have [min,
+ /// max]:
+ /// s1 ["A", "Z"]
+ /// s1 ["A", "L"]
+ /// s1 ["N", "Z"]
+ /// s1 [NULL, NULL]
+ /// s1 ["A", NULL]
+ fn utf8_setup() -> (SchemaRef, TestStatistics) {
+ let schema = Arc::new(Schema::new(vec![Field::new("s1",
DataType::Utf8, true)]));
+
+ let statistics = TestStatistics::new().with(
+ "s1",
+ ContainerStats::new_utf8(
+ vec![Some("A"), Some("A"), Some("N"), Some("M"), None,
Some("A")], // min
+ vec![Some("Z"), Some("L"), Some("Z"), Some("M"), None, None],
// max
+ ),
+ );
+ (schema, statistics)
+ }
+
+ #[test]
+ fn prune_utf8_eq() {
+ let (schema, statistics) = utf8_setup();
+
+ // Expression "s1 = 'A'"
+ // s1 ["A", "Z"] ==> some rows could pass (must keep)
+ // s1 ["A", "L"] ==> some rows could pass (must keep)
+ // s1 ["N", "Z"] ==> no rows can pass (not keep)
+ // s1 ["M", "M"] ==> no rows can pass (not keep)
+ // s1 [NULL, NULL] ==> unknown (must keep)
+ // s1 ["A", NULL] ==> unknown (must keep)
+ let expected_ret = &[true, true, false, false, true, true];
+
+ prune_with_expr(
+ // s1 LIKE 'A%'
+ col("s1").eq(lit("A")),
+ &schema,
+ &statistics,
+ expected_ret,
+ );
+ }
+
+ #[test]
+ fn prune_utf8_like() {
+ let (schema, statistics) = utf8_setup();
+
+ // Expression "s1 LIKE 'A%'"
+ // s1 ["A", "Z"] ==> some rows could pass (must keep)
+ // s1 ["A", "L"] ==> some rows could pass (must keep)
+ // s1 ["N", "Z"] ==> no rows can pass (not keep)
+ // s1 ["M", "M"] ==> no rows can pass (not keep)
+ // s1 [NULL, NULL] ==> unknown (must keep)
+ // s1 ["A", NULL] ==> unknown (must keep)
+ let expected_ret = &[true, true, false, false, true, true];
+
+ prune_with_expr(
+ // s1 LIKE 'A%'
+ col("s1").like(lit("A%")),
+ &schema,
+ &statistics,
+ expected_ret,
+ );
+ }
+
+ #[test]
+ fn prune_utf8_not_like() {
+ let (schema, statistics) = utf8_setup();
+
+ // Expression "s1 NOT LIKE 'M%'"
+ // s1 ["A", "Z"] ==> some rows could pass (must keep)
+ // s1 ["A", "L"] ==> some rows could pass (must keep)
+ // s1 ["N", "Z"] ==> some rows could pass (must keep)
+ // s1 ["M", "M"] ==> no rows can pass (not keep)
+ // s1 [NULL, NULL] ==> unknown (must keep)
+ // s1 ["A", NULL] ==> unknown (must keep)
+ let expected_ret = &[true, true, true, false, true, true];
+
+ prune_with_expr(
+ // s1 NOT LIKE 'M%'
+ col("s1").not_like(lit("M%")),
+ &schema,
+ &statistics,
+ expected_ret,
+ );
+ }
+
+ #[test]
+ fn prune_utf8_like_empty_suffix() {
+ let (schema, statistics) = utf8_setup();
+
+ // Expression "s1 LIKE '%A'"
+ // s1 ["A", "Z"] ==> some rows could pass (must keep)
+ // s1 ["A", "L"] ==> some rows could pass (must keep)
+ // s1 ["N", "Z"] ==> some rows could pass (must keep)
+ // s1 ["M", "M"] ==> some rows could pass (must keep)
+ // s1 [NULL, NULL] ==> unknown (must keep)
+ // s1 ["A", NULL] ==> unknown (must keep)
+ let expected_ret = &[true, true, true, true, true, true];
+
+ prune_with_expr(
+ // s1 LIKE 'A%'
Review Comment:
this one is still wrong
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]