alamb commented on code in PR #11229: URL: https://github.com/apache/datafusion/pull/11229#discussion_r1680890680
########## datafusion/sqllogictest/test_files/errors.slt: ########## @@ -103,10 +103,6 @@ SELECT power(1, 2, 3); # Wrong window/aggregate function signature # -# AggregateFunction with wrong number of arguments Review Comment: I tried to come up with some other query that has an invalid arguments for count(*) but I could not ########## datafusion/functions-aggregate/src/count.rs: ########## @@ -97,7 +97,10 @@ impl Default for Count { impl Count { pub fn new() -> Self { Self { - signature: Signature::variadic_any(Volatility::Immutable), + signature: Signature::one_of( Review Comment: It would probably be good to call that out with a comment: ```suggestion signature: Signature::one_of( // TypeSignature::Any(0) is required to handle `Count()` with no args ``` Maybe as a follow on PR we could look into making `TypeSignature::VariadicAny` accept zero arguments (which I certainly would have expected, given the name) Another way might be to use https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.TypeSignature.html#variant.UserDefined and then overriding https://docs.rs/datafusion/latest/datafusion/logical_expr/trait.ScalarUDFImpl.html#method.coerce_types However that seems like it would be more complex than allowing VariadicAny to take 0 args ########## datafusion/optimizer/src/analyzer/count_empty_rule.rs: ########## @@ -0,0 +1,91 @@ +// 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. + +use datafusion_common::tree_node::{Transformed, TreeNode}; +use datafusion_common::Result; +use datafusion_common::{config::ConfigOptions, tree_node::TransformedResult}; +use datafusion_expr::utils::COUNT_STAR_EXPANSION; +use datafusion_expr::{ + expr::{AggregateFunction, AggregateFunctionDefinition, WindowFunction}, + LogicalPlan, WindowFunctionDefinition, +}; +use datafusion_expr::{lit, Expr}; + +use crate::utils::NamePreserver; +use crate::AnalyzerRule; + +/// Rewrite `Count()` to `Count(Expr:Literal(1))`. +#[derive(Default)] +pub struct CountEmptyRule {} Review Comment: As each optimizer pass does have non trivial overhead (like it walks the plan trees) I think it would be better if this was combined into the existing `CountWildcardRule` if possible -- 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...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org