我正在使用映射列的 JSON-Serde 功能来重命名我在 json 文档“客户 ID”->“客户 ID”中的列。我使用映射函数的原因是因为 HQL 不允许在 CREATE TABLE 定义中使用空格。
json 文档如下所示:
{"browser":"Safari",
"device_uuid":"gftgbvnfg-ed1ae6de-e2df-11e1-4c20-00ef75f32667",
"custom":
{"Customer ID":"4985495}"
}
Run Code Online (Sandbox Code Playgroud)
创建表hive如下:
CREATE TABLE json_serde_test
(
browser STRING,
device_uuid STRING,
custom struct< customer_id : STRING >
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ('json.mappings' = 'custom.Customer ID:custom.customer_id')
STORED AS TEXTFILE;
Run Code Online (Sandbox Code Playgroud)
当我尝试查询 json_serde_test 表时,自定义字段返回:
{"customer_id":null}
Run Code Online (Sandbox Code Playgroud)