请不要介意这是一个非常基本的:
测试.txt
1拉维100液压
2克里希纳200液压
3 fff 300秒
我在hive中创建了一个表,在city上有分区,并加载了如下数据:
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
当我以“select*from temp”查询表时;
## 输出:
temp.id temp.name temp.sal temp.city
1 ravi 100 hyd
2 krishna 200 hyd
3 fff 300 hyd
我的问题是,为什么第三行的城市名称从“sec”变为“hyd”?
我这边有什么问题吗?
提前谢谢!!!
3条答案
按热度按时间tnkciper1#
我希望分区不能与单个文件的load语句一起正常工作。
相反,我们需要写入temp表(
stat_parti
)在hive中,从那里我们需要另一个分区表(stat_test
)前任:
并能给出静态或动态分区。
1) 静态分区
2) 动态分区
这里我们需要启用
e4eetjau2#
你的问题是:
加载到此分区的所有数据都带有city='hyd'。如果您正在进行静态分区,那么您的责任就是将正确的值放入分区中。
只需从txt文件中删除最后一行,将其放入test2.txt并执行:
是的,不太舒服,但是静态分区是这样工作的。
1aaf6o9v3#
您在hdfs路径中复制的数据文件test.txt-'/testing/temp/city=hyd/test.txt'所有数据将进入分区-'city=hyd'
配置单元使用目录名来检索值。因此,字段city名称来自目录名hyd。