如何使用json模式插入覆盖目录?
有原始Hiveavro表(这实际上有很多领域)
tb_test--------
name string
kickname string
-----------------
然后我想通过jsonserde将查询结果保存到hdfs中的某个目录中。
我试过了。
insert overwrite directory '/json/'
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
WITH SERDEPROPERTIES (
"stat_name"="$._col0",
"stat_interval"="$._col1"
)
STORED AS TEXTFILE
select name, nickname
from tb_test limit 100
但是,在/json/中写入的json具有\u colxx字段名,而不是源字段名。
{"_col0":"basic_qv"," _col1":"h"}
{"_col0":"basic_qv","_col1 ":"h"}
{"_col0":"basic_qv","_col1 ":"h"}
{"_col0":"basic_qv"," _col1":"h"}
{"_col0":"basic_qv","_col1 ":"h"}
我预料到了
{"name":"basic_qv","nickname":"h"}
{"name":"basic_qv","nickname":"h"}
{"name":"basic_qv","nickname":"h"}
{"name":"basic_qv","nickname":"h"}
{"name":"basic_qv","nickname":"h"}
有什么帮助?
谢谢!!
1条答案
按热度按时间643ylb081#
您的解决方案(使用jsonudf和命名的\u struct)的问题如下所述:https://github.com/rcongiu/hive-json-serde/issues/151
您还可以创建基于jsonserde的表,并定义列,
insert overwrite
它使用表位置而不是目录。