jayzhan211 commented on code in PR #8636:
URL: https://github.com/apache/arrow-datafusion/pull/8636#discussion_r1439426467


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -0,0 +1,232 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Optimizer rule for expression rewrite
+
+use datafusion_common::config::ConfigOptions;
+use datafusion_common::tree_node::TreeNode;
+use datafusion_common::tree_node::TreeNodeRewriter;
+use datafusion_common::Result;
+use datafusion_expr::expr::ScalarFunction;
+use datafusion_expr::BuiltinScalarFunction;
+use datafusion_expr::Operator;
+use datafusion_expr::Projection;
+use datafusion_expr::ScalarFunctionDefinition;
+use datafusion_expr::{BinaryExpr, Expr, LogicalPlan};
+
+use super::AnalyzerRule;
+
+#[derive(Default)]
+pub struct OperatorToFunction {}
+
+impl OperatorToFunction {
+    pub fn new() -> Self {
+        Self {}
+    }
+}
+
+impl AnalyzerRule for OperatorToFunction {
+    fn name(&self) -> &str {
+        "operator_to_function"
+    }
+
+    fn analyze(&self, plan: LogicalPlan, _: &ConfigOptions) -> 
Result<LogicalPlan> {
+        analyze_internal(plan)
+    }
+}
+
+fn analyze_internal(plan: LogicalPlan) -> Result<LogicalPlan> {
+    // OperatorToFunction is only applied to Projection
+    match plan {
+        LogicalPlan::Projection(_) => {}

Review Comment:
   Based on test, I found they are all project plan with inputs.len() 1. Not 
sure is this assumption correct or not



##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -0,0 +1,232 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Optimizer rule for expression rewrite
+
+use datafusion_common::config::ConfigOptions;
+use datafusion_common::tree_node::TreeNode;
+use datafusion_common::tree_node::TreeNodeRewriter;
+use datafusion_common::Result;
+use datafusion_expr::expr::ScalarFunction;
+use datafusion_expr::BuiltinScalarFunction;
+use datafusion_expr::Operator;
+use datafusion_expr::Projection;
+use datafusion_expr::ScalarFunctionDefinition;
+use datafusion_expr::{BinaryExpr, Expr, LogicalPlan};
+
+use super::AnalyzerRule;
+
+#[derive(Default)]
+pub struct OperatorToFunction {}
+
+impl OperatorToFunction {
+    pub fn new() -> Self {
+        Self {}
+    }
+}
+
+impl AnalyzerRule for OperatorToFunction {
+    fn name(&self) -> &str {
+        "operator_to_function"
+    }
+
+    fn analyze(&self, plan: LogicalPlan, _: &ConfigOptions) -> 
Result<LogicalPlan> {
+        analyze_internal(plan)
+    }
+}
+
+fn analyze_internal(plan: LogicalPlan) -> Result<LogicalPlan> {
+    // OperatorToFunction is only applied to Projection
+    match plan {
+        LogicalPlan::Projection(_) => {}
+        _ => {
+            return Ok(plan);
+        }
+    }
+
+    let mut expr_rewriter = OperatorToFunctionRewriter {};
+
+    let new_expr = plan
+        .expressions()
+        .into_iter()
+        .map(|expr| expr.rewrite(&mut expr_rewriter))
+        .collect::<Result<Vec<_>>>()?;
+
+    // Not found cases that inputs more than one
+    assert_eq!(plan.inputs().len(), 1);

Review Comment:
   Same here



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to