简体   繁体   中英

Using an UDF to query a table in Hive

I have the following UDF available on Hive to convert a time bigint to date ,

to_date(from_utc_timestamp(from_unixtime(cast(listed_time/1000 AS bigint)),'PST'))

I want to use this UDF to query a table on a specific date. Something like,

SELECT * FROM <table_name> 
WHERE date = '2020-03-01'
ORDER BY <something>
LIMIT 10

I would suggest to change the logic: avoid applying the function to the column being filtered, because it is an inefficient approach. The function needs to be invoked for every row, which prevents the query from benefiting an index.

On the other hand, you can simply convert the input date to a unix timestamp (possibly with an UDF). This should look like;

SELECT * FROM <table_name> 
WHERE date = to_utc_timestamp('2020-03-01', 'PST') * 1000
ORDER BY <something>
LIMIT 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM