Skip to content

Commit 26cca18

Browse files
committed
Address comments
1 parent abf331e commit 26cca18

File tree

14 files changed

+1811
-1950
lines changed

14 files changed

+1811
-1950
lines changed

docs/reference/sql/functions/date-time.asciidoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ include-tagged::{sql-specs}/docs.csv-spec[dtIntervalMul]
9494
beta[]
9595

9696
[[sql-functions-current-date]]
97-
==== `CURRENT_TIMESTAMP/CURDATE`
97+
==== `CURRENT_DATE/CURDATE`
9898

9999
.Synopsis:
100100
[source, sql]
@@ -115,7 +115,7 @@ It can be used both as a keyword: `CURRENT_DATE` or as a function with no argume
115115
[NOTE]
116116
Unlike CURRENT_DATE, `CURDATE()` can only be used as a function with no arguments and not as a keyword.
117117

118-
This method always returns the same value within a query.
118+
This method always returns the same value for its every occurrence within the same query.
119119

120120
["source","sql",subs="attributes,callouts,macros"]
121121
--------------------------------------------------
@@ -157,7 +157,7 @@ Returns the date/time when the current query reached the server.
157157
As a function, `CURRENT_TIMESTAMP()` accepts _precision_ as an optional
158158
parameter for rounding the second fractional digits (nanoseconds).
159159

160-
This method always returns the same value within a query.
160+
This method always returns the same value for its every occurrence within the same query.
161161

162162
["source","sql",subs="attributes,callouts,macros"]
163163
--------------------------------------------------
@@ -464,7 +464,8 @@ NOW()
464464
.Description:
465465

466466
This function offers the same functionality as <<sql-functions-current-timestamp,CURRENT_TIMESTAMP()>> function: returns
467-
the datetime when the current query reached the server. This method always returns the same value within a query.
467+
the datetime when the current query reached the server. This method always returns the same value for its every
468+
occurrence within the same query.
468469

469470
["source","sql",subs="attributes,callouts,macros"]
470471
--------------------------------------------------
@@ -543,7 +544,8 @@ TODAY()
543544
.Description:
544545

545546
This function offers the same functionality as <<sql-functions-current-date,CURRENT_DATE()>> function: returns
546-
the date when the current query reached the server. This method always returns the same value within a query.
547+
the date when the current query reached the server. This method always returns the same value for its every occurrence
548+
within the same query.
547549

548550
["source","sql",subs="attributes,callouts,macros"]
549551
--------------------------------------------------

x-pack/plugin/sql/qa/src/main/resources/date.csv-spec

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ SELECT YEAR(TODAY()) / 1000 AS result;
2727
;
2828

2929
todayIntervalSubstraction
30-
SELECT YEAR(TODAY() - INTERVAL 2 YEARS) / 1000 AS result;
30+
SELECT TRUNCATE(YEAR(TODAY() - INTERVAL 50 YEARS) / 1000) AS result;
3131

3232
result
3333
---------------
34-
2
34+
1
3535
;
3636

3737

@@ -53,20 +53,20 @@ Tuval
5353
;
5454

5555
currentDateFilterScript
56-
SELECT first_name FROM test_emp WHERE YEAR(hire_date) - YEAR(TODAY()) / 1000 > 10 ORDER BY first_name ASC LIMIT 10;
57-
58-
first_name
59-
---------------
60-
Alejandro
61-
Amabile
62-
Anneke
63-
Anoosh
64-
Arumugam
65-
Basil
66-
Berhard
67-
Berni
68-
Bezalel
69-
Bojan
56+
SELECT first_name, TRUNCATE(YEAR(hire_date) - YEAR(TODAY()) / 1000) AS filter FROM test_emp
57+
WHERE TRUNCATE(YEAR(hire_date) - YEAR(TODAY()) / 1000) > 1990 ORDER BY first_name ASC LIMIT 10;
58+
59+
first_name | filter
60+
Cristinel |1991
61+
Kazuhito |1993
62+
Kenroku |1992
63+
Lillian |1997
64+
Magy |1991
65+
Mayumi |1993
66+
Mingsen |1992
67+
Sailaja |1994
68+
Saniya |1992
69+
Shahaf |1993
7070
;
7171

7272
dateExtractDateParts
@@ -142,3 +142,23 @@ SELECT YEAR(CAST('2019-01-21' AS DATE) + INTERVAL '1-2' YEAR TO MONTH) AS y, MON
142142
y:i | m:i
143143
2020 | 3
144144
;
145+
146+
orderByCurrentDate
147+
SELECT first_name FROM test_emp ORDER BY TODAY(), first_name LIMIT 5;
148+
149+
first_name
150+
---------------
151+
Alejandro
152+
Amabile
153+
Anneke
154+
Anoosh
155+
Arumugam
156+
;
157+
158+
groupByCurrentDate
159+
SELECT MAX(salary) FROM test_emp GROUP BY TODAY();
160+
161+
MAX(salary)
162+
---------------
163+
74999
164+
;

x-pack/plugin/sql/qa/src/main/resources/datetime.sql-spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ SELECT DAY_OF_WEEK(birth_date) day, COUNT(*) c FROM test_emp WHERE DAY_OF_WEEK(b
120120
currentTimestampYear
121121
SELECT YEAR(CURRENT_TIMESTAMP()) AS result;
122122

123+
orderByCurrentTimestamp
124+
SELECT first_name FROM test_emp ORDER BY NOW(), first_name LIMIT 5;
125+
126+
groupByCurrentTimestamp
127+
SELECT MAX(salary) FROM test_emp GROUP BY NOW();
128+
123129
//
124130
// H2 uses the local timezone instead of the specified one
125131
//
@@ -131,3 +137,4 @@ SELECT HOUR(CURRENT_TIMESTAMP()) AS result;
131137

132138
currentTimestampMinute-Ignore
133139
SELECT MINUTE(CURRENT_TIMESTAMP()) AS result;
140+

x-pack/plugin/sql/src/main/antlr/SqlBase.g4

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ valueExpression
215215
primaryExpression
216216
: castExpression #cast
217217
| extractExpression #extract
218-
| builtinDateFunction #currentDateFunction
219218
| builtinDateTimeFunction #currentDateTimeFunction
220219
| constant #constantDefault
221220
| (qualifiedName DOT)? ASTERISK #star
@@ -236,12 +235,9 @@ castTemplate
236235
: CAST '(' expression AS dataType ')'
237236
;
238237

239-
builtinDateFunction
240-
: name=CURRENT_DATE ('(' ')')?
241-
;
242-
243238
builtinDateTimeFunction
244-
: name=CURRENT_TIMESTAMP ('(' precision=INTEGER_VALUE? ')')?
239+
: name=CURRENT_DATE ('(' ')')?
240+
| name=CURRENT_TIMESTAMP ('(' precision=INTEGER_VALUE? ')')?
245241
;
246242

247243
convertTemplate

0 commit comments

Comments
 (0)