【发布时间】:2017-02-11 04:58:30
【问题描述】:
我正在尝试在 Hive 中创建一个外部表,用于获取 json 数据作为 Web 服务的响应。
下面给出了我创建外部表架构的json文件数据:
{
"location": {
"name": "Paris",
"region": "Ile-de-France",
"country": "France",
"lat": 48.87,
"lon": 2.33,
"tz_id": "Europe/Paris",
"localtime_epoch": 1486792043,
"localtime": "2017-02-11 5:47"
},
"current": {
"last_updated_epoch": 1486792043,
"last_updated": "2017-02-11 05:47",
"temp_c": 0.0,
"temp_f": 32.0,
"is_day": 0,
"condition": {
"text": "Mist",
"icon": "//cdn.apixu.com/weather/64x64/night/143.png",
"code": 1030
},
"wind_mph": 8.1,
"wind_kph": 13.0,
"wind_degree": 330,
"wind_dir": "NNW",
"pressure_mb": 1019.0,
"pressure_in": 30.6,
"precip_mm": 0.0,
"precip_in": 0.0,
"humidity": 74,
"cloud": 0,
"feelslike_c": -4.0,
"feelslike_f": 24.8
}
}
创建外部表命令如下:
CREATE EXTERNAL TABLE weatherdata (
location STRUCT<
name:STRING,
region:STRING,
country:STRING,
lat:FLOAT,
lon:FLOAT,
tz_id:STRING,
localtime:STRING>,
current STRUCT<
last_updated_epoch:BIGINT,
last_updated:STRING,
temp_c:FLOAT,
temp_f:FLOAT,
is_day:INT,
condition:STRUCT<text:STRING, icon:STRING, code:INT>,
wind_mph:FLOAT, wind_kph:FLOAT,
wind_degree:INT,
wind_dir:STRING,
pressure_mb:FLOAT,
pressure_in:FLOAT,
precip_mm:FLOAT,
precip_in:FLOAT,
humidity:INT,
cloud:INT,
feelslike_c:FLOAT,
feelslike_f:FLOAT>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';
我收到以下错误:
FAILED: ParseException line 9:3 cannot recognize input near 'current' 'STRUCT' '<' in column specification
我尝试使用字段“current”作为“curr”创建这个外部表,只是为了检查并成功创建了表。很明显,将上面给出的“json”数据加载到此表中时,只有“位置”数据加载成功,“当前”数据显示为空。 “当前”是蜂巢中的关键字吗?什么问题?
【问题讨论】:
-
你有
condition:STRUCT,那么为什么location或current上没有:? -
@cricket_007 ':' 仅用于内部结构变量。
标签: json hadoop hive hdfs hiveql