问题1:location配置错误,导致hive表无法被操作
案件背景:大数据平台有两个环境,分正式环境和测试环境。创建hive的时候,把正式环境的表的location配置成测试的路径,测试环境的hive表的location配置成正式的路径。这样导致两张hive表无法被操作,truncate、insert、select、drop都不能。
案件错误日志:
执行命令 drop table mysql4_csp_cstm_terminal;
报错:FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:java.lang.IllegalArgumentException: Wrong FS: hdfs://xx.xx.xx.xx:8020/user/hive/warehouse/db_ecar.db/mysql4_csp_cstm_terminal, expected: hdfs://masterf:8020)
解决方案:
将hive表的location修改过来。
alter table mysql4_csp_cstm_terminal set location 'hdfs://xx.xx.xx.xx:8020/user/hive/warehouse/db_ecar.db/mysql4_csp_cstm_terminal'
问题2:hive分区表增加字段时,新字段值会为空问题背景:
一张有数据的分区表需要增加字段,直接给表增加字段,会导致再给分区表插入数据时,新字段的值会为空。
原因:
修改表结构后,元数据库中的SDS中该表对应的CD_ID会改变,但是该表分区下面对应的CD_ID还是原来表的CD_ID。
解决方案:
首先,在给表增加字段:alter table table_name add columns(column_name string); //新增字段的值为NULL
再,给分区增加字段:alter table table_name partition(step='1') add columns(column_name string);