This is an automated email from the ASF dual-hosted git repository.
panxiaolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 7f9ea1a2317 [fix](parser) Syntax error in column with agg_state
(#46829)
7f9ea1a2317 is described below
commit 7f9ea1a231774160d81ee006560031867e5cbbc7
Author: Uniqueyou <[email protected]>
AuthorDate: Mon Jan 13 11:36:49 2025 +0800
[fix](parser) Syntax error in column with agg_state (#46829)
### What problem does this PR solve?
the problem only exists in the old optimizer
```
mysql> CREATE TABLE t (
-> `k1` int NULL,
-> `k2` agg_state<sum(int null)> GENERIC NOT NULL,
-> `k3` agg_state<group_concat(text null)> GENERIC NOT NULL
-> ) ENGINE=OLAP
-> AGGREGATE KEY(`k1`)
-> DISTRIBUTED BY HASH(`k1`) BUCKETS 3
-> PROPERTIES (
-> "replication_allocation" = "tag.location.default: 1"
-> );
ERROR 1105 (HY000): errCode = 2, detailMessage = Syntax error in line 3:
`k2` agg_state<sum(int null)> GENERIC NOT NULL,
^
Encountered: SUM
Expected: SUM is keyword, maybe `SUM`
```
---
fe/fe-core/src/main/cup/sql_parser.cup | 2 +-
.../agg_state/test_dis_nereids_agg_state.out | 55 +++++++++++++++
.../agg_state/test_dis_nereids_agg_state.groovy | 81 ++++++++++++++++++++++
3 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup
b/fe/fe-core/src/main/cup/sql_parser.cup
index 4250e5262e9..2976d7977cc 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -6676,7 +6676,7 @@ type ::=
{: ScalarType type = ScalarType.createHllType();
RESULT = type;
:}
- | KW_AGG_STATE LESSTHAN IDENT:fnName LPAREN type_def_nullable_list:list
RPAREN GREATERTHAN
+ | KW_AGG_STATE LESSTHAN ident:fnName LPAREN type_def_nullable_list:list
RPAREN GREATERTHAN
{:
RESULT = Expr.createAggStateType(fnName,
list.stream().map(TypeDef::getType).collect(Collectors.toList()),
diff --git
a/regression-test/data/datatype_p0/agg_state/test_dis_nereids_agg_state.out
b/regression-test/data/datatype_p0/agg_state/test_dis_nereids_agg_state.out
new file mode 100644
index 00000000000..8fbf1bde370
--- /dev/null
+++ b/regression-test/data/datatype_p0/agg_state/test_dis_nereids_agg_state.out
@@ -0,0 +1,55 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !sum --
+6
+
+-- !avg --
+2.0
+
+-- !max_by --
+2 1
+
+-- !sum_const --
+3
+
+-- !sum_null --
+\N
+
+-- !desc --
+k1 int Yes true \N
+k2 agg_state<max_by(int, int null)> No false \N GENERIC
+
+-- !length1 --
+1 11
+
+-- !group1 --
+1 1
+
+-- !merge1 --
+1
+
+-- !length2 --
+1 11
+2 11
+3 11
+4 11
+
+-- !group2 --
+1 1
+2 1
+3 2
+4 3
+
+-- !merge2 --
+3
+
+-- !union --
+3
+
+-- !max_by_null --
+\N \N
+
+-- !ndv --
+1
+
+-- !approx_count_distinct --
+1
diff --git
a/regression-test/suites/datatype_p0/agg_state/test_dis_nereids_agg_state.groovy
b/regression-test/suites/datatype_p0/agg_state/test_dis_nereids_agg_state.groovy
new file mode 100644
index 00000000000..75955f78e36
--- /dev/null
+++
b/regression-test/suites/datatype_p0/agg_state/test_dis_nereids_agg_state.groovy
@@ -0,0 +1,81 @@
+// 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.
+
+suite("test_dis_nereids_agg_state") {
+ sql "set global enable_agg_state=true"
+ sql "set enable_nereids_planner=false"
+ sql """ DROP TABLE IF EXISTS dis_nereids_d_table; """
+ sql """
+ create table dis_nereids_d_table(
+ k1 int null,
+ k2 int not null,
+ k3 bigint null,
+ k4 varchar(100) null
+ )
+ duplicate key (k1,k2,k3)
+ distributed BY hash(k1) buckets 3
+ properties("replication_num" = "1");
+ """
+
+ sql "insert into dis_nereids_d_table select 1,1,1,'a';"
+ sql "insert into dis_nereids_d_table select 2,2,2,'b';"
+ sql "insert into dis_nereids_d_table select 3,3,null,'c';"
+
+ qt_sum """ select sum_merge(sum_state(k1)) from dis_nereids_d_table; """
+ qt_avg """ select avg_merge(avg_state(k1)) from dis_nereids_d_table; """
+ qt_max_by """ select
max_by_merge(max_by_state(k1,k3)),min_by_merge(min_by_state(k1,k3)) from
dis_nereids_d_table; """
+
+ qt_sum_const """ select sum_merge(sum_state(1)) from dis_nereids_d_table;
"""
+ qt_sum_null """ select sum_merge(sum_state(null)) from
dis_nereids_d_table; """
+
+ sql """ DROP TABLE IF EXISTS dis_nereids_a_table; """
+ sql """
+ create table dis_nereids_a_table(
+ k1 int null,
+ k2 agg_state<max_by(int not null,int)> generic
+ )
+ aggregate key (k1)
+ distributed BY hash(k1) buckets 3
+ properties("replication_num" = "1");
+ """
+
+ qt_desc "desc dis_nereids_a_table;"
+
+ sql "insert into dis_nereids_a_table select 1,max_by_state(1,3);"
+ sql "insert into dis_nereids_a_table select 1,max_by_state(2,2);"
+ sql "insert into dis_nereids_a_table values(1,max_by_state(3,1));"
+
+ qt_length1 """select k1,length(k2) from dis_nereids_a_table order by k1;"""
+ qt_group1 """select k1,max_by_merge(k2) from dis_nereids_a_table group by
k1 order by k1;"""
+ qt_merge1 """select max_by_merge(k2) from dis_nereids_a_table;"""
+
+ sql "insert into dis_nereids_a_table select k1+1, max_by_state(k2,k1+10)
from dis_nereids_d_table;"
+
+ qt_length2 """select k1,length(k2) from dis_nereids_a_table order by k1;"""
+ qt_group2 """select k1,max_by_merge(k2) from dis_nereids_a_table group by
k1 order by k1;"""
+ qt_merge2 """select max_by_merge(k2) from dis_nereids_a_table;"""
+
+ qt_union """ select max_by_merge(kstate) from (select k1,max_by_union(k2)
kstate from dis_nereids_a_table group by k1 order by k1) t; """
+ qt_max_by_null """ select
max_by_merge(max_by_state(k1,null)),min_by_merge(min_by_state(null,k3)) from
dis_nereids_d_table; """
+
+ test {
+ sql "select avg_state(1) from dis_nereids_d_table;"
+ }
+
+ qt_ndv """select ndv_merge(t) from (select ndv_union(ndv_state(1)) as t
from dis_nereids_d_table group by k1)p;"""
+ qt_approx_count_distinct """select approx_count_distinct_merge(t) from
(select approx_count_distinct_union(approx_count_distinct_state(1)) as t from
dis_nereids_d_table group by k1)p;"""
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]