STRUCT

name

SinceVersion 2.0.0

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.

1. 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:

1. BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, DECIMAL, DECIMALV3, DATE,
2. DATEV2, DATETIME, DATETIMEV2, CHAR, VARCHAR, STRING

We have a todo list for future version:

1. TODO:支持嵌套 STRUCT 或其他的复杂类型

example

Create table example:

1. mysql> CREATE TABLE `struct_test` (
2. `id` int(11) NULL,
3. `s_info` STRUCT<s_id:int(11), s_name:string, s_address:string> NULL
4. ) ENGINE=OLAP
5. DUPLICATE KEY(`id`)
6. COMMENT 'OLAP'
7. DISTRIBUTED BY HASH(`id`) BUCKETS 1
8. PROPERTIES (
9. "replication_allocation" = "tag.location.default: 1",
10. "storage_format" = "V2",
11. "light_schema_change" = "true",
12. "disable_auto_compaction" = "false"
13. );

Insert data example:

1. INSERT INTO `struct_test` VALUES (1, {1, 'sn1', 'sa1'});
2. INSERT INTO `struct_test` VALUES (2, struct(2, 'sn2', 'sa2'));
3. INSERT INTO `struct_test` VALUES (3, named_struct('s_id', 3, 's_name', 'sn3', 's_address', 'sa3'));

Stream load:

test.csv:

1. 1|{"s_id":1, "s_name":"sn1", "s_address":"sa1"}
2. 2|{s_id:2, s_name:sn2, s_address:sa2}
3. 3|{"s_address":"sa3", "s_name":"sn3", "s_id":3}

exmaple:

1. curl --location-trusted -u root -T test.csv  -H "label:test_label" http://host:port/api/test/struct_test/_stream_load

Select data example:

1. mysql> select * from struct_test;
2. +------+-------------------+
3. | id   | s_info            |
4. +------+-------------------+
5. |    1 | {1, 'sn1', 'sa1'} |
6. |    2 | {2, 'sn2', 'sa2'} |
7. |    3 | {3, 'sn3', 'sa3'} |
8. +------+-------------------+
9. 3 rows in set (0.02 sec)

keywords

1. STRUCT