Skip to content

Commit b2f85fb

Browse files
authored
feat(draft): map data type (#3696)
- deps: zetasql -> 0.3.3 - parser: map data type - parser: create table with array/map data type - parser & node: extract array/map value with []operator - udf: map functions - udf: map_keys function - codegen: construct map data type - codegen: access map value by key with []operator - type system: NULL and VOID type - refactor & IWYU TODO - []operator support for array type - codegen: use vector type & SIMD instructions instead of array ?
1 parent 3b473ab commit b2f85fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1605
-534
lines changed

cases/function/join/test_lastjoin_simple.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,4 +1067,4 @@ cases:
10671067
rows:
10681068
- [ "aa",2,131,1590738990000 ]
10691069
- [ "bb",21,NULL,NULL ]
1070-
- [ "dd", 41, NULL, NULL ]
1070+
- [ "dd", 41, NULL, NULL ]

cases/plan/back_quote_identifier.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ cases:
131131
| | +-node[kColumnDesc]
132132
| | +-column_name: a-1
133133
| | +-column_type: int32
134-
| | +-NOT NULL: 0
135134
| +-1:
136135
| | +-node[kColumnDesc]
137136
| | +-column_name: b-1
138137
| | +-column_type: string
139-
| | +-NOT NULL: 0
140138
| +-2:
141139
| +-node[kColumnIndex]
142140
| +-keys: [a-1, b-1]

cases/plan/const_query.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,36 @@ cases:
3939
mode: request-unsupport
4040
sql: |
4141
select int(NULL) as c1, bigint(NULL) as c2, float(NULL) as c3, double(NULL) as c4, timestamp(NULL) as c5, date(NULL) as c6, string(NULL) as c7;
42+
43+
- id: map_data_type
44+
mode: request-unsupport
45+
desc: access map value with []operator
46+
sql: |
47+
select map(1, 2)[1]
48+
expect:
49+
node_tree_str: |
50+
+-node[kQuery]: kQuerySelect
51+
+-distinct_opt: false
52+
+-where_expr: null
53+
+-group_expr_list: null
54+
+-having_expr: null
55+
+-order_expr_list: null
56+
+-limit: null
57+
+-select_list[list]:
58+
| +-0:
59+
| +-node[kResTarget]
60+
| +-val:
61+
| | map(1, 2)[1]
62+
| +-name: <nil>
63+
+-tableref_list: []
64+
+-window_list: []
65+
plan_tree_str: |
66+
+-[kQueryPlan]
67+
+-[kProjectPlan]
68+
+-table: <nil>
69+
+-project_list_vec[list]:
70+
+-[kProjectList]
71+
+-projects on table [list]:
72+
+-[kProjectNode]
73+
+-[0]map(1, 2)[1]: map(1, 2)[1]
74+
null

cases/plan/create.yaml

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,10 @@ cases:
163163
| | +-node[kColumnDesc]
164164
| | +-column_name: a
165165
| | +-column_type: int32
166-
| | +-NOT NULL: 0
167166
| +-1:
168167
| | +-node[kColumnDesc]
169168
| | +-column_name: b
170169
| | +-column_type: string
171-
| | +-NOT NULL: 0
172170
| +-2:
173171
| +-node[kColumnIndex]
174172
| +-keys: [a, b]
@@ -218,12 +216,10 @@ cases:
218216
| | +-node[kColumnDesc]
219217
| | +-column_name: a
220218
| | +-column_type: int16
221-
| | +-NOT NULL: 0
222219
| +-1:
223220
| | +-node[kColumnDesc]
224221
| | +-column_name: b
225222
| | +-column_type: float
226-
| | +-NOT NULL: 0
227223
| +-2:
228224
| +-node[kColumnIndex]
229225
| +-keys: [a]
@@ -274,12 +270,10 @@ cases:
274270
| | +-node[kColumnDesc]
275271
| | +-column_name: a
276272
| | +-column_type: int32
277-
| | +-NOT NULL: 0
278273
| +-1:
279274
| | +-node[kColumnDesc]
280275
| | +-column_name: b
281276
| | +-column_type: timestamp
282-
| | +-NOT NULL: 0
283277
| +-2:
284278
| +-node[kColumnIndex]
285279
| +-keys: [a]
@@ -627,12 +621,10 @@ cases:
627621
| | +-node[kColumnDesc]
628622
| | +-column_name: a
629623
| | +-column_type: int32
630-
| | +-NOT NULL: 0
631624
| +-1:
632625
| | +-node[kColumnDesc]
633626
| | +-column_name: b
634627
| | +-column_type: timestamp
635-
| | +-NOT NULL: 0
636628
| +-2:
637629
| +-node[kColumnIndex]
638630
| +-keys: [a]
@@ -685,33 +677,27 @@ cases:
685677
| +-0:
686678
| | +-node[kColumnDesc]
687679
| | +-column_name: column1
688-
| | +-column_type: int32
689-
| | +-NOT NULL: 1
680+
| | +-column_type: int32 NOT NULL
690681
| +-1:
691682
| | +-node[kColumnDesc]
692683
| | +-column_name: column2
693-
| | +-column_type: int16
694-
| | +-NOT NULL: 1
684+
| | +-column_type: int16 NOT NULL
695685
| +-2:
696686
| | +-node[kColumnDesc]
697687
| | +-column_name: column5
698-
| | +-column_type: string
699-
| | +-NOT NULL: 1
688+
| | +-column_type: string NOT NULL
700689
| +-3:
701690
| | +-node[kColumnDesc]
702691
| | +-column_name: column6
703-
| | +-column_type: string
704-
| | +-NOT NULL: 1
692+
| | +-column_type: string NOT NULL
705693
| +-4:
706694
| | +-node[kColumnDesc]
707695
| | +-column_name: std_ts
708-
| | +-column_type: timestamp
709-
| | +-NOT NULL: 1
696+
| | +-column_type: timestamp NOT NULL
710697
| +-5:
711698
| | +-node[kColumnDesc]
712699
| | +-column_name: std_date
713-
| | +-column_type: date
714-
| | +-NOT NULL: 1
700+
| | +-column_type: date NOT NULL
715701
| +-6:
716702
| +-node[kColumnIndex]
717703
| +-keys: [column2]
@@ -743,33 +729,27 @@ cases:
743729
| +-0:
744730
| | +-node[kColumnDesc]
745731
| | +-column_name: column1
746-
| | +-column_type: int32
747-
| | +-NOT NULL: 1
732+
| | +-column_type: int32 NOT NULL
748733
| +-1:
749734
| | +-node[kColumnDesc]
750735
| | +-column_name: column2
751-
| | +-column_type: int16
752-
| | +-NOT NULL: 1
736+
| | +-column_type: int16 NOT NULL
753737
| +-2:
754738
| | +-node[kColumnDesc]
755739
| | +-column_name: column5
756-
| | +-column_type: string
757-
| | +-NOT NULL: 1
740+
| | +-column_type: string NOT NULL
758741
| +-3:
759742
| | +-node[kColumnDesc]
760743
| | +-column_name: column6
761-
| | +-column_type: string
762-
| | +-NOT NULL: 1
744+
| | +-column_type: string NOT NULL
763745
| +-4:
764746
| | +-node[kColumnDesc]
765747
| | +-column_name: std_ts
766-
| | +-column_type: timestamp
767-
| | +-NOT NULL: 1
748+
| | +-column_type: timestamp NOT NULL
768749
| +-5:
769750
| | +-node[kColumnDesc]
770751
| | +-column_name: std_date
771-
| | +-column_type: date
772-
| | +-NOT NULL: 1
752+
| | +-column_type: date NOT NULL
773753
| +-6:
774754
| +-node[kColumnIndex]
775755
| +-keys: [column2]
@@ -796,17 +776,11 @@ cases:
796776
| +-0:
797777
| | +-node[kColumnDesc]
798778
| | +-column_name: column1
799-
| | +-column_type: int32
800-
| | +-NOT NULL: 0
801-
| | +-default_value:
802-
| | +-expr[primary]
803-
| | +-value: 1
804-
| | +-type: int32
779+
| | +-column_type: int32 DEFAULT 1
805780
| +-1:
806781
| +-node[kColumnDesc]
807782
| +-column_name: column2
808783
| +-column_type: int32
809-
| +-NOT NULL: 0
810784
+-table_option_list: []
811785
- id: 27
812786
desc: Column default value with explicit type
@@ -824,20 +798,11 @@ cases:
824798
| +-0:
825799
| | +-node[kColumnDesc]
826800
| | +-column_name: column1
827-
| | +-column_type: string
828-
| | +-NOT NULL: 0
829-
| | +-default_value:
830-
| | +-expr[cast]
831-
| | +-cast_type: string
832-
| | +-expr:
833-
| | +-expr[primary]
834-
| | +-value: 1
835-
| | +-type: int32
801+
| | +-column_type: string DEFAULT string(1)
836802
| +-1:
837803
| +-node[kColumnDesc]
838804
| +-column_name: column3
839805
| +-column_type: int32
840-
| +-NOT NULL: 0
841806
+-table_option_list: []
842807
- id: 28
843808
desc: Create table with database.table
@@ -856,12 +821,10 @@ cases:
856821
| | +-node[kColumnDesc]
857822
| | +-column_name: column1
858823
| | +-column_type: string
859-
| | +-NOT NULL: 0
860824
| +-1:
861825
| +-node[kColumnDesc]
862826
| +-column_name: column3
863827
| +-column_type: int32
864-
| +-NOT NULL: 0
865828
+-table_option_list: []
866829
- id: 29
867830
desc: create index with db name prefix
@@ -898,12 +861,10 @@ cases:
898861
| | +-node[kColumnDesc]
899862
| | +-column_name: column1
900863
| | +-column_type: int32
901-
| | +-NOT NULL: 0
902864
| +-1:
903865
| | +-node[kColumnDesc]
904866
| | +-column_name: column2
905867
| | +-column_type: timestamp
906-
| | +-NOT NULL: 0
907868
| +-2:
908869
| +-node[kColumnIndex]
909870
| +-keys: [column1]
@@ -934,12 +895,10 @@ cases:
934895
| | +-node[kColumnDesc]
935896
| | +-column_name: a
936897
| | +-column_type: int32
937-
| | +-NOT NULL: 0
938898
| +-1:
939899
| | +-node[kColumnDesc]
940900
| | +-column_name: b
941901
| | +-column_type: timestamp
942-
| | +-NOT NULL: 0
943902
| +-2:
944903
| +-node[kColumnIndex]
945904
| +-keys: [a]
@@ -1049,12 +1008,10 @@ cases:
10491008
| | +-node[kColumnDesc]
10501009
| | +-column_name: column1
10511010
| | +-column_type: int32
1052-
| | +-NOT NULL: 0
10531011
| +-1:
10541012
| | +-node[kColumnDesc]
10551013
| | +-column_name: column2
10561014
| | +-column_type: timestamp
1057-
| | +-NOT NULL: 0
10581015
| +-2:
10591016
| +-node[kColumnIndex]
10601017
| +-keys: [column1]
@@ -1068,3 +1025,45 @@ cases:
10681025
+-0:
10691026
+-node[kCompressType]
10701027
+-compress_type: snappy
1028+
- id: 35
1029+
desc: Create table with array & map type
1030+
sql: |
1031+
create table t1 (id int,
1032+
member ARRAY <STRING> NOT NULL,
1033+
attrs MAP <STRING, INT NOT NULL > NOT NULL);
1034+
expect:
1035+
node_tree_str: |
1036+
+-node[CREATE]
1037+
+-table: t1
1038+
+-IF NOT EXIST: 0
1039+
+-column_desc_list[list]:
1040+
| +-0:
1041+
| | +-node[kColumnDesc]
1042+
| | +-column_name: id
1043+
| | +-column_type: int32
1044+
| +-1:
1045+
| | +-node[kColumnDesc]
1046+
| | +-column_name: member
1047+
| | +-column_type: array<string> NOT NULL
1048+
| +-2:
1049+
| +-node[kColumnDesc]
1050+
| +-column_name: attrs
1051+
| +-column_type: map<string, int32 NOT NULL> NOT NULL
1052+
+-table_option_list: []
1053+
plan_tree_str: |
1054+
+-[kCreatePlan]
1055+
+-table: t1
1056+
+-column_desc_list[list]:
1057+
| +-0:
1058+
| | +-node[kColumnDesc]
1059+
| | +-column_name: id
1060+
| | +-column_type: int32
1061+
| +-1:
1062+
| | +-node[kColumnDesc]
1063+
| | +-column_name: member
1064+
| | +-column_type: array<string> NOT NULL
1065+
| +-2:
1066+
| +-node[kColumnDesc]
1067+
| +-column_name: attrs
1068+
| +-column_type: map<string, int32 NOT NULL> NOT NULL
1069+
+-table_option_list: []

cases/plan/simple_query.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,4 @@ cases:
644644
+-[kTablePlan]
645645
+-table: t
646646
+-alias: t1
647+

cases/query/udf_query.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,37 @@ cases:
554554
- c1 bool
555555
data: |
556556
true, false
557+
558+
# ================================================================
559+
# Map data type
560+
# ================================================================
561+
- id: 13
562+
mode: request-unsupport
563+
sql: |
564+
select
565+
map(1, "2")[1] as e1,
566+
map("abc", 100)["abc"] as e2,
567+
map(1, "2", 3, "4")[5] as e3,
568+
map("c", 99, "d", 101)["d"] as e4,
569+
map(date("2012-12-12"), "e", date("2013-11-11"), "f", date("2014-10-10"), "g")[date("2013-11-11")] as e5,
570+
map(timestamp(88), timestamp(1000), timestamp(99), timestamp(2000)) [timestamp(99)] as e6,
571+
map('1', 2, '3', 4, '5', 6, '7', 8, '9', 10, '11', 12)['9'] as e7,
572+
map('1', 2, '3', 4, '5', 6, '7', 8, '9', 10, '11', 12)['10'] as e8,
573+
# first match on duplicate keys
574+
map('1', 2, '1', 4, '1', 6, '7', 8, '9', 10, '11', 12)['1'] as e9,
575+
map("c", 99, "d", NULL)["d"] as e10,
576+
expect:
577+
columns: ["e1 string", "e2 int", "e3 string", "e4 int", "e5 string", "e6 timestamp", "e7 int", "e8 int", "e9 int", "e10 int"]
578+
data: |
579+
2, 100, NULL, 101, f, 2000, 10, NULL, 2, NULL
580+
- id: 14
581+
mode: request-unsupport
582+
sql: |
583+
select
584+
array_contains(map_keys(map(1, '2', 3, '4')), 1) as e1,
585+
array_contains(map_keys(map('1', 2, '3', 4)), '2') as e2,
586+
array_contains(map_keys(map(timestamp(88), timestamp(1000), timestamp(99), timestamp(2000))) , timestamp(99)) as e3,
587+
expect:
588+
columns: ["e1 bool", "e2 bool", "e3 bool"]
589+
data: |
590+
true, false, true

hybridse/include/base/fe_status.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
#ifndef HYBRIDSE_INCLUDE_BASE_FE_STATUS_H_
1818
#define HYBRIDSE_INCLUDE_BASE_FE_STATUS_H_
19+
20+
#include <sstream>
1921
#include <string>
2022
#include <vector>
21-
#include "glog/logging.h"
23+
2224
#include "proto/fe_common.pb.h"
23-
#include "proto/fe_type.pb.h"
2425

2526
namespace hybridse {
2627
namespace base {

hybridse/include/node/expr_node.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define HYBRIDSE_INCLUDE_NODE_EXPR_NODE_H_
1919

2020
#include <string>
21-
#include <vector>
2221

2322
#include "base/fe_status.h"
2423
#include "codec/fe_row_codec.h"

0 commit comments

Comments
 (0)