You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by xu...@apache.org on 2023/04/26 14:10:23 UTC
[doris] branch master updated: [bug](map-type)fix some bugs in map and map element function (#18935)
This is an automated email from the ASF dual-hosted git repository.
xuyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 925efc1902 [bug](map-type)fix some bugs in map and map element function (#18935)
925efc1902 is described below
commit 925efc19023d56ce948cb05c347552a406c47c3f
Author: xy720 <22...@users.noreply.github.com>
AuthorDate: Wed Apr 26 22:10:15 2023 +0800
[bug](map-type)fix some bugs in map and map element function (#18935)
fix some bugs in map and map element function.
---
.../vec/functions/array/function_array_element.h | 3 ++-
fe/fe-core/src/main/cup/sql_parser.cup | 15 +++++++++++-
.../apache/doris/analysis/FunctionCallExpr.java | 7 ++++++
.../stream_load/test_map_load_and_function.out | 27 ++++++++++++++++++++++
.../stream_load/test_map_load_and_function.groovy | 9 ++++++++
5 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/array/function_array_element.h b/be/src/vec/functions/array/function_array_element.h
index b6ef0d305f..9d49f9ef03 100644
--- a/be/src/vec/functions/array/function_array_element.h
+++ b/be/src/vec/functions/array/function_array_element.h
@@ -107,7 +107,8 @@ public:
args = {col_left, block.get_by_position(arguments[1])};
}
ColumnPtr res_column = nullptr;
- if (args[0].column->is_column_map()) {
+ if (args[0].column->is_column_map() ||
+ check_column_const<ColumnMap>(args[0].column.get())) {
res_column = _execute_map(args, input_rows_count, src_null_map, dst_null_map);
} else {
res_column = _execute_nullable(args, input_rows_count, src_null_map, dst_null_map);
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup
index 7787c8fdea..8418cf58ed 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -746,7 +746,7 @@ nonterminal LiteralExpr literal;
nonterminal CaseExpr case_expr;
nonterminal ArrayList<CaseWhenClause> case_when_clause_list;
nonterminal FunctionParams function_params;
-nonterminal Expr function_call_expr, array_expr;
+nonterminal Expr function_call_expr, array_expr, map_expr;
nonterminal ArrayLiteral array_literal;
nonterminal MapLiteral map_literal;
nonterminal StructField struct_field;
@@ -6284,6 +6284,17 @@ map_literal ::=
:}
;
+map_expr ::=
+ KW_MAP LPAREN function_params:params RPAREN
+ {:
+ RESULT = new FunctionCallExpr("map", params);
+ :}
+ | KW_MAP LPAREN RPAREN
+ {:
+ RESULT = new MapLiteral();
+ :}
+ ;
+
struct_field ::=
ident:name COLON type:type
{: RESULT = new StructField(name, type); :}
@@ -6330,6 +6341,8 @@ non_pred_expr ::=
{: RESULT = a; :}
| array_literal:a
{: RESULT = a; :}
+ | map_expr:a
+ {: RESULT = a; :}
| map_literal:a
{: RESULT = a; :}
| struct_literal:s
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index fcf8250739..a027944747 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1461,6 +1461,13 @@ public class FunctionCallExpr extends Expr {
fn.getReturnType().getPrimitiveType().setTimeType();
}
+ if (fnName.getFunction().equalsIgnoreCase("map")) {
+ if ((children.size() & 1) == 1) {
+ throw new AnalysisException("map can't be odd parameters, need even parameters: "
+ + this.toSql());
+ }
+ }
+
if (fnName.getFunction().equalsIgnoreCase("named_struct")) {
if ((children.size() & 1) == 1) {
throw new AnalysisException("named_struct can't be odd parameters, need even parameters: "
diff --git a/regression-test/data/load_p0/stream_load/test_map_load_and_function.out b/regression-test/data/load_p0/stream_load/test_map_load_and_function.out
index c02d5efe7a..b26f936f94 100644
--- a/regression-test/data/load_p0/stream_load/test_map_load_and_function.out
+++ b/regression-test/data/load_p0/stream_load/test_map_load_and_function.out
@@ -60,6 +60,9 @@
-- !select_map2 --
{1000:"k11", 2000:"k22"}
+-- !select_map3 --
+MAP{}
+
-- !select_element1 --
1000
@@ -84,6 +87,30 @@ k22
-- !select_element8 --
\N
+-- !select_element9 --
+1000
+
+-- !select_element10 --
+2000
+
+-- !select_element11 --
+\N
+
+-- !select_element12 --
+\N
+
+-- !select_element13 --
+k11
+
+-- !select_element14 --
+k22
+
+-- !select_element15 --
+\N
+
+-- !select_element16 --
+\N
+
-- !select_element101 --
1 \N \N
2 {" 11amory ":23, "beat":20, " clever ":66} \N
diff --git a/regression-test/suites/load_p0/stream_load/test_map_load_and_function.groovy b/regression-test/suites/load_p0/stream_load/test_map_load_and_function.groovy
index 5d0a187d09..19021d01d2 100644
--- a/regression-test/suites/load_p0/stream_load/test_map_load_and_function.groovy
+++ b/regression-test/suites/load_p0/stream_load/test_map_load_and_function.groovy
@@ -78,6 +78,7 @@ suite("test_map_load_and_function", "p0") {
// map construct
qt_select_map1 "SELECT map('k11', 1000, 'k22', 2000)"
qt_select_map2 "SELECT map(1000, 'k11', 2000, 'k22')"
+ qt_select_map3 "SELECT map()"
// map element_at
qt_select_element1 "SELECT map('k11', 1000, 'k22', 2000)['k11']"
@@ -88,6 +89,14 @@ suite("test_map_load_and_function", "p0") {
qt_select_element6 "SELECT map(1000, 'k11', 2000, 'k22')[2000]"
qt_select_element7 "SELECT map(1000, 'k11', 2000, 'k22')[3000]"
qt_select_element8 "SELECT map('k11', 1000, 'k22', 2000)[NULL]"
+ qt_select_element9 "SELECT {'k11':1000, 'k22':2000}['k11']"
+ qt_select_element10 "SELECT {'k11':1000, 'k22':2000}['k22']"
+ qt_select_element11 "SELECT {'k11':1000, 'k22':2000}['nokey']"
+ qt_select_element12 "SELECT {'k11':1000, 'k22':2000}[NULL]"
+ qt_select_element13 "SELECT {1000:'k11', 2000:'k22'}[1000]"
+ qt_select_element14 "SELECT {1000:'k11', 2000:'k22'}[2000]"
+ qt_select_element15 "SELECT {1000:'k11', 2000:'k22'}[3000]"
+ qt_select_element16 "SELECT {1000:'k11', 2000:'k22'}[NULL]"
qt_select_element101 "SELECT id, m, m['k1'] FROM ${testTable} ORDER BY id"
qt_select_element102 "SELECT id, m, m['k2'] FROM ${testTable} ORDER BY id"
qt_select_element103 "SELECT id, m, m[' 11amory '] FROM ${testTable} ORDER BY id"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org