我有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_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
“输出”值中显示的“空”表示“国家/地区”字段。 但是当我给出下面的Select时,'Snapshort_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)
原因是什么?