From a92e1d004897ff9b2f811621441c0c6b32b64598 Mon Sep 17 00:00:00 2001 From: prabal864 <159599201+Prabal864@users.noreply.github.com> Date: Sat, 22 Aug 2026 06:28:26 +0530 Subject: [PATCH 1/2] HIVE-28117: Fix misleading YYYY date pattern in add_months() documentation GenericUDFAddMonths's @Description Javadoc documented the default output format and its example using the uppercase pattern YYYY-MM-dd. In Java's SimpleDateFormat, uppercase Y means the ISO week-based year, not the calendar year - a different field from lowercase y. The actual default formatter used by the code (DateUtils.getDateFormat()) already correctly uses lowercase "yyyy-MM-dd"; only the documentation string was wrong. A user who follows the documented example and passes a custom output_date_format containing YYYY (as literally shown in Hive's own docs) gets silently wrong output near year boundaries, exactly as reported in HIVE-28117: add_months(dt, -2, 'YYYY-MM') on 2024-02-29 returned '2024-12' instead of '2023-12'. Also normalizes the same pattern in TestGenericUDFAddMonths's fixture constants, which perpetuated the same wrong-case convention. No existing assertion uses an output date within the ISO week-year boundary window, so this doesn't change any expected test result. No runtime behavior changes - this is a documentation-string-only fix. --- .../hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java | 4 ++-- .../hive/ql/udf/generic/TestGenericUDFAddMonths.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java index 82e877219ed0..5190f40d46da 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java @@ -53,9 +53,9 @@ + "Returns the date that is num_months after start_date.", extended = "start_date is a string or timestamp indicating a valid date. " + "num_months is a number. output_date_format is an optional String which specifies the format for output.\n" - + "The default output format is 'YYYY-MM-dd'.\n" + + "The default output format is 'yyyy-MM-dd'.\n" + "Example:\n > SELECT _FUNC_('2009-08-31', 1) FROM src LIMIT 1;\n" + " '2009-09-30'." - + "\n > SELECT _FUNC_('2017-12-31 14:15:16', 2, 'YYYY-MM-dd HH:mm:ss') LIMIT 1;\n" + + "\n > SELECT _FUNC_('2017-12-31 14:15:16', 2, 'yyyy-MM-dd HH:mm:ss') LIMIT 1;\n" + "'2018-02-28 14:15:16'.\n") @NDV(maxNdv = 250) // 250 seems to be reasonable upper limit for this public class GenericUDFAddMonths extends GenericUDF { diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java index be8b9d14a0f4..e0ad69428c29 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFAddMonths.java @@ -43,10 +43,10 @@ */ public class TestGenericUDFAddMonths { - private final Text fmtTextWithTime = new Text("YYYY-MM-dd HH:mm:ss"); - private final Text fmtTextWithTimeAndms = new Text("YYYY-MM-dd HH:mm:ss.SSS"); - private final Text fmtTextWithoutTime = new Text("YYYY-MM-dd"); - private final Text fmtTextInvalid = new Text("YYYY-abcdz"); + private final Text fmtTextWithTime = new Text("yyyy-MM-dd HH:mm:ss"); + private final Text fmtTextWithTimeAndms = new Text("yyyy-MM-dd HH:mm:ss.SSS"); + private final Text fmtTextWithoutTime = new Text("yyyy-MM-dd"); + private final Text fmtTextInvalid = new Text("yyyy-abcdz"); @Test public void testAddMonthsInt() throws HiveException { From d9589172340c3087709836fe993222e1065d5e02 Mon Sep 17 00:00:00 2001 From: Prabal Pratap Singh <159599201+Prabal864@users.noreply.github.com> Date: Sun, 23 Aug 2026 13:16:26 +0530 Subject: [PATCH 2/2] HIVE-28117: Update udf_add_months.q.out for yyyy-MM-dd doc format change --- ql/src/test/results/clientpositive/llap/udf_add_months.q.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ql/src/test/results/clientpositive/llap/udf_add_months.q.out b/ql/src/test/results/clientpositive/llap/udf_add_months.q.out index 61f9e07fad02..919d8039252d 100644 --- a/ql/src/test/results/clientpositive/llap/udf_add_months.q.out +++ b/ql/src/test/results/clientpositive/llap/udf_add_months.q.out @@ -9,11 +9,11 @@ POSTHOOK: query: DESCRIBE FUNCTION EXTENDED add_months POSTHOOK: type: DESCFUNCTION add_months(start_date, num_months, output_date_format) - Returns the date that is num_months after start_date. start_date is a string or timestamp indicating a valid date. num_months is a number. output_date_format is an optional String which specifies the format for output. -The default output format is 'YYYY-MM-dd'. +The default output format is 'yyyy-MM-dd'. Example: > SELECT add_months('2009-08-31', 1) FROM src LIMIT 1; '2009-09-30'. - > SELECT add_months('2017-12-31 14:15:16', 2, 'YYYY-MM-dd HH:mm:ss') LIMIT 1; + > SELECT add_months('2017-12-31 14:15:16', 2, 'yyyy-MM-dd HH:mm:ss') LIMIT 1; '2018-02-28 14:15:16'. Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFAddMonths