adriangb commented on code in PR #12978:
URL: https://github.com/apache/datafusion/pull/12978#discussion_r1805420707


##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1610,6 +1625,93 @@ fn build_statistics_expr(
     Ok(statistics_expr)
 }
 
+fn extract_string_literal(expr: &Arc<dyn PhysicalExpr>) -> Result<&String> {
+    if let Some(lit) = expr.as_any().downcast_ref::<phys_expr::Literal>() {
+        if let ScalarValue::Utf8(Some(s)) = lit.value() {
+            return Ok(s);
+        }
+    }
+    plan_err!("LIKE expression must be a string literal")
+}
+
+fn extract_like_string_literal_prefix(
+    expr: &Arc<dyn PhysicalExpr>,
+) -> Result<Arc<phys_expr::Literal>> {
+    let s = extract_string_literal(expr)?;
+    let mut split_literal = s.split('%');
+    let prefix = split_literal.next().unwrap_or("");
+    // if the prefix is empty, return true
+    if prefix.is_empty() {
+        return plan_err!("Empty prefix in LIKE expression");
+    }
+    Ok(Arc::new(phys_expr::Literal::new(ScalarValue::Utf8(Some(
+        prefix.to_string(),
+    )))))
+}
+
+fn build_like_match(
+    expr_builder: &mut PruningExpressionBuilder,
+) -> Result<Arc<dyn PhysicalExpr>> {
+    // column LIKE literal => (min, max) LIKE literal split at % => min <= 
split literal && split literal <= max

Review Comment:
   Right that's the point, by splitting it at the first `%` we are able to 
apply the same rules as equality:
   ```
   column LIKE literal -> (min, max) LIKE (literal split at %) -> min <= split 
literal && split literal <= max
   vs
   column = literal -> (min, max) = literal -> min <= literal && literal <= max
   ```



-- 
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]

Reply via email to