jorgecarleitao commented on a change in pull request #7974:
URL: https://github.com/apache/arrow/pull/7974#discussion_r471718884



##########
File path: rust/datafusion/src/sql/planner.rs
##########
@@ -476,70 +478,50 @@ impl<S: SchemaProvider> SqlToRel<S> {
             }
 
             SQLExpr::Function(function) => {
-                //TODO: fix this hack
-                let name: String = function.name.to_string();
-                match name.to_lowercase().as_ref() {
-                    "min" | "max" | "sum" | "avg" => {
-                        let rex_args = function
-                            .args
-                            .iter()
-                            .map(|a| self.sql_to_rex(a, schema))
-                            .collect::<Result<Vec<Expr>>>()?;
-
-                        // return type is same as the argument type for these 
aggregate
-                        // functions
-                        let return_type = 
rex_args[0].get_type(schema)?.clone();
-
-                        Ok(Expr::AggregateFunction {
-                            name: name.clone(),
-                            args: rex_args,
-                            return_type,
-                        })
-                    }
-                    "count" => {
-                        let rex_args = function
-                            .args
-                            .iter()
-                            .map(|a| match a {
-                                SQLExpr::Value(Value::Number(_)) => 
Ok(lit(1_u8)),
-                                SQLExpr::Wildcard => Ok(lit(1_u8)),
-                                _ => self.sql_to_rex(a, schema),
-                            })
-                            .collect::<Result<Vec<Expr>>>()?;
-
-                        Ok(Expr::AggregateFunction {
-                            name: name.clone(),
-                            args: rex_args,
-                            return_type: DataType::UInt64,
-                        })
-                    }
-                    _ => match self.schema_provider.get_function_meta(&name) {
-                        Some(fm) => {
-                            let rex_args = function
+                // make the search case-insensitive
+                let name: String = function.name.to_string().to_lowercase();
+
+                match self.schema_provider.get_function_meta(&name) {
+                    Some(fm) => {
+                        let args = if name == "count" {
+                            // optimization to avoid computing expressions

Review comment:
       This should probably be moved to another place (an optimizer?). For now 
I left it where it here as it was.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to