STRUCT
STRUCTβ
nameβ
STRUCT
descriptionβ
STRUCT<field_name:field_type [COMMENT 'comment_string'], ... >
Represents value with structure described by multiple fields, which can be viewed as a collection of multiple columns.
Need to manually enable the support, it is disabled by default.
admin set frontend config("enable_struct_type" = "true");
It cannot be used as a Key column. Now STRUCT can only used in Duplicate Model Tables.
The names and number of Fields in a Struct is fixed and always Nullable, and a Field typically consists of the following parts.
- field_name: Identifier naming the field, non repeatable.
- field_type: A data type.
- COMMENT: An optional string describing the field. (currently not supported)
The currently supported types are:
BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, DECIMAL, DECIMALV3, DATE,
DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING
We have a todo list for future version:
TODO:ζ―ζε΅ε₯ STRUCT ζε
Άδ»ηε€ζη±»ε
exampleβ
Create table 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 data example:
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}
exmaple:
curl --location-trusted -u root -T test.csv -H "label:test_label" http://host:port/api/test/struct_test/_stream_load
Select data example:
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