Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function name as identifier in antlr #1015

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions docs/user/dql/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,17 @@ CURRENT_DATE
Description
>>>>>>>>>>>

`CURRENT_DATE` and `CURRENT_DATE()` are synonyms for `CURDATE() <#curdate>`_.
`CURRENT_DATE()` are synonyms for `CURDATE() <#curdate>`_.

Example::

> SELECT CURRENT_DATE(), CURRENT_DATE;
> SELECT CURRENT_DATE();
fetched rows / total rows = 1/1
+------------------+----------------+
| CURRENT_DATE() | CURRENT_DATE |
|------------------+----------------|
| 2022-08-02 | 2022-08-02 |
+------------------+----------------+
+------------------+
| CURRENT_DATE() |
|------------------+
| 2022-08-02 |
+------------------+


CURRENT_TIME
Expand All @@ -1006,17 +1006,17 @@ CURRENT_TIME
Description
>>>>>>>>>>>

`CURRENT_TIME` and `CURRENT_TIME()` are synonyms for `CURTIME() <#curtime>`_.
`CURRENT_TIME()` are synonyms for `CURTIME() <#curtime>`_.

Example::

> SELECT CURRENT_TIME(), CURRENT_TIME;
> SELECT CURRENT_TIME();
fetched rows / total rows = 1/1
+-----------------+----------------+
| CURRENT_TIME() | CURRENT_TIME |
|-----------------+----------------|
| 15:39:05 | 15:39:05 |
+-----------------+----------------+
+-----------------+
| CURRENT_TIME() |
|-----------------+
| 15:39:05 |
+-----------------+


CURRENT_TIMESTAMP
Expand All @@ -1025,17 +1025,17 @@ CURRENT_TIMESTAMP
Description
>>>>>>>>>>>

`CURRENT_TIMESTAMP` and `CURRENT_TIMESTAMP()` are synonyms for `NOW() <#now>`_.
`CURRENT_TIMESTAMP()` are synonyms for `NOW() <#now>`_.

Example::

> SELECT CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP;
> SELECT CURRENT_TIMESTAMP();
fetched rows / total rows = 1/1
+-----------------------+---------------------+
| CURRENT_TIMESTAMP() | CURRENT_TIMESTAMP |
|-----------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+-----------------------+---------------------+
+-----------------------+
| CURRENT_TIMESTAMP() |
|-----------------------+
| 2022-08-02 15:54:19 |
+-----------------------+


CURTIME
Expand Down Expand Up @@ -1548,17 +1548,17 @@ LOCALTIMESTAMP
Description
>>>>>>>>>>>

`LOCALTIMESTAMP` and `LOCALTIMESTAMP()` are synonyms for `NOW() <#now>`_.
`LOCALTIMESTAMP()` are synonyms for `NOW() <#now>`_.

Example::

> SELECT LOCALTIMESTAMP(), LOCALTIMESTAMP;
> SELECT LOCALTIMESTAMP();
fetched rows / total rows = 1/1
+---------------------+---------------------+
| LOCALTIMESTAMP() | LOCALTIMESTAMP |
|---------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+---------------------+---------------------+
+---------------------+
| LOCALTIMESTAMP() |
|---------------------+
| 2022-08-02 15:54:19 |
+---------------------+


LOCALTIME
Expand All @@ -1567,17 +1567,17 @@ LOCALTIME
Description
>>>>>>>>>>>

`LOCALTIME` and `LOCALTIME()` are synonyms for `NOW() <#now>`_.
`LOCALTIME()` are synonyms for `NOW() <#now>`_.

Example::

> SELECT LOCALTIME(), LOCALTIME;
fetched rows / total rows = 1/1
+---------------------+---------------------+
| LOCALTIME() | LOCALTIME |
|---------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+---------------------+---------------------+
+---------------------+
| LOCALTIME() |
|---------------------+
| 2022-08-02 15:54:19 |
+---------------------+


MAKEDATE
Expand Down
70 changes: 35 additions & 35 deletions docs/user/ppl/functions/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ CURRENT_DATE
Description
>>>>>>>>>>>

