Attila Jeges has uploaded a new patch set (#3). ( 
http://gerrit.cloudera.org:8080/13648 )

Change subject: IMPALA-7369: part 2: Add INTERVAL expr support and built-in 
functions for DATE
......................................................................

IMPALA-7369: part 2: Add INTERVAL expr support and built-in functions for DATE

This change implements INTERVAL expression support for DATE type and
adds several DATE related built-in functions.

The following functions are supported in Hive:

  INT YEAR(DATE d)
  Extracts year of the 'd' date, returns it as an int in 0-9999 range.

  INT MONTH(DATE d)
  Extracts month of the 'd' date and returns it as an int in 1-12
  range.

  INT DAY(DATE d), INT DAYOFMONTH(DATE d)
  Extracts day-of-month of the 'd' date and returns it as an int in
  1-31 range.

  INT QUARTER(DATE d)
  Extracts quarter of the 'd' date and returns it as an int in 1-4
  range.

  INT DAYOFWEEK(DATE d)
  Extracts day-of-week of the 'd' date and returns it as an int in
  1-7 range. 1 is Sunday and 7 is Saturday.

  INT DAYOFYEAR(DATE d)
  Extracts day-of-year of the 'd' date and returns it as an int in
  1-366 range.

  INT WEEKOFYEAR(DATE d)
  Extracts week-of-year of the 'd' date and returns it as an int in
  1-53 range.

  STRING DAYNAME(DATE d)
  Returns the day field from a 'd' date, converted to the string
  corresponding to that day name. The range of return values is
  "Sunday" to "Saturday".

  STRING MONTHNAME(DATE d)
  Returns the month field from a 'd' date, converted to the string
  corresponding to that month name. The range of return values is
  "January" to "December".

  DATE NEXT_DAY(DATE d, STRING weekday)
  Returns the first date which is later than 'd' and named as
  'weekday'. 'weekday' is 3 letters or full name of the day of the
  week.

  DATE LAST_DAY(DATE d)
  Returns the last day of the month which the 'd' date belongs to.

  INT DATEDIFF(DATE d1, DATE d2)
  Returns the number of days from 'd1' date to 'd2' date.

  DATE CURRENT_DATE()
  Returns the current date (in the local time zone).

  INT INT_MONTHS_BETWEEN(DATE d1, DATE d2)
  Returns the number of months between 'd1' and 'd2' dates, as an int
  representing only the full months that passed.
  If 'd1' represents an earlier date than 'd2', the result is
  negative.

  DOUBLE MONTHS_BETWEEN(DATE d1, DATE d2)
  Returns the number of months between 'd1' and 'd2' dates. Can
  include a fractional part representing extra days in addition to the
  full months between the dates. The fractional component is computed
  by dividing the difference in days by 31 (regardless of the month).
  If 'd1' represents an earlier date than 'd2', the result is
  negative.

  DATE ADD_YEARS(DATE d, INT/BIGINT num_years),
  DATE SUB_YEARS(DATE d, INT/BIGINT num_years)
  Adds/subtracts a specified number of years to a 'd' date value.

  DATE ADD_MONTHS(DATE d, INT/BIGINT num_months),
  DATE SUB_MONTHS(DATE d, INT/BIGINT num_months)
  Adds/subtracts a specified number of months to a date value.
  If 'd' is the last day of a month, the returned date will fall on
  the last day of the target month too.

  DATE ADD_DAYS(DATE d, INT/BIGINT num_days),
  DATE SUB_DAYS(DATE d, INT/BIGINT num_days)
  Adds/subtracts a specified number of days to a date value.

  DATE ADD_WEEKS(DATE d, INT/BIGINT num_weeks),
  DATE SUB_WEEKS(DATE d, INT/BIGINT num_weeks)
  Adds/subtracts a specified number of weeks to a date value.

The following function doesn't exist in Hive but supported by Amazon
Redshift

  INT DATE_CMP(DATE d1, DATE d2)
  Compares 'd1' and 'd2' dates. Returns:
  1. NULL, if either 'd1' or 'd2' is NULL
  2. -1 if d1 < d2
  3. 1 if d1 > d2
  4. 0 if d1 == d2
  (https://docs.aws.amazon.com/redshift/latest/dg/r_DATE_CMP.html)

Change-Id: If404bffdaf055c769e79ffa8f193bac415cfdd1a
---
M be/src/benchmarks/date-benchmark.cc
M be/src/codegen/impala-ir.cc
M be/src/exprs/CMakeLists.txt
A be/src/exprs/date-functions-ir.cc
A be/src/exprs/date-functions.h
M be/src/exprs/expr-test.cc
M be/src/exprs/scalar-expr-evaluator.cc
M be/src/exprs/timestamp-functions-ir.cc
M be/src/exprs/timestamp-functions.cc
M be/src/exprs/timestamp-functions.h
M be/src/exprs/udf-builtins.cc
M be/src/runtime/date-test.cc
M be/src/runtime/date-value.cc
M be/src/runtime/date-value.h
M common/function-registry/impala_functions.py
M fe/src/main/java/org/apache/impala/analysis/TimestampArithmeticExpr.java
M fe/src/test/java/org/apache/impala/analysis/AnalyzeExprsTest.java
17 files changed, 1,676 insertions(+), 174 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/48/13648/3
--
To view, visit http://gerrit.cloudera.org:8080/13648
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: If404bffdaf055c769e79ffa8f193bac415cfdd1a
Gerrit-Change-Number: 13648
Gerrit-PatchSet: 3
Gerrit-Owner: Attila Jeges <atti...@cloudera.com>
Gerrit-Reviewer: Attila Jeges <atti...@cloudera.com>
Gerrit-Reviewer: Csaba Ringhofer <csringho...@cloudera.com>
Gerrit-Reviewer: Impala Public Jenkins <impala-public-jenk...@cloudera.com>

Reply via email to