Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 无法使用Select查询在表上显示时间戳_Sql_Hadoop_Hive_Hql - Fatal编程技术网

Sql 无法使用Select查询在表上显示时间戳

Sql 无法使用Select查询在表上显示时间戳,sql,hadoop,hive,hql,Sql,Hadoop,Hive,Hql,我有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.TextInpu

我有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
输出值中显示的“null”用于“国家/地区”字段。 但当我在下面给出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)

原因是什么?

字段名是否可能互换?发布输出<代码>显示创建表weatherdata蜂巢(expl)>显示创建表气象数据
OK
创建表
weatherdata
value`string,
snapshort\u time
timestamp)由(
country
string)分区行格式SERDE'org.apache.hadoop.hive.serde2.lazy.lazympleserde'存储为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“TBLProperty”('transient_lastdldltime'='1486827197')所用时间:2.602秒,获取时间:15行`franklinsijo您是对的。这是由于字段名称的交换。我将其整理出来。感谢您的帮助。@VishalSharma,您应该回答您的问题并发布您的解决方案,以便其他人也能从中受益。同时接受您的答案。