`CURRENT_DATE` and `CURRENT_DATE()` are synonyms for `CURDATE() <#curdate>`_.
`CURRENT_DATE()` are synonyms for `CURDATE() <#curdate>`_.

Example::

> source=people | eval `CURRENT_DATE()` = CURRENT_DATE(), `CURRENT_DATE` = CURRENT_DATE | fields `CURRENT_DATE()`, `CURRENT_DATE`
> source=people | eval `CURRENT_DATE()` = CURRENT_DATE() | fields `CURRENT_DATE()`
fetched rows / total rows = 1/1
+------------------+----------------+
| CURRENT_DATE() | CURRENT_DATE |
|------------------+----------------|
| 2022-08-02 | 2022-08-02 |
+------------------+----------------+
+------------------+
| CURRENT_DATE() |
|------------------+
| 2022-08-02 |
+------------------+


CURRENT_TIME
Expand All @@ -221,17 +221,17 @@ CURRENT_TIME
Description
>>>>>>>>>>>

`CURRENT_TIME` and `CURRENT_TIME()` are synonyms for `CURTIME() <#curtime>`_.
`CURRENT_TIME()` are synonyms for `CURTIME() <#curtime>`_.

Example::

> source=people | eval `CURRENT_TIME()` = CURRENT_TIME(), `CURRENT_TIME` = CURRENT_TIME | fields `CURRENT_TIME()`, `CURRENT_TIME`
> source=people | eval `CURRENT_TIME()` = CURRENT_TIME() | fields `CURRENT_TIME()`
fetched rows / total rows = 1/1
+------------------+----------------+
| CURRENT_TIME() | CURRENT_TIME |
|------------------+----------------|
| 15:39:05 | 15:39:05 |
+------------------+----------------+
+------------------+
| CURRENT_TIME() |
|------------------+
| 15:39:05 |
+------------------+


CURRENT_TIMESTAMP
Expand All @@ -240,17 +240,17 @@ CURRENT_TIMESTAMP
Description
>>>>>>>>>>>

`CURRENT_TIMESTAMP` and `CURRENT_TIMESTAMP()` are synonyms for `NOW() <#now>`_.
`CURRENT_TIMESTAMP()` are synonyms for `NOW() <#now>`_.

Example::

> source=people | eval `CURRENT_TIMESTAMP()` = CURRENT_TIMESTAMP(), `CURRENT_TIMESTAMP` = CURRENT_TIMESTAMP | fields `CURRENT_TIMESTAMP()`, `CURRENT_TIMESTAMP`
> source=people | eval `CURRENT_TIMESTAMP()` = CURRENT_TIMESTAMP() | fields `CURRENT_TIMESTAMP()`
fetched rows / total rows = 1/1
+-----------------------+---------------------+
| CURRENT_TIMESTAMP() | CURRENT_TIMESTAMP |
|-----------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+-----------------------+---------------------+
+-----------------------+
| CURRENT_TIMESTAMP() |
|-----------------------+
| 2022-08-02 15:54:19 |
+-----------------------+


CURTIME
Expand Down Expand Up @@ -720,17 +720,17 @@ LOCALTIMESTAMP
Description
>>>>>>>>>>>

`LOCALTIMESTAMP` and `LOCALTIMESTAMP()` are synonyms for `NOW() <#now>`_.
`LOCALTIMESTAMP()` are synonyms for `NOW() <#now>`_.

Example::

> source=people | eval `LOCALTIMESTAMP()` = LOCALTIMESTAMP(), `LOCALTIMESTAMP` = LOCALTIMESTAMP | fields `LOCALTIMESTAMP()`, `LOCALTIMESTAMP`
> source=people | eval `LOCALTIMESTAMP()` = LOCALTIMESTAMP() | fields `LOCALTIMESTAMP()`
fetched rows / total rows = 1/1
+---------------------+---------------------+
| LOCALTIMESTAMP() | LOCALTIMESTAMP |
|---------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+---------------------+---------------------+
+---------------------+
| LOCALTIMESTAMP() |
|---------------------+
| 2022-08-02 15:54:19 |
+---------------------+


