github-actions[bot] commented on code in PR #60833:
URL: https://github.com/apache/doris/pull/60833#discussion_r2898912776


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Entropy.java:
##########
@@ -0,0 +1,77 @@
+// 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.
+
+package org.apache.doris.nereids.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DoubleType;
+import org.apache.doris.nereids.types.coercion.AnyDataType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/** Entropy */
+public class Entropy extends NullableAggregateFunction implements 
ExplicitlyCastableSignature {
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(DoubleType.INSTANCE).varArgs(AnyDataType.INSTANCE_WITHOUT_INDEX)
+    );
+
+    public Entropy(Expression arg0, Expression... varArgs) {
+        this(false, false, arg0, varArgs);
+    }
+
+    public Entropy(boolean distinct, Expression arg0, Expression... varArgs) {
+        this(distinct, false, arg0, varArgs);
+    }
+
+    public Entropy(boolean distinct, boolean alwaysNullable, Expression arg0, 
Expression... varArgs) {
+        this(distinct, alwaysNullable, false, 
ExpressionUtils.mergeArguments(arg0, varArgs));
+    }
+
+    private Entropy(boolean distinct, boolean alwaysNullable, boolean isSkew, 
List<Expression> expressions) {
+        super("entropy", distinct, alwaysNullable, isSkew, expressions);

Review Comment:
   **[Low]** The `isSkew` parameter is accepted here and passed to the 
superclass, but `Entropy` does not override `withIsSkew()`. The base class 
`AggregateFunction.withIsSkew()` throws `RuntimeException("current expression 
has not impl the withIsSkew method")`. If the optimizer ever attempts to set 
skew on an entropy aggregation, this would cause a runtime crash.
   
   Since there's no semantic reason for entropy to support skew optimization, 
consider removing the `isSkew` parameter and using the simpler super 
constructor (matching the pattern used by `Avg`, `Variance`, `Sem`):
   ```java
   private Entropy(boolean distinct, boolean alwaysNullable, List<Expression> 
expressions) {
       super("entropy", distinct, alwaysNullable, expressions);
   }
   ```
   Or alternatively, override `withIsSkew()` to handle it properly.



##########
be/src/vec/aggregate_functions/aggregate_function_entropy.cpp:
##########
@@ -0,0 +1,65 @@
+// 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.
+// This file is copied from
+// 
https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/AggregateFunctionEntropy.cpp
+// and modified by Doris
+
+#include "vec/aggregate_functions/aggregate_function_entropy.h"
+
+#include "runtime/define_primitive_type.h"
+#include "vec/aggregate_functions/aggregate_function_simple_factory.h"
+#include "vec/aggregate_functions/helpers.h"
+
+namespace doris::vectorized {
+#include "common/compile_check_begin.h"
+
+AggregateFunctionPtr create_aggregate_function_entropy(const std::string& name,
+                                                       const DataTypes& 
argument_types,
+                                                       const DataTypePtr& 
result_type,
+                                                       const bool 
result_is_nullable,
+                                                       const 
AggregateFunctionAttr& attr) {
+    if (argument_types.size() == 1) {
+        auto res = creator_with_type_list<
+                TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, 
TYPE_BIGINT, TYPE_LARGEINT,
+                TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, 
TYPE_DECIMAL256, TYPE_DECIMALV2,
+                TYPE_FLOAT, TYPE_DOUBLE, TYPE_DATE, TYPE_DATETIME, 
TYPE_DATEV2, TYPE_DATETIMEV2,
+                TYPE_TIME, TYPE_TIMEV2, TYPE_TIMESTAMPTZ>::
+                create<AggregateFunctionEntropy, 
AggregateFunctionEntropySingleNumericData>(

Review Comment:
   **[Medium]** `TYPE_IPV4` and `TYPE_IPV6` are missing from this numeric type 
list. Currently they fall through to the generic path 
(`AggregateFunctionEntropyGenericData`), which works but is suboptimal — it 
serializes values into the Arena and hashes them, while the numeric path uses 
values directly as hash map keys.
   
   Both types have proper `PrimitiveTypeTraits` defined (`IPv4` is uint32-like, 
`IPv6` is uint128-like), and other comparable aggregate functions (`topn`, 
`approx_count_distinct`) include them in their numeric type lists.
   
   Suggested fix:
   ```cpp
   creator_with_type_list<
           TYPE_BOOLEAN, TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT, 
TYPE_LARGEINT,
           TYPE_DECIMAL32, TYPE_DECIMAL64, TYPE_DECIMAL128I, TYPE_DECIMAL256, 
TYPE_DECIMALV2,
           TYPE_FLOAT, TYPE_DOUBLE, TYPE_DATE, TYPE_DATETIME, TYPE_DATEV2, 
TYPE_DATETIMEV2,
           TYPE_TIME, TYPE_TIMEV2, TYPE_TIMESTAMPTZ, TYPE_IPV4, TYPE_IPV6>
   ```



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