如何根据CSV的形状更改hive表模式
Hive [部署在Azure HDInsight
数据文件CSV [在Azure Blob Storage)
我的要求::
例如。我有CSV与3列A B C
和另一个CSV与3列A B D
有任何方法根据CSV形状创建Hive表?
What I tried:
我在hive中创建了一个表,其中a B C D
和加载的file1(a B C)
预期为A B C D - x x x null
file2(a B D)
预期为A B C D - x x null x
,
file2(A B D)
实际结果A B C D - x x x null
如有任何建议,不胜感激。
提前谢谢你
不,在单表中这是不可能的,可以通过以下方式解决:
1两个表+视图创建两个表:T1 (A,B,C)和T2 (A,B,D),视图
select A,B,C, null as D
from table1
UNION ALL
select A, B, null as C, D
from table2
2创建一个包含A, B, C列的表和一个基于file_name逻辑的视图(伪代码,检查input__file_name实际返回的内容并相应地修复)
select A, B,
case when INPUT__FILE__NAME == 'file1' then C else null end as C,
case when INPUT__FILE__NAME == 'file2' then C else null end as D
但是这个视图不能在Presto等其他工具中工作,所以,第一个选项是更好的。