PREHOOK: query: describe function months_between PREHOOK: type: DESCFUNCTION POSTHOOK: query: describe function months_between POSTHOOK: type: DESCFUNCTION months_between(date1, date2) - returns number of months between dates date1 and date2 PREHOOK: query: desc function extended months_between PREHOOK: type: DESCFUNCTION POSTHOOK: query: desc function extended months_between POSTHOOK: type: DESCFUNCTION months_between(date1, date2) - returns number of months between dates date1 and date2 If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise the UDF calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2. date1 and date2 type can be date, timestamp or string in the format 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'. The result is rounded to 8 decimal places. Example: > SELECT months_between('1997-02-28 10:30:00', '1996-10-30'); 3.94959677 PREHOOK: query: --test string format explain select months_between('1995-02-02', '1995-01-01') PREHOOK: type: QUERY POSTHOOK: query: --test string format explain select months_between('1995-02-02', '1995-01-01') POSTHOOK: type: QUERY STAGE DEPENDENCIES: Stage-0 is a root stage STAGE PLANS: Stage: Stage-0 Fetch Operator limit: -1 Processor Tree: TableScan alias: _dummy_table Row Limit Per Split: 1 Statistics: Num rows: 0 Data size: 1 Basic stats: PARTIAL Column stats: COMPLETE Select Operator expressions: 1.03225806 (type: double) outputColumnNames: _col0 Statistics: Num rows: 0 Data size: 1 Basic stats: PARTIAL Column stats: COMPLETE ListSink PREHOOK: query: select months_between('1995-02-02', '1995-01-01'), months_between('2003-07-17', '2005-07-06'), months_between('2001-06-30', '2000-05-31'), months_between('2000-06-01', '2004-07-01'), months_between('2002-02-28', '2002-03-01'), months_between('2002-02-31', '2002-03-01'), months_between('2012-02-29', '2012-03-01'), months_between('2012-02-31', '2012-03-01'), months_between('1976-01-01 00:00:00', '1975-12-31 23:59:59'), months_between('1976-01-01', '1975-12-31 23:59:59'), months_between('1997-02-28 10:30:00', '1996-10-30'), -- if both are last day of the month then time part should be ignored months_between('2002-03-31', '2002-02-28'), months_between('2002-03-31', '2002-02-28 10:30:00'), months_between('2002-03-31 10:30:00', '2002-02-28'), -- if the same day of the month then time part should be ignored months_between('2002-03-24', '2002-02-24'), months_between('2002-03-24', '2002-02-24 10:30:00'), months_between('2002-03-24 10:30:00', '2002-02-24'), -- partial time. time part will be skipped months_between('1995-02-02 10:39', '1995-01-01'), months_between('1995-02-02', '1995-01-01 10:39'), -- no leading 0 for month and day should work months_between('1995-02-2', '1995-1-01'), months_between('1995-2-02', '1995-01-1'), -- short year should work months_between('495-2-02', '495-01-1'), months_between('95-2-02', '95-01-1'), months_between('5-2-02', '5-01-1') PREHOOK: type: QUERY PREHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### POSTHOOK: query: select months_between('1995-02-02', '1995-01-01'), months_between('2003-07-17', '2005-07-06'), months_between('2001-06-30', '2000-05-31'), months_between('2000-06-01', '2004-07-01'), months_between('2002-02-28', '2002-03-01'), months_between('2002-02-31', '2002-03-01'), months_between('2012-02-29', '2012-03-01'), months_between('2012-02-31', '2012-03-01'), months_between('1976-01-01 00:00:00', '1975-12-31 23:59:59'), months_between('1976-01-01', '1975-12-31 23:59:59'), months_between('1997-02-28 10:30:00', '1996-10-30'), -- if both are last day of the month then time part should be ignored months_between('2002-03-31', '2002-02-28'), months_between('2002-03-31', '2002-02-28 10:30:00'), months_between('2002-03-31 10:30:00', '2002-02-28'), -- if the same day of the month then time part should be ignored months_between('2002-03-24', '2002-02-24'), months_between('2002-03-24', '2002-02-24 10:30:00'), months_between('2002-03-24 10:30:00', '2002-02-24'), -- partial time. time part will be skipped months_between('1995-02-02 10:39', '1995-01-01'), months_between('1995-02-02', '1995-01-01 10:39'), -- no leading 0 for month and day should work months_between('1995-02-2', '1995-1-01'), months_between('1995-2-02', '1995-01-1'), -- short year should work months_between('495-2-02', '495-01-1'), months_between('95-2-02', '95-01-1'), months_between('5-2-02', '5-01-1') POSTHOOK: type: QUERY POSTHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### 1.03225806 -23.64516129 13.0 -49.0 -0.12903226 0.06451613 -0.09677419 0.03225806 3.7E-7 3.7E-7 3.94959677 1.0 1.0 1.0 1.0 1.0 1.0 1.03225806 1.03225806 1.03225806 1.03225806 1.03225806 1.03225806 1.03225806 PREHOOK: query: --test timestamp format select months_between(cast('1995-02-02 00:00:00' as timestamp), cast('1995-01-01 00:00:00' as timestamp)), months_between(cast('2003-07-17 00:00:00' as timestamp), cast('2005-07-06 00:00:00' as timestamp)), months_between(cast('2001-06-30 00:00:00' as timestamp), cast('2000-05-31 00:00:00' as timestamp)), months_between(cast('2000-06-01 00:00:00' as timestamp), cast('2004-07-01 00:00:00' as timestamp)), months_between(cast('2002-02-28 00:00:00' as timestamp), cast('2002-03-01 00:00:00' as timestamp)), months_between(cast('2002-02-31 00:00:00' as timestamp), cast('2002-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-29 00:00:00' as timestamp), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-31 00:00:00' as timestamp), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('1976-01-01 00:00:00' as timestamp), cast('1975-12-31 23:59:59' as timestamp)), months_between(cast('1976-01-01' as date), cast('1975-12-31 23:59:59' as timestamp)), months_between(cast('1997-02-28 10:30:00' as timestamp), cast('1996-10-30' as date)), -- if both are last day of the month then time part should be ignored months_between(cast('2002-03-31 00:00:00' as timestamp), cast('2002-02-28 00:00:00' as timestamp)), months_between(cast('2002-03-31 00:00:00' as timestamp), cast('2002-02-28 10:30:00' as timestamp)), months_between(cast('2002-03-31 10:30:00' as timestamp), cast('2002-02-28 00:00:00' as timestamp)), -- if the same day of the month then time part should be ignored months_between(cast('2002-03-24 00:00:00' as timestamp), cast('2002-02-24 00:00:00' as timestamp)), months_between(cast('2002-03-24 00:00:00' as timestamp), cast('2002-02-24 10:30:00' as timestamp)), months_between(cast('2002-03-24 10:30:00' as timestamp), cast('2002-02-24 00:00:00' as timestamp)) PREHOOK: type: QUERY PREHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### POSTHOOK: query: --test timestamp format select months_between(cast('1995-02-02 00:00:00' as timestamp), cast('1995-01-01 00:00:00' as timestamp)), months_between(cast('2003-07-17 00:00:00' as timestamp), cast('2005-07-06 00:00:00' as timestamp)), months_between(cast('2001-06-30 00:00:00' as timestamp), cast('2000-05-31 00:00:00' as timestamp)), months_between(cast('2000-06-01 00:00:00' as timestamp), cast('2004-07-01 00:00:00' as timestamp)), months_between(cast('2002-02-28 00:00:00' as timestamp), cast('2002-03-01 00:00:00' as timestamp)), months_between(cast('2002-02-31 00:00:00' as timestamp), cast('2002-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-29 00:00:00' as timestamp), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-31 00:00:00' as timestamp), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('1976-01-01 00:00:00' as timestamp), cast('1975-12-31 23:59:59' as timestamp)), months_between(cast('1976-01-01' as date), cast('1975-12-31 23:59:59' as timestamp)), months_between(cast('1997-02-28 10:30:00' as timestamp), cast('1996-10-30' as date)), -- if both are last day of the month then time part should be ignored months_between(cast('2002-03-31 00:00:00' as timestamp), cast('2002-02-28 00:00:00' as timestamp)), months_between(cast('2002-03-31 00:00:00' as timestamp), cast('2002-02-28 10:30:00' as timestamp)), months_between(cast('2002-03-31 10:30:00' as timestamp), cast('2002-02-28 00:00:00' as timestamp)), -- if the same day of the month then time part should be ignored months_between(cast('2002-03-24 00:00:00' as timestamp), cast('2002-02-24 00:00:00' as timestamp)), months_between(cast('2002-03-24 00:00:00' as timestamp), cast('2002-02-24 10:30:00' as timestamp)), months_between(cast('2002-03-24 10:30:00' as timestamp), cast('2002-02-24 00:00:00' as timestamp)) POSTHOOK: type: QUERY POSTHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### 1.03225806 -23.64516129 13.0 -49.0 -0.12903226 0.06451613 -0.09677419 0.03225806 3.7E-7 3.7E-7 3.94959677 1.0 1.0 1.0 1.0 1.0 1.0 PREHOOK: query: --test date format select months_between(cast('1995-02-02' as date), cast('1995-01-01' as date)), months_between(cast('2003-07-17' as date), cast('2005-07-06' as date)), months_between(cast('2001-06-30' as date), cast('2000-05-31' as date)), months_between(cast('2000-06-01' as date), cast('2004-07-01' as date)), months_between(cast('2002-02-28' as date), cast('2002-03-01' as date)), months_between(cast('2002-02-31' as date), cast('2002-03-01' as date)), months_between(cast('2012-02-29' as date), cast('2012-03-01' as date)), months_between(cast('2012-02-31' as date), cast('2012-03-01' as date)) PREHOOK: type: QUERY PREHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### POSTHOOK: query: --test date format select months_between(cast('1995-02-02' as date), cast('1995-01-01' as date)), months_between(cast('2003-07-17' as date), cast('2005-07-06' as date)), months_between(cast('2001-06-30' as date), cast('2000-05-31' as date)), months_between(cast('2000-06-01' as date), cast('2004-07-01' as date)), months_between(cast('2002-02-28' as date), cast('2002-03-01' as date)), months_between(cast('2002-02-31' as date), cast('2002-03-01' as date)), months_between(cast('2012-02-29' as date), cast('2012-03-01' as date)), months_between(cast('2012-02-31' as date), cast('2012-03-01' as date)) POSTHOOK: type: QUERY POSTHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### 1.03225806 -23.64516129 13.0 -49.0 -0.12903226 0.06451613 -0.09677419 0.03225806 PREHOOK: query: --test misc with null select months_between(cast(null as string), '2012-03-01'), months_between('2012-02-31', cast(null as timestamp)), months_between(cast(null as timestamp), cast(null as date)), months_between(cast(null as string), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-31 00:00:00' as timestamp), cast(null as string)), months_between(cast(null as timestamp), cast('2012-03-01' as string)), months_between(cast('2012-02-31' as date), cast(null as string)), months_between('2012-02-10', cast(null as string)), months_between(cast(null as string), '2012-02-10'), months_between(cast(null as string), cast(null as string)), months_between('2012-02-10', cast(null as timestamp)), months_between(cast(null as timestamp), '2012-02-10'), months_between(cast(null as timestamp), cast(null as timestamp)), -- string dates without day should be parsed to null months_between('2012-03', '2012-02-24'), months_between('2012-03-24', '2012-02') PREHOOK: type: QUERY PREHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### POSTHOOK: query: --test misc with null select months_between(cast(null as string), '2012-03-01'), months_between('2012-02-31', cast(null as timestamp)), months_between(cast(null as timestamp), cast(null as date)), months_between(cast(null as string), cast('2012-03-01 00:00:00' as timestamp)), months_between(cast('2012-02-31 00:00:00' as timestamp), cast(null as string)), months_between(cast(null as timestamp), cast('2012-03-01' as string)), months_between(cast('2012-02-31' as date), cast(null as string)), months_between('2012-02-10', cast(null as string)), months_between(cast(null as string), '2012-02-10'), months_between(cast(null as string), cast(null as string)), months_between('2012-02-10', cast(null as timestamp)), months_between(cast(null as timestamp), '2012-02-10'), months_between(cast(null as timestamp), cast(null as timestamp)), -- string dates without day should be parsed to null months_between('2012-03', '2012-02-24'), months_between('2012-03-24', '2012-02') POSTHOOK: type: QUERY POSTHOOK: Input: _dummy_database@_dummy_table #### A masked pattern was here #### NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL