hive的cascade使用解释

最近看到涉及到hive表字段新增,项目组其他人员让我add columns后加 cascade,这个我以前见到过,但是我一般没有用,也没出问题,那就研究下。

网上大多数的说法就是分区表加字段需要级联,原因是,你add column只针对后面的新增分区,历史分区没有加上字段,后面你插入数据也无法查询。

实践是检验真理的唯一标准。

复制代码
drop table if exists cc_test.cascade_1;
create table cc_test.cascade_1(
                                  id string ,
                                  name string
)
    partitioned by (bd_date string)
stored as parquet ;

insert into cc_test.cascade_1(id, name, bd_date) VALUES ('1','1','1'),('2','2','2');

alter table cc_test.cascade_1 add columns (sex string ) ;

insert into cc_test.cascade_1(id, name,sex, bd_date) VALUES ('11','11','11','1'),('3','3','3','3');

select * from cc_test.cascade_1

擦 id=11 的这条数据的sex确实没有显现出来,难道我真的错了?

加了级联cascade 就好了。

其实不然,只需将表的存储类型改为orc即可。

说明了parquet由于存储类型的问题,add columns的需要加cascade

但是orc不需要的。

直接去官网看下cascade解释

ADD COLUMNS lets you add new columns to the end of the existing columns but before the partition columns. This is supported for Avro backed tables as well, for Hive 0.14 and later.

-- add columns 只支持在列的最后和分区字段前加列。

REPLACE COLUMNS removes all existing columns and adds the new set of columns. This can be done only for tables with a native SerDe (DynamicSerDe, MetadataTypedColumnsetSerDe, LazySimpleSerDe and ColumnarSerDe). Refer to Hive SerDe for more information. REPLACE COLUMNS can also be used to drop columns. For example, "ALTER TABLE test_change REPLACE COLUMNS (a int, b int);" will remove column 'c' from test_change's schema.

--这个是repalce 和change的用法

The PARTITION clause is available in Hive 0.14.0 and later; see Upgrading Pre-Hive 0.13.0 Decimal Columns for usage.

-- 对某个分区的操作

The CASCADE |RESTRICT clause is available in Hive 1.1.0. ALTER TABLE ADD|REPLACE COLUMNS with CASCADE command changes the columns of a table's metadata, and cascades the same change to all the partition metadata. RESTRICT is the default, limiting column changes only to table metadata.

这里说的是默认是restrict 默认只改表的数据,cascade改表的元数据和分区的元数据

但是这里并没有说哪些类型的表不需要改?

ALTER TABLE ADD or REPLACE COLUMNS CASCADE will override the table partition's column metadata regardless of the table or partition's protection mode. Use with discretion.

The column change command will only modify Hive's metadata, and will not modify data. Users should make sure the actual data layout of the table/partition conforms with the metadata definition.

经过测试 textfile和parquet 需要加,orc和avro不需要,当然你要全部加上也没啥。

相关推荐
SelectDB技术团队12 小时前
上市大模型企业数据基础设施的选择:MiniMax 基于阿里云 SelectDB 版,打造全球统一AI可观测中台
数据库·数据仓库·人工智能·ai·apache
weixin_4624462312 小时前
Hive Metastore 使用 MySQL 8(CJ 驱动)完整配置实战(含完整 Shell 脚本)
hive·hadoop·mysql
zgl_2005377912 小时前
源代码:ZGLanguage 解析SQL数据血缘 之 显示 MERGE SQL 结构图
数据库·数据仓库·hive·数据治理·etl·sql解析·数据血缘
Gain_chance12 小时前
24-学习笔记尚硅谷数仓搭建-DIM层的维度表建表思路及商品表维度表的具体建表解析
数据仓库·hive·笔记·学习·datagrip
编程小风筝13 小时前
MySQL数据库如何实现实现数据仓库存储?
数据库·数据仓库·mysql
talle202114 小时前
Hive | 分区与分桶
大数据·数据仓库·hive
zhangkaixuan4561 天前
Paimon 读取数据流程深度解析
大数据·hadoop·flink·apache·paimon
Gain_chance1 天前
23-学习笔记尚硅谷数仓搭建-ODS层业务全量表、增量表结构设计及数据装载脚本
数据仓库·hive·笔记·学习
JZC_xiaozhong1 天前
什么是ETL?一文了解提取、转换与加载
数据库·数据仓库·数据分析·etl·数据一致性·数据孤岛解决方案·数据集成与应用集成
yumgpkpm2 天前
在AI语言大模型时代 Cloudera CDP(华为CMP 鲲鹏版)对自有知识的保护
人工智能·hadoop·华为·zookeeper·spark·kafka