无法使用表上的select查询显示时间戳

mwg9r5ms  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(310)

我有3个字段的“weatherdata”表。

CREATE TABLE weatherdata( value` string, snapshort_time timestamp)
PARTITIONED BY ( country string) 
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 
STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
LOCATION 'hdfs://quickstart.cloudera:8020/user/hive/warehouse/expl.db‌​/weatherdata'

当我将下面给出的命令写到这个表上时,它成功地在输出端显示了“snapshort\u time”字段:

hive (expl)> select * from weatherdata;
OK
{"location: {"name":"Beijing","region":"Beijing","country":"China","lat":39.93,"lon":116.39,"tz_id":"Asia/Shanghai","localtime_epoch":1486857803,"localtime":"2017-02-12 0:03"},"current":{"last_updated_epoch":1486857803,"last_updated":"2017-02-12 00:03","temp_c":-3.0,"temp_f":26.6,"is_day":0,"condition":{"text":"Clear","icon":"//cdn.apixu.com/weather/64x64/night/113.png","code":1000},"wind_mph":0.0,"wind_kph":0.0,"wind_degree":0,"wind_dir":"N","pressure_mb":1028.0,"pressure_in":30.8,"precip_mm":0.0,"precip_in":0.0,"humidity":39,"cloud":0,"feelslike_c":-3.0,"feelslike_f":26.6}}  NULL    2017-02-11 08:22:36

输出值中显示的“null”用于“country”字段。但是当我给下面的select时,snapshort\u time显示为null。

select get_json_object(value, '$.location.name') AS name, 
get_json_object(value,'$.location.region') AS region, 
get_json_object(value, '$.location.country') AS country, 
get_json_object(value, '$.current.condition.text') AS text, 
get_json_object(value, '$.current.feelslike_c') AS feelslike_c, 
Snapshort_time
from weatherdata;

以下是输出:

OK
Beijing Beijing China   Clear   -3.0    NULL
Dubai   Dubai   United Arab Emirates    Clear   24.6    NULL
London  City of London, Greater London  United Kingdom  Mist    -1.3    NULL
Moscow  Moscow City Russia  Clear   -5.7    NULL
Paris   Ile-de-France   France  Patchy light snow   -1.2    NULL
Sydney  New South Wales Australia   Partly cloudy   26.3    NULL
Tokyo   Tōkyō   Japan   Partly cloudy   -1.3    NULL
Toronto Ontario Canada  Overcast    -4.0    NULL
Washington  District of Columbia    United States of America    Partly cloudy   5.9 NULL
Time taken: 0.339 seconds, Fetched: 9 row(s)

原因是什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题