zclllyybb commented on code in PR #57545:
URL: https://github.com/apache/doris/pull/57545#discussion_r2490372313
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Sem.java:
##########
@@ -15,57 +15,84 @@
// specific language governing permissions and limitations
// under the License.
-package org.apache.doris.nereids.trees.expressions.functions.scalar;
+package org.apache.doris.nereids.trees.expressions.functions.agg;
import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
-import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
-import org.apache.doris.nereids.types.BooleanType;
-import org.apache.doris.nereids.types.StringType;
-import org.apache.doris.nereids.types.VarcharType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DoubleType;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
/**
- * ScalarFunction 'is_uuid'.
+ * AggregateFunction 'sem'.
*/
-public class IsUuid extends ScalarFunction
- implements UnaryExpression, ExplicitlyCastableSignature,
PropagateNullable {
+
+public class Sem extends NullableAggregateFunction
+ implements UnaryExpression, ExplicitlyCastableSignature {
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
-
FunctionSignature.ret(BooleanType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT),
-
FunctionSignature.ret(BooleanType.INSTANCE).args(StringType.INSTANCE));
+
FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE));
/**
* constructor with 1 argument.
*/
- public IsUuid(Expression arg) {
- super("is_uuid", arg);
+ public Sem(Expression child) {
+ this(false, false, child);
+ }
+
+ /**
+ * constructor with distinct flag and 1 argument.
+ */
+ public Sem(boolean distinct, Expression arg) {
+ this(distinct, false, arg);
+ }
+
+ private Sem(boolean distinct, boolean alwaysNullable, Expression arg) {
+ super("sem", distinct, alwaysNullable, arg);
+ }
+
+ /** constructor for withChildren and reuse signature */
+ private Sem(NullableAggregateFunctionParams functionParams) {
+ super(functionParams);
+ }
+
+ @Override
+ public void checkLegalityBeforeTypeCoercion() {
+ DataType argType = child().getDataType();
+ if (!argType.isDoubleType()) {
+ throw new AnalysisException("sem only requires a double parameter:
" + this.toSql());
Review Comment:
这会不会阻止别的类型转换过来啊?
##########
be/src/vec/aggregate_functions/aggregate_function_sem.h:
##########
@@ -0,0 +1,133 @@
+// 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.
+
+#pragma once
+
+#include <math.h>
+
+#include "runtime/decimalv2_value.h"
+#include "runtime/define_primitive_type.h"
+#include "runtime/primitive_type.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type.h"
+#include "vec/data_types/data_type_decimal.h"
+
+namespace doris::vectorized {
+#include "common/compile_check_begin.h"
+
+class Arena;
+class BufferReadable;
+class BufferWritable;
+
+struct AggregateFunctionSemData {
+ double mean {};
+ double m2 {}; // Cumulative sum of squares
+ UInt64 count = 0;
+
+ void add(const double& value) {
Review Comment:
可以在这边加一下注释说明下welford算法
--
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]