请介意这是否是非常基本的内容:

test.txt

1拉维100 hyd
2克里希纳200 hyd
3 fff 300秒

我已经在 hive 中创建了一个带有城市分区的表,并加载了以下数据:

create external table temp(id int, name string, sal int)
partitioned by(city string)
location '/testing';
load data inpath '/test.txt' into table temp partition(city='hyd');
在HDFS中,结构为/testing/temp/city=hyd/test.txt

当我查询表为“从温度中选择*”时;

输出:
temp.id temp.name temp.sal temp.city
    1   ravi    100 hyd
    2   krishna 200 hyd
    3   fff     300 hyd

在这里,我的问题是,为什么第三行中的城市名称从“sec”更改为“hyd”?

我这边有什么问题吗?

提前致谢 !!!

最佳答案

您的问题是这样的:

load data inpath '/test.txt' into table temp partition(city='hyd');

您加载到该分区中的所有数据都带有city ='hyd'。
如果您要进行静态分区,则您有责任将正确的值放入分区中。

只需从txt文件中删除最后一行,将其放入test2.txt并执行:
load data inpath '/test.txt' into table temp partition(city='hyd');
load data inpath '/test2.txt' into table temp partition(city='sec');

是的,不是很舒服,但是静态分区以这种方式工作。

08-06 23:27