STRUCT
STRUCT
name
STRUCT
description
STRUCT<field_name:field_type [COMMENT 'comment_string'], ... >
由多个 Field 组成的结构体,也可被理解为多个列的集合。不能作为 Key 使用,目前 STRUCT 仅支持在 Duplicate 模型的表中使用。
一个 Struct 中的 Field 的名字和数量固定,总是为 Nullable,一个 Field 通常由下面部分组成。
- field_name: Field 的标识符,不可重复
- field_type: Field 的类型
- COMMENT: Field 的注释,可选 (暂不支持)
当前可支持的类型有:
BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, DECIMAL, DECIMALV3, DATE,
DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING
在将来的版本我们还将完善:
TODO:支持嵌套 STRUCT 或其他的复杂类型
example
建表示例如下:
mysql> CREATE TABLE `struct_test` (
`id` int(11) NULL,
`s_info` STRUCT<s_id:int(11), s_name:string, s_address:string> NULL
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false"
);
插入数据示例:
Insert:
INSERT INTO `struct_test` VALUES (1, {1, 'sn1', 'sa1'});
INSERT INTO `struct_test` VALUES (2, struct(2, 'sn2', 'sa2'));
INSERT INTO `struct_test` VALUES (3, named_struct('s_id', 3, 's_name', 'sn3', 's_address', 'sa3'));
Stream load:
test.csv:
1|{"s_id":1, "s_name":"sn1", "s_address":"sa1"}
2|{s_id:2, s_name:sn2, s_address:sa2}
3|{"s_address":"sa3", "s_name":"sn3", "s_id":3}
示例:
curl --location-trusted -u root -T test.csv -H "label:test_label" http://host:port/api/test/struct_test/_stream_load
查询数据示例:
mysql> select * from struct_test;
+------+-------------------+
| id | s_info |
+------+-------------------+
| 1 | {1, 'sn1', 'sa1'} |
| 2 | {2, 'sn2', 'sa2'} |
| 3 | {3, 'sn3', 'sa3'} |
+------+-------------------+
3 rows in set (0.02 sec)
keywords
STRUCT