Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 01-05-2016 02:32 PM
From the https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
trunc(string date, string format)
I'm executing these commands in beeline:
0: jdbc:hive2://> select trunc(current_timestamp(), 'MM'); OK +-------------+--+ | _c0 | +-------------+--+ | 2016-01-01 | +-------------+--+ 1 row selected (0.97 seconds) 0: jdbc:hive2://> select trunc(current_timestamp(), 'DD'); OK +-------+--+ | _c0 | +-------+--+ | NULL | +-------+--+ 1 row selected (0.241 seconds)
Now, the question is why doesn't it support a day value? This is such a natural function for truncating timestamps to a day only.
Created 01-05-2016 02:42 PM
Through experiments I found this one works as expected:
jdbc:hive2://> select date_sub(current_timestamp(), 0); OK +-------------+--+ | _c0 | +-------------+--+ | 2016-01-05 | +-------------+--+
Which is much harder than it should be. Given how much legacy SQL there is relying on trunc(timestamp), can we enhance the Hive's function to throw the timestamp out too maybe?
Created 01-05-2016 02:42 PM
Through experiments I found this one works as expected:
jdbc:hive2://> select date_sub(current_timestamp(), 0); OK +-------------+--+ | _c0 | +-------------+--+ | 2016-01-05 | +-------------+--+
Which is much harder than it should be. Given how much legacy SQL there is relying on trunc(timestamp), can we enhance the Hive's function to throw the timestamp out too maybe?
Created 01-05-2016 04:46 PM
I found that to_date() function generates correct data types which will work correctly with comparisons and ordering.
Created 10-28-2020 03:21 AM