oc7o commented on code in PR #23188:
URL: https://github.com/apache/datafusion/pull/23188#discussion_r3564503379


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1112,7 +1147,39 @@ pub fn similar_to(
         (true, false) => Operator::RegexNotMatch,
         (true, true) => Operator::RegexNotIMatch,
     };
-    Ok(Arc::new(BinaryExpr::new(expr, binary_op, pattern)))
+
+    let translated_pattern = match 
pattern.downcast_ref::<crate::expressions::Literal>() {
+        Some(literal) => match literal.value() {
+            ScalarValue::Utf8(Some(s)) => 
Arc::new(crate::expressions::Literal::new(
+                ScalarValue::Utf8(Some(sql_similar_to_regex(s.as_str()))),
+            )) as Arc<dyn PhysicalExpr>,
+            ScalarValue::LargeUtf8(Some(s)) => 
Arc::new(crate::expressions::Literal::new(
+                ScalarValue::LargeUtf8(Some(sql_similar_to_regex(s.as_str()))),
+            )) as Arc<dyn PhysicalExpr>,
+            ScalarValue::Utf8View(Some(s)) => 
Arc::new(crate::expressions::Literal::new(
+                ScalarValue::Utf8View(Some(sql_similar_to_regex(s.as_str()))),
+            )) as Arc<dyn PhysicalExpr>,
+            ScalarValue::Utf8(None)
+            | ScalarValue::LargeUtf8(None)
+            | ScalarValue::Utf8View(None) => pattern,
+            other => {
+                return not_impl_err!(
+                    "SIMILAR TO with a non-string literal pattern is not 
supported: {other:?}"
+                );
+            }
+        },
+        None => {
+            return not_impl_err!(

Review Comment:
   Okay I added a physical expression for this. I could also have extended 
`BinaryExpr` but I think this would have a lot more implications to other parts 
of the code base. Imho a `PhysicalExpr` implementation for 
`SqlSimilarToPattern` is the cleanest approach.
   



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