Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matriv committed Oct 10, 2019
1 parent b8230f3 commit 20d18ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions docs/reference/sql/functions/date-time.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,30 @@ 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-add]]
==== `DATE_ADD/DATE_ADD/TIMESTAMPADD/TIMESTAMP_ADD`
==== `DATE_ADD/DATEADD/TIMESTAMPADD/TIMESTAMP_ADD`

.Synopsis:
[source, sql]
--------------------------------------------------
DATE_PART(
DATE_ADD(
string_exp, <1>
integer_exp, <2>
datetime_exp) <3>
--------------------------------------------------

*Input*:

<1> string expression denoting the unit to add to the date/datetime
<2> integer expression denoting how many times the above unit should be added/subtracted (if it's negative)
to/from the date/datetime
<1> string expression denoting the date/time unit to add to the date/datetime
<2> integer expression denoting how many times the above unit should be added to/from the date/datetime,
if a negative value is used it results to a subtraction from the date/datetime
<3> date/datetime expression

*Output*: datetime

.Description:

Add/Subtract the given number of units to/from a date/datetime. If any of the three arguments is `null`
a `null` is returned.
Add the given number of date/time units to a date/datetime. If the number of units is negative then it's subtracted from
the date/datetime.If any of the three arguments is `null` a `null` is returned.

This comment has been minimized.

Copy link
@astefan

astefan Oct 10, 2019

Contributor

Whitespace after dot.


[cols="^,^"]
|===
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugin/sql/qa/src/main/resources/datetime.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ DATE_ADD('mcs', -12345678, '2019-09-04T11:22:33.123Z'::datetime)::string as dt_m

selectAddWithDate
schema::dt_year:ts|dt_quarter:ts|dt_month:ts|dt_week:ts|dt_day:ts|dt_hours:ts|dt_min:ts|dt_sec:ts|dt_millis:s|dt_mcsec:s|dt_nsec:s
SELECT DATE_ADD('year', 10, '2019-09-04'::date) as dt_year, DATE_ADD('quarter', -10, '2019-09-04'::date) as dt_quarter, DATE_ADD('month', 20, '2019-09-04'::date) as dt_month,
DATE_ADD('week', -50, '2019-09-04'::date) as dt_week, DATE_ADD('day', 200, '2019-09-04'::date) as dt_day,
DATE_ADD('hours', -3000, '2019-09-04'::date) as dt_hours, DATE_ADD('minutes', 5678, '2019-09-04'::date) as dt_min, DATE_ADD('second', 987654, '2019-09-04'::date) as dt_sec,
DATE_ADD('milliseconds', 4314144, '2019-09-04'::date)::string as dt_millis, DATE_ADD('mcs', -12345678, '2019-09-04'::date)::string as dt_mcsec, DATE_ADD('nanosecond', 12345600, '2019-09-04'::date)::string as dt_nsec;
SELECT DATEADD('year', 10, '2019-09-04'::date) as dt_year, DATEADD('quarter', -10, '2019-09-04'::date) as dt_quarter, DATEADD('month', 20, '2019-09-04'::date) as dt_month,
DATEADD('week', -50, '2019-09-04'::date) as dt_week, DATEADD('day', 200, '2019-09-04'::date) as dt_day,
DATEADD('hours', -3000, '2019-09-04'::date) as dt_hours, DATEADD('minutes', 5678, '2019-09-04'::date) as dt_min, DATEADD('second', 987654, '2019-09-04'::date) as dt_sec,
DATEADD('milliseconds', 4314144, '2019-09-04'::date)::string as dt_millis, DATEADD('mcs', -12345678, '2019-09-04'::date)::string as dt_mcsec, DATEADD('nanosecond', 12345600, '2019-09-04'::date)::string as dt_nsec;

dt_year | dt_quarter | dt_month | dt_week | dt_day | dt_hours | dt_min | dt_sec | dt_millis | dt_mcsec | dt_nsec
-------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+--------------------------+-------------------------
Expand All @@ -150,9 +150,9 @@ DATE_ADD('milliseconds', 4314144, '2019-09-04'::date)::string as dt_millis, DATE

selectDateAddWithField
schema::emp_no:i|birth_date:ts|dt_year:ts|dt_quarter:ts|dt_month:ts|dt_week:ts|dt_day:ts|dt_min:ts|dt_sec:ts
SELECT emp_no, birth_date, DATE_ADD('year', 10, birth_date) as dt_year, DATE_ADD('quarter', -10, birth_date) as dt_quarter,
DATE_ADD('month', 20, birth_date) as dt_month, DATE_ADD('week', -20, birth_date) as dt_week, DATE_ADD('day', 300, birth_date) as dt_day,
DATE_ADD('minutes', 10000, birth_date) as dt_min, DATE_ADD('second', 100000, birth_date) as dt_sec
SELECT emp_no, birth_date, TIMESTAMP_ADD('year', 10, birth_date) as dt_year, TIMESTAMP_ADD('quarter', -10, birth_date) as dt_quarter,
TIMESTAMP_ADD('month', 20, birth_date) as dt_month, TIMESTAMP_ADD('week', -20, birth_date) as dt_week, TIMESTAMP_ADD('day', 300, birth_date) as dt_day,
TIMESTAMP_ADD('minutes', 10000, birth_date) as dt_min, TIMESTAMP_ADD('second', 100000, birth_date) as dt_sec
FROM test_emp WHERE emp_no >= 10032 AND emp_no <= 10042 ORDER BY 1;

emp_no | birth_date | dt_year | dt_quarter | dt_month | dt_week | dt_day | dt_min | dt_sec
Expand All @@ -171,7 +171,7 @@ FROM test_emp WHERE emp_no >= 10032 AND emp_no <= 10042 ORDER BY 1;
;

selectAddWithComplexExpressions
SELECT gender, birth_date, DATE_ADD('months', CASE WHEN gender = 'M' THEN 10 WHEN gender = 'F' THEN -10 ELSE 100 END,
SELECT gender, birth_date, TIMESTAMPADD('months', CASE WHEN gender = 'M' THEN 10 WHEN gender = 'F' THEN -10 ELSE 100 END,
birth_date + INTERVAL 10 month) AS dt FROM test_emp WHERE dt > '1954-07-01'::date ORDER BY emp_no LIMIT 10;

gender:s | birth_date:ts | dt:ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class DateAddProcessor extends ThreeArgsDateTimeProcessor {

public static final String NAME = "dtadd";

public DateAddProcessor(Processor source1, Processor source2, Processor source3, ZoneId zoneId) {
super(source1, source2, source3, zoneId);
public DateAddProcessor(Processor unit, Processor numberOfUnits, Processor timestamp, ZoneId zoneId) {
super(unit, numberOfUnits, timestamp, zoneId);
}

public DateAddProcessor(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static DateAddPipe randomDateAddPipe() {
@Override
public void testTransform() {
// test transforming only the properties (source, expression),
// skipping the children (the two parameters of the binary function) which are tested separately
// skipping the children (the three parameters of the function) which are tested separately
DateAddPipe b1 = randomInstance();

Expression newExpression = randomValueOtherThan(b1.expression(), this::randomDateAddPipeExpression);
Expand Down

0 comments on commit 20d18ae

Please sign in to comment.