Hudi基础 -- Spark SQL DDL
创始人
2024-05-24 17:51:53
0

目录

1.创建一个cow类型的表

2.创建一个cow类型,主键为ID的表

3.创建mor类型主键更新的表

4. 创建分区表

5.CTAS(Create table as select) 创建表

5.1 CTAS创建非分区表

5.2 CTAS创建分区、主键表


Spark Create Table 关键参数:
参数名称 描述 可选项:默认值
primaryKey 表的主键名称,组合主键使用逗号分隔; (Optional) : id
type 表类型:cow’ 或 ‘mor’,默认是cow; (Optional) : cow
preCombineField 当数据的主键相同时,会根据这个字段判断是否要更新此主键的数据。不指定默认保留最新 ; (Optional) : ts

1.创建一个cow类型的表

-- create a non-primary key table
create table if not exists hudi_table2(id int,name string,price double
) using hudi
options (type = 'cow'
);

2.创建一个cow类型,主键为ID的表

-- create a managed cow table
create table if not exists hudi_table0 (id int,name string,price double
) using hudi
options (type = 'cow',primaryKey = 'id'
);

3.创建mor类型主键更新的表

create table if not exists hudi_table1 (id int,name string,price double,ts bigint
) using hudi
options (type = 'mor',primaryKey = 'id,name',preCombineField = 'ts'
);

4. 创建分区表

create table if not exists hudi_table_p0 (
id bigint,
name string,
dt string,
hh string  
) using hudi
options (type = 'cow',primaryKey = 'id',preCombineField = 'ts'
)
partitioned by (dt, hh);

5.CTAS(Create table as select) 创建表

Hudi支持CTAS(Create table as select)的方式创建表

5.1 CTAS创建非分区表

create table h3 using hudi
as
select 1 as id, 'a1' as name, 10 as price;

5.2 CTAS创建分区、主键表

create table h2 using hudi
options (type = 'cow', primaryKey = 'id')
partitioned by (dt)
as
select 1 as id, 'a1' as name, 10 as price, 1000 as dt;
更多的 ddl 参考 SQL DDL | Apache Hudi

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...