Guangning Yu's Blog

Hive Basics

2015-11-18 11:44:16  |  Hive
  • Date functions
  1. -- change date format
  2. from_unixtime(unix_timestamp('20150101' ,'yyyyMMdd'), 'yyyy-MM-dd')
  3. -- add n days
  4. date_add('2015-11-01', 30) -- will return '2015-12-01'
  5. -- calculate date difference
  6. datediff('2015-12-01', '2015-11-01') -- will return 30
  • Generate row number
  1. row_number() over (DISTRIBUTE BY... SORT BY... DESC)
  • Get partition information
  1. analyze table xxx.yyy partition(dt = '2015-12-11') compute statistics;
  2. describe formated xxx.yyy partition (dt = '2015-12-11');