adriangb commented on code in PR #12978:
URL: https://github.com/apache/datafusion/pull/12978#discussion_r1805418293
##########
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(
Review Comment:
The logic is pretty simple (truncate at the first one) but I agree another
test would be nice.
--
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]