hive修改字段后查询不了数据

情况描述

hive版本为: apache-hive-2.1.0
hadoop版本为: apache-hadoop-2.6.0-cdh-5.13.3

修改添加两个字段删除一个字段,但跟日志文件数据是一一对应的。
发现修改后,在hive中用mapreduce查询这两个新加的字段,值为null。
而用hive中用spark引擎却可以找到字段的值。

hive修改字段

通过alert table tablename add column(旧字段1,旧字段2,…,旧字段N,新字段1,新字段2)
修改。

修改

在hive中,修改后发现查询旧字段时正常的,而新加的字段1,字段2值为null。
使用spark引擎,发现该数据查询正常。

解决

分区按日期分,重新关联hdfs。
写个执行脚本,从开始日期的日志当最新的日志

脚本

	#!/bin/sh
	begin = $(date +%s -d "20151101")
	end = $(date +%s -d "20191101")
	db=sss
	tmpfile = /tmp/tmp.sql
	while[ $begin -le $end ]
	do
		dt = $(date +%Y%m%d -d @begin)
		echo "alert table tablename drop partition(date=$dt);alert table $db.tablename add
		partition(pdate=$dt) location '/$db/$dt/';" >> $tmpfile
		begin=$((begin+86400))
	done
	hive -f $tmpfile
发布了79 篇原创文章 · 获赞 3 · 访问量 5259

猜你喜欢

转载自blog.csdn.net/SW_LCC/article/details/102854676
今日推荐