hive的cascade使用表明

打印 上一主题 下一主题

主题 1031|帖子 1031|积分 3093

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
迩来看到涉及到hive表字段新增,项目组其他职员让我add columns后加 cascade,这个我以前见到过,但是我一般没有用,也没出问题,那就研究下。
网上大多数的说法就是分区表加字段必要级联,缘故起因是,你add column只针对后面的新增分区,历史分区没有加上字段,后面你插入数据也无法查询。
实践是查验真理的唯一标准。
  
  1. drop table if exists cc_test.cascade_1;
  2. create table cc_test.cascade_1(
  3.                                   id string ,
  4.                                   name string
  5. )
  6.     partitioned by (bd_date string)
  7. stored as parquet ;
  8. insert into cc_test.cascade_1(id, name, bd_date) VALUES ('1','1','1'),('2','2','2');
  9. alter table cc_test.cascade_1 add columns (sex string ) ;
  10. insert into cc_test.cascade_1(id, name,sex, bd_date) VALUES ('11','11','11','1'),('3','3','3','3');
  11. 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不必要,固然你要全部加上也没啥。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

用户云卷云舒

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表