本文介绍了列存引擎支持的数据类型,及其与Iceberg数据类型的对应关系,涵盖基础数据类型、时间戳、日期等。
数据类型
数据类型 | 对应的Java类型 | 对应的 Iceberg 数据类型 | 描述 |
BOOLEAN | java.lang.Boolean | boolean | 长度为1字节。布尔型,取值为true或false。 |
TINYINT | java.lang.Byte | int | 长度为2字节。定长精确数值类型。取值范围取决于长度,以及数值中有无符号。 |
SMALLINT | java.lang.Short | int | 长度为2字节。定长精确数值类型。取值范围取决于长度,以及数值中有无符号。 |
INTEGER | java.lang.Integer | int | 长度为4字节。定长精确数值类型。取值范围取决于长度,以及数值中有无符号。 |
BIGINT | java.lang.Long | long | 长度为8字节。定长精确数值类型。取值范围取决于长度,以及数值中有无符号。 |
FLOAT | java.lang.Float | float | 长度为4字节。定长非精确数值类型。取值范围和精度取决于长度、precision和scale,以及数值中有无符号。 |
DOUBLE | java.lang.Double | double | 长度为8字节。定长非精确数值类型。取值范围和精度取决于长度、precision和scale,以及数值中有无符号。使用SQL语句拼写时,按照科学计数法的方式来表示DOUBLE类型的值。 |
DECIMAL(precision,scale) | java.lang.BigDecimal | decimal | 变长二进制类型。DECIMAL为十进制,消耗的字节数随精度的增加而增加,通常用于存储金额等高精度数据。对于精度要求不高的场景(例如监控),可以使用FLOAT或DOUBLE。定义类型时需要指定precision和scale。
|
VARCHAR / CHAR(N) | java.lang.String | string | 字符串,支持中文。
|
VARBINARY | byte[] | binary | 变长二进制类型,作为主键时只能是最后一列主键。 |
DATE | java.sql.Types#DATE | date | 仅存储日期(不推荐使用时区转换),格式和时区特性参考背景信息。 |
TIMESTAMP(毫秒精度) | java.sql.Types#TIMESTAMP | timestamptz(微秒精度) | 时间戳。TIMESTAMP类型的格式和时区特性说明请参见背景信息。 |
暂不支持的数据类型:
集合数据类型:LIST,MAP,STRUCT。
基础数据类型: BINARY(N),TIME。
使用示例
基础数据类型
基础数据类型用于表示常见的数值、布尔值、字符串和二进制数据。Lindorm 列存引擎支持多种标量类型,适用于大多数结构化数据场景。以下示例创建一张包含多种基础数据类型的表,并插入典型数据:
CREATE TABLE sensor_data (
id BIGINT,
name VARCHAR,
active BOOLEAN,
temp FLOAT,
pressure DOUBLE,
amount DECIMAL(10, 2)
) PARTITION BY LIST(bucket(4, id))
WITH (
EngineType = 'COLUMN',
'column.engine.num_regions' = '2',
'column.engine.delta_store.memstore.skip_write.enabled' = 'false',
'column.engine.delta_store.query.enabled' = 'true'
);
-- 插入示例数据
INSERT INTO sensor_data (id, name, active, temp, pressure) VALUES (1001, 'sensor-A', true, 23.5, 101325.76);查询结果如下:
mysql> select * from sensor_data;
+------+----------+--------+------+-----------+-----------+---------+
| id | name | active | temp | pressure | amount | payload |
+------+----------+--------+------+-----------+-----------+---------+
| 1001 | sensor-A | 1 | 23.5 | 101325.76 | 999999.99 | null |
+------+----------+--------+------+-----------+-----------+---------+时间戳
Timestamp表示时间点,支持int类型(毫秒时间戳)或string类型(格式化字符串)。示例表示2011年03月02日 04:05:00AM GMT,如下:
CREATE TABLE person_info (
name varchar ,
birthtime timestamp ,
address varchar
) PARTITION BY LIST(bucket(4, name))
WITH (
EngineType=`COLUMN`,
'column.engine.num_regions'='2',
'column.engine.delta_store.memstore.skip_write.enabled' = 'false',
'column.engine.delta_store.query.enabled' = 'true'
);
INSERT INTO person_info (name, birthtime, address) VALUES ( 'my', 1299038700000, 'hz');
INSERT INTO person_info (name, birthtime, address) VALUES ( 'mm', '2011-03-02 04:05+0000', 'hz');
INSERT INTO person_info (name, birthtime, address) VALUES ( 'lucy', '2011-03-02 04:05:00+0000', 'bj');查询结果如下:
mysql> select * from person_info;
+------+---------------------+---------+
| name | birthtime | address |
+------+---------------------+---------+
| my | 2011-03-02 12:05:00 | hz |
| mm | 2011-03-02 04:05:00 | hz |
| lucy | 2011-03-02 04:05:00 | bj |
+------+---------------------+---------+日期
支持使用 STRING 表示date数据类型。如果使用STRING表示的date类型,格式为yyyy-mm-dd。示例如下:
CREATE TABLE person_info_v2 (
name varchar ,
birthday date ,
address varchar
) PARTITION BY LIST(bucket(4, name))
WITH (
EngineType=`COLUMN`,
'column.engine.num_regions'='2',
'column.engine.delta_store.memstore.skip_write.enabled' = 'false',
'column.engine.delta_store.query.enabled' = 'true'
);
INSERT INTO person_info_v2 (name,birthday,address) VALUES ( 'lucy', '2021-02-01', 'beijing');查询结果如下:
mysql> select * from person_info_v2;
+------+------------+---------+
| name | birthday | address |
+------+------------+---------+
| lucy | 2021-02-01 | beijing |
+------+------------+---------+