JSON Serde - 映射列名

Lou*_*yan 1 json hadoop hive

我正在使用映射列的 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)

Rob*_*giu 6

注意:我是 SerDe 的作者。编辑答案,因为我第一次只是凭记忆回答,这是不正确的。这将工作(已测试)

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 ('mapping.customer_id' = 'Customer ID')
STORED AS TEXTFILE;

LOAD DATA LOCAL INPATH 'data.txt' OVERWRITE INTO TABLE json_serde_test; 
Run Code Online (Sandbox Code Playgroud)

映射应具有以下形式:映射。蜂巢列= json 列

我对其进行了测试,它可以正常工作:

hive> select custom from json_serde_test;
OK
{"customer_id":"4985495}"}
Run Code Online (Sandbox Code Playgroud)