Skip to content

Commit a1b7c42

Browse files
authored
[Exec](alias) support stddev alias to std (#52819)
Support `stddev` alias to `std` for BI support like mysql way
1 parent a9d83b8 commit a1b7c42

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

be/src/vec/aggregate_functions/aggregate_function_stddev.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void register_aggregate_function_stddev_variance_pop(AggregateFunctionSimpleFact
105105
factory.register_alias("variance", "variance_pop");
106106
factory.register_function_both("stddev", create_aggregate_function_stddev_pop);
107107
factory.register_alias("stddev", "stddev_pop");
108+
factory.register_alias("stddev", "std");
108109
}
109110

110111
void register_aggregate_function_stddev_variance_samp_old(AggregateFunctionSimpleFactory& factory) {

fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public class FunctionCallExpr extends Expr {
7979
public static final ImmutableSet<String> STDDEV_FUNCTION_SET = new ImmutableSortedSet.Builder(
8080
String.CASE_INSENSITIVE_ORDER)
8181
.add("stddev").add("stddev_val").add("stddev_samp").add("stddev_pop").add("variance").add("variance_pop")
82-
.add("variance_pop").add("var_samp").add("var_pop").add("variance_samp").add("avg_weighted").build();
82+
.add("variance_pop").add("var_samp").add("var_pop").add("variance_samp").add("avg_weighted")
83+
.add("std").build();
8384
public static final Map<String, java.util.function.BiFunction<ArrayList<Expr>, Type, Type>> PRECISION_INFER_RULE;
8485
public static final java.util.function.BiFunction<ArrayList<Expr>, Type, Type> DEFAULT_PRECISION_INFER_RULE;
8586
public static final ImmutableSet<String> ROUND_FUNCTION_SET = new ImmutableSortedSet.Builder(

fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinAggregateFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public class BuiltinAggregateFunctions implements FunctionHelper {
160160
agg(SequenceCount.class, "sequence_count"),
161161
agg(SequenceMatch.class, "sequence_match"),
162162
agg(Skew.class, "skew", "skew_pop", "skewness"),
163-
agg(Stddev.class, "stddev_pop", "stddev"),
163+
agg(Stddev.class, "stddev_pop", "stddev", "std"),
164164
agg(StddevSamp.class, "stddev_samp"),
165165
agg(Sum.class, "sum"),
166166
agg(Sum0.class, "sum0"),

fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,14 @@ private void initAggregateBuiltins() {
12201220
null, null, null,
12211221
"",
12221222
false, true, false, true));
1223+
addBuiltin(AggregateFunction.createBuiltin("stddev",
1224+
Lists.newArrayList(t), STDDEV_RETTYPE_SYMBOL.get(t), t,
1225+
"",
1226+
"",
1227+
"",
1228+
null, null, null,
1229+
"",
1230+
false, true, false, true));
12231231
addBuiltin(AggregateFunction.createBuiltin("stddev_samp",
12241232
Lists.newArrayList(t), STDDEV_RETTYPE_SYMBOL.get(t), t,
12251233
"",

fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/GenerateFunction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public class GenerateFunction {
183183
.put("any", "any_value")
184184
.put("char_length", "character_length")
185185
.put("stddev_pop", "stddev")
186+
.put("std", "stddev")
186187
.put("percentile_cont", "percentile")
187188
.put("var_pop", "variance")
188189
.put("variance_pop", "variance")

regression-test/data/query_p0/sql_functions/aggregate_functions/test_aggregate_all_functions.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ beijing chengdu shanghai
211211
2 216.5
212212
3 36.0
213213

214+
-- !select29 --
215+
1 0.0
216+
2 216.5
217+
3 36.0
218+
214219
-- !select30 --
215220
1 0.0
216221
2 216.5

regression-test/suites/query_p0/sql_functions/aggregate_functions/test_aggregate_all_functions.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ suite("test_aggregate_all_functions", "arrow_flight_sql") {
381381
sql "INSERT INTO ${tableName_15} values(1,10), (2,8), (2,441) ,(1,10) ,(3,29) ,(3,101)"
382382

383383
qt_select29 "select id,stddev(level) from ${tableName_15} group by id order by id"
384+
qt_select29 "select id,std(level) from ${tableName_15} group by id order by id"
384385
qt_select30 "select id,stddev_pop(level) from ${tableName_15} group by id order by id"
385386

386387
sql "DROP TABLE IF EXISTS ${tableName_15}"

0 commit comments

Comments
 (0)