mongo-hadoop,如何查询hive中的timestamp列

时间:2016-08-22 03:39:44

标签: mongodb hadoop hive

选择并格式化列可以

hive> select time, date(time) from user_login limit 10; OK 2016-05-24 10:20:26 2016-05-24 2016-05-24 10:21:03 2016-05-24 2016-05-24 10:21:06 2016-05-24 2016-05-24 10:22:21 2016-05-24 2016-05-24 10:22:24 2016-05-24 2016-05-24 10:22:32 2016-05-24 2016-05-24 10:22:49 2016-05-24 2016-05-24 10:23:12 2016-05-24 2016-05-24 10:23:53 2016-05-24 2016-05-24 10:23:53 2016-05-24 Time taken: 0.084 seconds, Fetched: 10 row(s) 但是当在time上过滤时,结果为空 hive> select time, date(time) from user_login where date(time)=date('2016-05-24') limit 10; Query ID = tars_20160822103939_102dd35a-c11f-4ed9-a67b-d40a9c0d60ee Total jobs = 1 Launching Job 1 out of 1 Number of reduce tasks is set to 0 since there's no reduce operator Starting Job = job_1471603982720_0033, Tracking URL = http://cdh001:8088/proxy/application_1471603982720_0033/ Kill Command = /opt/cloudera/parcels/CDH-5.8.0-1.cdh5.8.0.p0.42/lib/hadoop/bin/hadoop job -kill job_1471603982720_0033 Hadoop job information for Stage-1: number of mappers: 15; number of reducers: 0 2016-08-22 10:40:02,182 Stage-1 map = 0%, reduce = 0% 2016-08-22 10:40:37,535 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 28.94 sec MapReduce Total cumulative CPU time: 28 seconds 940 msec Ended Job = job_1471603982720_0033 MapReduce Jobs Launched: Stage-Stage-1: Map: 15 Cumulative CPU: 28.94 sec HDFS Read: 67811 HDFS Write: 0 SUCCESS Total MapReduce CPU Time Spent: 28 seconds 940 msec OK Time taken: 43.937 seconds hive> select time, date(time) from user_login where date(time)='2016-05-24' limit 10; Query ID = tars_20160822104242_394085e0-4faa-41b2-8469-cd7d3ab1a1f2 Total jobs = 1 Launching Job 1 out of 1 Number of reduce tasks is set to 0 since there's no reduce operator Starting Job = job_1471603982720_0034, Tracking URL = http://cdh001:8088/proxy/application_1471603982720_0034/ Kill Command = /opt/cloudera/parcels/CDH-5.8.0-1.cdh5.8.0.p0.42/lib/hadoop/bin/hadoop job -kill job_1471603982720_0034 Hadoop job information for Stage-1: number of mappers: 15; number of reducers: 0 2016-08-22 10:42:14,425 Stage-1 map = 0%, reduce = 0% 2016-08-22 10:42:55,860 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 66.35 sec MapReduce Total cumulative CPU time: 1 minutes 6 seconds 350 msec Ended Job = job_1471603982720_0034 MapReduce Jobs Launched: Stage-Stage-1: Map: 15 Cumulative CPU: 66.35 sec HDFS Read: 68831 HDFS Write: 60 SUCCESS Total MapReduce CPU Time Spent: 1 minutes 6 seconds 350 msec OK NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Time taken: 49.602 seconds, Fetched: 10 row(s)

更新

create table ddl

CREATE TABLE user_login
(
  tour_id STRING,
  phone STRING,
  app_id STRING,
  time TIMESTAMP
)
COMMENT 'mongodb.actionlog.user.login'
STORED BY 'com.mongodb.hadoop.hive.MongoStorageHandler'
WITH SERDEPROPERTIES('mongo.columns.mapping'='{}')
TBLPROPERTIES('mongo.uri'='mongodb://10.252.223.34:30000/actionlog.user.login');

ENVS

Hadoop 2.6.0-cdh5.8.0 
Hive 1.1.0-cdh5.8.0

1 个答案:

答案 0 :(得分:0)

这适用::: select time, date(time) from user_login where date(time)=TO_DATE(from_unixtime(UNIX_TIMESTAMP('2016-05-24', "yyyy-MM-dd"))) limit 10

hive> select time, date(time) from user_login where date(time)=TO_DATE(from_unixtime(UNIX_TIMESTAMP('2016-05-24', "yyyy-MM-dd"))) limit 10
OK
2016-05-24 10:20:26 2016-05-24
2016-05-24 10:21:03 2016-05-24
2016-05-24 10:21:06 2016-05-24
2016-05-24 10:22:21 2016-05-24
2016-05-24 10:22:24 2016-05-24
2016-05-24 10:22:32 2016-05-24
2016-05-24 10:22:49 2016-05-24
2016-05-24 10:23:12 2016-05-24
2016-05-24 10:23:53 2016-05-24
2016-05-24 10:23:53 2016-05-24