Hive分区表新增字段值为NULL

背景

对于HIVE分区表通过add column添加字段,向已存在分区中插入数据,结果新增字段的值全部为null。 已存在分区会产生该问题,新分区不会产生该问题。

原因

实际上数据是插入成功的。HDFS上的数据更新了,但是我们查询的时候仍然查询的是旧的元数据信息(即Mysql中的信息)

官方解释如下:

Change Column Name/Type/Position/Comment

ALTER TABLE table_name [PARTITION partition_spec] CHANGE [COLUMN] col_old_name col_new_name column_type

[COMMENT col_comment] [FIRST|AFTER column_name] [CASCADE|RESTRICT];
This command will allow users to change a column’s name, data type, comment, or position, or an arbitrary combination of them. The PARTITION clause is available in Hive 0.14.0 and later; see Upgrading Pre-Hive 0.13.0 Decimal Columns for usage. A patch for Hive 0.13 is also available (see HIVE-7971).

The CASCADE|RESTRICT clause is available in Hive 1.1.0. ALTER TABLE CHANGE COLUMN with CASCADE command changes the columns of a table’s

你可能感兴趣的:(大数据技术,HIVE,ALTER,TABLE,ADD,COLUMN,元数据)