LOCALTIME
Expand All @@ -739,17 +739,17 @@ LOCALTIME
Description
>>>>>>>>>>>

`LOCALTIME` and `LOCALTIME()` are synonyms for `NOW() <#now>`_.
`LOCALTIME()` are synonyms for `NOW() <#now>`_.

Example::

> source=people | eval `LOCALTIME()` = LOCALTIME(), `LOCALTIME` = LOCALTIME | fields `LOCALTIME()`, `LOCALTIME`
> source=people | eval `LOCALTIME()` = LOCALTIME() | fields `LOCALTIME()`
fetched rows / total rows = 1/1
+---------------------+---------------------+
| LOCALTIME() | LOCALTIME |
|---------------------+---------------------|
| 2022-08-02 15:54:19 | 2022-08-02 15:54:19 |
+---------------------+---------------------+
+---------------------+
| LOCALTIME() |
|---------------------+
| 2022-08-02 15:54:19 |
+---------------------+


MAKEDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_timestamp")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -695,7 +695,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "localtimestamp")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -704,7 +704,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "localtime")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -731,7 +731,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_time")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", false)
.put("referenceGetter", (Supplier<Temporal>) LocalTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalTime::parse)
Expand All @@ -749,7 +749,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_date")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", false)
.put("referenceGetter", (Supplier<Temporal>) LocalDate::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDate::parse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_timestamp")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -514,7 +514,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "localtimestamp")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -523,7 +523,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "localtime")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", true)
.put("referenceGetter", (Supplier<Temporal>) LocalDateTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDateTime::parse)
Expand All @@ -550,7 +550,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_time")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", false)
.put("referenceGetter", (Supplier<Temporal>) LocalTime::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalTime::parse)
Expand All @@ -568,7 +568,7 @@ private List<ImmutableMap<Object, Object>> nowLikeFunctionsData() {
ImmutableMap.builder()
.put("name", "current_date")
.put("hasFsp", false)
.put("hasShortcut", true)
.put("hasShortcut", false)
.put("constValue", false)
.put("referenceGetter", (Supplier<Temporal>) LocalDate::now)
.put("parser", (BiFunction<CharSequence, DateTimeFormatter, Temporal>) LocalDate::parse)
Expand Down
12 changes: 5 additions & 7 deletions ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ dateAndTimeFunctionBase

// Functions which value could be cached in scope of a single query
constantFunctionName
: datetimeConstantLiteral
: CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP | LOCALTIME | LOCALTIMESTAMP | UTC_TIMESTAMP | UTC_DATE | UTC_TIME
| CURDATE | CURTIME | NOW
;

Expand Down Expand Up @@ -507,7 +507,6 @@ datetimeLiteral
: dateLiteral
| timeLiteral
| timestampLiteral
| datetimeConstantLiteral
;

dateLiteral
Expand All @@ -522,11 +521,6 @@ timestampLiteral
: TIMESTAMP timestamp=stringLiteral
;

// Actually, these constants are shortcuts to the corresponding functions
datetimeConstantLiteral
: CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP | LOCALTIME | LOCALTIMESTAMP | UTC_TIMESTAMP | UTC_DATE | UTC_TIME
;

intervalUnit
: MICROSECOND | SECOND | MINUTE | HOUR | DAY | WEEK | MONTH | QUARTER | YEAR | SECOND_MICROSECOND
| MINUTE_MICROSECOND | MINUTE_SECOND | HOUR_MICROSECOND | HOUR_SECOND | HOUR_MINUTE | DAY_MICROSECOND
Expand Down Expand Up @@ -571,4 +565,8 @@ keywordsCanBeId
| TIMESTAMP | DATE | TIME
| FIRST | LAST
| timespanUnit | SPAN
| constantFunctionName
| dateAndTimeFunctionBase
| textFunctionBase
| mathematicalFunctionBase
;
Loading