waynexia commented on code in PR #6840:
URL: https://github.com/apache/arrow-datafusion/pull/6840#discussion_r1251967011


##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -1120,6 +1151,70 @@ fn make_substrait_window_function(
     }
 }
 
+#[allow(deprecated)]
+fn make_substrait_like_expr(

Review Comment:
   Maybe we can combine `Expr::Like` and `Expr::ILike` by adding a field 
`ignore_case`? cc @alamb 



##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -1329,3 +1272,66 @@ fn from_substrait_null(null_type: &Type) -> 
Result<ScalarValue> {
         ))
     }
 }
+
+async fn make_datafusion_like(

Review Comment:
   Maybe it's time to refactor these large `producer.rs` and `consumer.rs` into 
several small files and organize them by functionality (e.g., produce `like` 
and consume `like`) 



##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -1120,6 +1151,70 @@ fn make_substrait_window_function(
     }
 }
 
+#[allow(deprecated)]
+fn make_substrait_like_expr(
+    ignore_case: bool,
+    negated: bool,
+    expr: &Box<Expr>,
+    pattern: &Box<Expr>,
+    escape_char: Option<char>,
+    schema: &DFSchemaRef,
+    col_ref_offset: usize,
+    extension_info: &mut (
+        Vec<extensions::SimpleExtensionDeclaration>,
+        HashMap<String, u32>,
+    ),
+) -> Result<Expression> {
+    let function_anchor = if ignore_case {
+        _register_function("ilike".to_string(), extension_info)
+    } else {
+        _register_function("like".to_string(), extension_info)
+    };
+    let expr = to_substrait_rex(expr, schema, col_ref_offset, extension_info)?;
+    let pattern = to_substrait_rex(pattern, schema, col_ref_offset, 
extension_info)?;
+    let escape_char =
+        to_substrait_literal(&ScalarValue::Utf8(escape_char.map(|c| 
c.to_string())))?;
+    let arguments = vec![
+        FunctionArgument {
+            arg_type: Some(ArgType::Value(expr)),
+        },
+        FunctionArgument {
+            arg_type: Some(ArgType::Value(pattern)),
+        },
+        FunctionArgument {
+            arg_type: Some(ArgType::Value(escape_char)),
+        },
+    ];
+
+    let substrait_like = Expression {
+        rex_type: Some(RexType::ScalarFunction(ScalarFunction {
+            function_reference: function_anchor,
+            arguments,
+            output_type: None,
+            args: vec![],
+            options: vec![],
+        })),
+    };
+
+    if negated {
+        let function_anchor = _register_function("not".to_string(), 
extension_info);
+
+        Ok(Expression {

Review Comment:
   This pattern is very common. I'm thinking of wrapping it into something like 
`LogicalPlanBuilder`



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

Reply via email to