说明:
本文档展示的内容仅适用于 Doris 1.1及以下版本,后续版本建议使用 Multi-Catalog 功能对接外部数据目录。
Hudi External Table of Doris 提供了 Doris 直接访问 Hudi 外部表的能力,外部表省去了繁琐的数据导入工作,并借助 Doris 本身的 OLAP 的能力来解决 Hudi 表的数据分析问题:
1. 支持 Hudi 数据源接入 Doris。
2. 支持 Doris 与 Hive 数据源 Hudi 中的表联合查询,进行更加复杂的分析操作。
本文档主要介绍该功能的使用方式和注意事项等。
使用方法
Doris 中创建 Hudi 的外表
可以通过以下两种方式在 Doris 中创建 Hudi 外表。建外表时无需声明表的列定义,Doris 可以在查询时从 HiveMetaStore 中获取列信息。
1. 创建一个单独的外表,用于挂载 Hudi 表。具体相关语法,可以通过 CREATE TABLE 查看。
-- 语法CREATE [EXTERNAL] TABLE table_name[(column_definition1[, column_definition2, ...])]ENGINE = HUDI[COMMENT "comment"]PROPERTIES ("hudi.database" = "hudi_db_in_hive_metastore","hudi.table" = "hudi_table_in_hive_metastore","hudi.hive.metastore.uris" = "thrift://127.0.0.1:9083");-- 例子:挂载 HiveMetaStore 中 hudi_db_in_hive_metastore 下的 hudi_table_in_hive_metastore,挂载时不指定schema。CREATE TABLE `t_hudi`ENGINE = HUDIPROPERTIES ("hudi.database" = "hudi_db_in_hive_metastore","hudi.table" = "hudi_table_in_hive_metastore","hudi.hive.metastore.uris" = "thrift://127.0.0.1:9083");-- 例子:挂载时指定schemaCREATE TABLE `t_hudi` (`id` int NOT NULL COMMENT "id number",`name` varchar(10) NOT NULL COMMENT "user name") ENGINE = HUDIPROPERTIES ("hudi.database" = "hudi_db_in_hive_metastore","hudi.table" = "hudi_table_in_hive_metastore","hudi.hive.metastore.uris" = "thrift://127.0.0.1:9083");
参数说明:
外表列:
可以不指定列名,这时查询时会从 HiveMetaStore 中获取列信息,推荐这种建表方式。
指定列名时指定的列名要在 Hudi 表中存在。
ENGINE 需要指定为 HUDI。
PROPERTIES 属性:
hudi.hive.metastore.uris
:Hive Metastore 服务地址。hudi.database
:挂载 Hudi 对应的数据库名。hudi.table
:挂载 Hudi 对应的表名。展示表结构
展示表结构可以通过
SHOW CREATE TABLE
查看。类型匹配
支持的 Hudi 列类型与 Doris 对应关系如下表:
Hudi | Doris | 描述 |
BOOLEAN | BOOLEAN | - |
INTEGER | INT | - |
LONG | BIGINT | - |
FLOAT | FLOAT | - |
DOUBLE | DOUBLE | - |
DATE | DATE | - |
TIMESTAMP | DATETIME | Timestamp 转成 Datetime 会损失精度 |
STRING | STRING | - |
UUID | VARCHAR | 使用 VARCHAR 来代替 |
DECIMAL | DECIMAL | - |
TIME | - | 不支持 |
FIXED | - | 不支持 |
BINARY | - | 不支持 |
STRUCT | - | 不支持 |
LIST | - | 不支持 |
MAP | - | 不支持 |
注意
当前默认支持的 Hudi 版本为 0.10.0,未在其他版本进行测试。
查询用法
完成在 Doris 中建立 Hudi 外表后,除了无法使用 Doris 中的数据模型(rollup、预聚合、物化视图等)外,与普通的 Doris OLAP 表并无区别。
select * from t_hudi where k1 > 1000 and k3 ='term' or k4 like '%doris';