From 07d22a80e6cb96cb72309cf8d62317405cd50da7 Mon Sep 17 00:00:00 2001 From: Marios Trivyzas Date: Thu, 26 Sep 2019 17:38:03 +0300 Subject: [PATCH 1/2] SQL: Add alias DATETRUNC to DATE_TRUNC function To be on the safe side in terms of use cases also add the alias DATETRUNC to the DATE_TRUNC function. Follows: #46473 --- docs/reference/sql/functions/date-time.asciidoc | 2 +- x-pack/plugin/sql/qa/src/main/resources/command.csv-spec | 1 + x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec | 5 +++-- .../xpack/sql/expression/function/FunctionRegistry.java | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/reference/sql/functions/date-time.asciidoc b/docs/reference/sql/functions/date-time.asciidoc index 3f515ec98e2df..b0d5a395cf90b 100644 --- a/docs/reference/sql/functions/date-time.asciidoc +++ b/docs/reference/sql/functions/date-time.asciidoc @@ -249,7 +249,7 @@ Currently, using a _precision_ greater than 3 doesn't make any difference to the function as the maximum number of second fractional digits returned is 3 (milliseconds). [[sql-functions-datetime-trunc]] -==== `DATE_TRUNC` +==== `DATE_TRUNC/DATETRUNC` .Synopsis: [source, sql] diff --git a/x-pack/plugin/sql/qa/src/main/resources/command.csv-spec b/x-pack/plugin/sql/qa/src/main/resources/command.csv-spec index abb1175cb2f86..ead39e735d026 100644 --- a/x-pack/plugin/sql/qa/src/main/resources/command.csv-spec +++ b/x-pack/plugin/sql/qa/src/main/resources/command.csv-spec @@ -39,6 +39,7 @@ CURRENT_DATE |SCALAR CURRENT_TIME |SCALAR CURRENT_TIMESTAMP|SCALAR CURTIME |SCALAR +DATETRUNC |SCALAR DATE_TRUNC |SCALAR DAY |SCALAR DAYNAME |SCALAR diff --git a/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec b/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec index 7198da9319cdb..bfb8c1c4d624a 100644 --- a/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec +++ b/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec @@ -235,6 +235,7 @@ CURRENT_DATE |SCALAR CURRENT_TIME |SCALAR CURRENT_TIMESTAMP|SCALAR CURTIME |SCALAR +DATETRUNC |SCALAR DATE_TRUNC |SCALAR DAY |SCALAR DAYNAME |SCALAR @@ -2425,7 +2426,7 @@ SELECT DATE_TRUNC('millennium', '2019-09-04T11:22:33.123Z'::datetime) AS millenn truncateDateTimeWeek // tag::truncateDateTimeWeek -SELECT DATE_TRUNC('week', '2019-08-24T11:22:33.123Z'::datetime) AS week; +SELECT DATETRUNC('week', '2019-08-24T11:22:33.123Z'::datetime) AS week; week ------------------------ @@ -2457,7 +2458,7 @@ SELECT DATE_TRUNC('decade', CAST('2019-09-04' AS DATE)) AS decades; truncateDateQuarter schema::quarter:ts // tag::truncateDateQuarter -SELECT DATE_TRUNC('quarters', CAST('2019-09-04' AS DATE)) AS quarter; +SELECT DATETRUNC('quarters', CAST('2019-09-04' AS DATE)) AS quarter; quarter ------------------------ diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java index 0ebe256fe0999..0fbfab890c67e 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/function/FunctionRegistry.java @@ -194,7 +194,7 @@ private void defineDefaultFunctions() { def(DayOfMonth.class, DayOfMonth::new, "DAY_OF_MONTH", "DAYOFMONTH", "DAY", "DOM"), def(DayOfWeek.class, DayOfWeek::new, "DAY_OF_WEEK", "DAYOFWEEK", "DOW"), def(DayOfYear.class, DayOfYear::new, "DAY_OF_YEAR", "DAYOFYEAR", "DOY"), - def(DateTrunc.class, DateTrunc::new, "DATE_TRUNC"), + def(DateTrunc.class, DateTrunc::new, "DATETRUNC", "DATE_TRUNC"), def(HourOfDay.class, HourOfDay::new, "HOUR_OF_DAY", "HOUR"), def(IsoDayOfWeek.class, IsoDayOfWeek::new, "ISO_DAY_OF_WEEK", "ISODAYOFWEEK", "ISODOW", "IDOW"), def(IsoWeekOfYear.class, IsoWeekOfYear::new, "ISO_WEEK_OF_YEAR", "ISOWEEKOFYEAR", "ISOWEEK", "IWOY", "IW"), From f78771ebe70912ecd54fd9061488d4962362082f Mon Sep 17 00:00:00 2001 From: Marios Trivyzas Date: Fri, 27 Sep 2019 13:44:42 +0300 Subject: [PATCH 2/2] mention the null behaviour --- docs/reference/sql/functions/date-time.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/sql/functions/date-time.asciidoc b/docs/reference/sql/functions/date-time.asciidoc index b0d5a395cf90b..510137ad13c63 100644 --- a/docs/reference/sql/functions/date-time.asciidoc +++ b/docs/reference/sql/functions/date-time.asciidoc @@ -269,7 +269,7 @@ DATE_TRUNC( .Description: Truncate the date/datetime to the specified unit by setting all fields that are less significant than the specified -one to zero (or one, for day, day of week and month). +one to zero (or one, for day, day of week and month). If any of the two arguments is `null` a `null` is returned. [cols="^,^"] |===