Created on 09-25-2017 02:53 AM - last edited on 09-16-2022 05:17 AM by kh-asen
Hi,
I have a table in Hbase and want to access through impala.
The table has a row key combination of three columns (abcshsk#2017-08-01 00:00:00.0#cpu)
Three columns (string,timestamp,string) this is my row key now.
I have to write a Impala query to display column1, timestamp as Day,column 2 from table name where condition 1 and condition 2 order by day,timestamp.
The question is how to cast a timestamp in impala to date?
Cast(timestamp,date) is not there. how to do?
I used to_date(timestamp)
I can able to display Day from the query result.
condition two is date range.
how to select date ranges using timestamp( date range between) ?
how to order by Day and to_date(timestamp) ?
will order by work in Hbase? whatever column in order by i use i am not able to order.
I tried order by a double data type column also.
any condition in impala to use order by in hbase?
pls suggest. Thanks.
Created 09-25-2017 07:30 AM
Impala doesn't have a date data type, it does have a timestamp type though: https://www.cloudera.com/documentation/enterprise/latest/topics/impala_timestamp.html. to_date() converts timestamp to a string.https://www.cloudera.com/documentation/enterprise/latest/topics/impala_datetime_functions.html
If you want to remove the time portion of the timestamp you can use trunc(ts, "DD") to get the timestamp of midnight on that day: https://www.cloudera.com/documentation/enterprise/latest/topics/impala_datetime_functions.html
I don't understand your question about "order by". Order by should work for all scalar data types in Impala (timestamp, double, etc). What do you want it to do and what is it doing now?
Created 09-25-2017 07:37 AM
Created 09-25-2017 10:03 AM
I'd expect ORDER BY trunc(ts, "DD") to work. E.g. on my system this works:
[localhost:21000] > select timestamp_col, tinyint_col from functional_hbase.alltypestiny order by trunc(timestamp_col, 'DD'), tinyint_col desc; +---------------------+-------------+ | timestamp_col | tinyint_col | +---------------------+-------------+ | 2009-01-01 00:01:00 | 1 | | 2009-01-01 00:00:00 | 0 | | 2009-02-01 00:01:00 | 1 | | 2009-02-01 00:00:00 | 0 | | 2009-03-01 00:01:00 | 1 | | 2009-03-01 00:00:00 | 0 | | 2009-04-01 00:01:00 | 1 | | 2009-04-01 00:00:00 | 0 | +---------------------+-------------+
Created 09-25-2017 07:20 PM
Hi,
Hbase table
table in hbase
hbid is combination of 3 columns. two string and one timestamp column
anhdu6jbc#cpu#2017-08-01 00:00:09.0= hostname#matrix__timestamp
hbid- anhdu6jbc#cpu__2017-08-01 00:00:09.0
country-string-addf
matrix_value- double-8.9
select extract(split_part(hbid,'_',3),"day") as Day,split_part(split_part(hbid,'_',2),'#',1) as Hostname,split_part(hbid,'_',3) as starttime,matrix_value from table where split_part(split_part(hbid,'_',2),'#',2)='cpu'and matrix_value <=100 and split_part(split_part(hbid,'_',2),'#',1)='2jdnca' and (to_date(split_part(hbid,'_',3)) >= '2017-08-01' and to_date(split_part(hbid,'_',3)) <= '2017-08-08') order by matrix_value limit 10
Exception
select extract(split_part(hbid,'_',3),"day") as Day,split_part(split_part(hbid,'_',2),'#',1) as Hostname,split_part(hbid,'_',3) as starttime,matrix_value from tablename where split_part(split_part(hbid,'_',2),'#',2)='cpu'and matrix_value <=100 and split_part(split_part(hbid,'_',2),'#',1)='shdjd1d' order by trunc(split_part(hbid,'_',3),'DD')
Exception