我在配置单元中从具有以下结构的json文件创建一个表:
{
"id": "1",
"clave": "1",
"tipo_registro": "Planilla",
"creado_por": "ETL cargaInicialPlanilla",
"fecha_creacion": "2016-09-269T00:00:00.0Z",
"modificado_por": "ETL cargaInicialPlanilla",
"fecha_ultima_modificacion": "2016-09-269T00:00:00.0Z",
"oficina": "comun",
"valores": {
"P_ACTIVO": "1",
"P_AT_ACTIVO": "1",
"P_AT_DESCRIPCION": "Fecha de Emisión",
"P_AT_EDITABLE": "1",
"P_AT_IDTIPODATO": "5",
"P_AT_LARGO": "0",
"P_AT_REPETIBLE": "0",
"P_AT_TD_ACTIVO": "1",
"P_AT_TD_DESCRIPCION": "System.DateTime",
"P_AT_TD_VALOR": "System.DateTime",
"P_IDATRIBUTOM": "15",
"P_IDPLANILLAM": "1",
"P_IDRECAUDO": "11",
"P_OCULTO": "0",
"P_ORDEN": "1"
}
}
我将文件放在hdfs(/user/hive/testtable)中,并使用以下命令创建表:
CREATE EXTERNAL TABLE IF NOT EXISTS test
(
id STRING,
clave STRING,
tipo_registro STRING,
creado_por STRING,
fecha_creacion STRING,
modificado_por STRING,
fecha_ultima_modificacion STRING,
oficina STRING,
valor MAP<String, String>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION '/user/hive/TestTable';
但是当我查询表时,valor或map字段总是空的。
我看到其他关于这个的文章,但是在大多数文章中,总是使用struct而不是map,我需要使用map,因为这个字段不是静态的,在其他文档中可能有不同的字段。
我会感谢任何帮助,提前谢谢。
1条答案
按热度按时间eoxn13cs1#
你的json有valores,但是在你的配置单元表中你定义为valor,这就是为什么它总是空的,在你的配置单元表中将它改为valores以匹配你的json属性名,它应该可以工作。