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


##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -1610,6 +1624,74 @@ fn build_statistics_expr(
     Ok(statistics_expr)
 }
 
+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
+    // column LIKE 'foo%' => min <= 'foo' && 'foo' <= max
+    // column LIKE '%foo' => min <= '' && '' <= max => true
+    // column LIKE '%foo%' => min <= '' && '' <= max => true
+    // column LIKE 'foo' => min <= 'foo' && 'foo' <= max
+
+    fn unpack_string(s: &ScalarValue) -> Result<&String> {
+        match s {
+            ScalarValue::Utf8(Some(s)) => Ok(s),
+            ScalarValue::LargeUtf8(Some(s)) => Ok(s),
+            ScalarValue::Utf8View(Some(s)) => Ok(s),
+            ScalarValue::Dictionary(_, value) => unpack_string(value),
+            _ => plan_err!("LIKE expression must be a string literal"),
+        }
+    }
+
+    fn extract_string_literal(expr: &Arc<dyn PhysicalExpr>) -> Result<&String> 
{
+        if let Some(lit) = expr.as_any().downcast_ref::<phys_expr::Literal>() {
+            let s = unpack_string(lit.value())?;
+            return Ok(s);
+        }
+        plan_err!("LIKE expression must be a string literal")

Review Comment:
   These errors don't get surfaced to users. They get handled within this 
module, becoming `true` by default (and multiple `true` get coalesced). It's 
the same thing that would happen if you put in a clause like `AND 
my_special_function(column)`.



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