Skip to content

Commit fa8ea3d

Browse files
Revert "Added support of timestamp/date/time using curly brackets (#297)"
This reverts commit a7f0182.
1 parent a7f0182 commit fa8ea3d

File tree

6 files changed

+4
-159
lines changed

6 files changed

+4
-159
lines changed

docs/user/dql/expressions.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A literal is a symbol that represents a value. The most common literal values in
2525
1. Numeric literals: specify numeric values such as integer and floating-point numbers.
2626
2. String literals: specify a string enclosed by single or double quotes.
2727
3. Boolean literals: ``true`` or ``false``.
28-
4. Date and Time literals: DATE 'YYYY-MM-DD' represent the date, TIME 'hh:mm:ss' represent the time, TIMESTAMP 'YYYY-MM-DD hh:mm:ss' represent the timestamp. You can also surround the literals with curly brackets, if you do, you can replace date with d, time with t, and timestamp with ts
28+
4. Date and Time literals: DATE 'YYYY-MM-DD' represent the date, TIME 'hh:mm:ss' represent the time, TIMESTAMP 'YYYY-MM-DD hh:mm:ss' represent the timestamp.
2929

3030
Examples
3131
--------
@@ -49,15 +49,6 @@ Here is an example for different type of literals::
4949
| Hello | Hello | It"s | It's | It's | "Its" | It's | It\'s | \I\t\s |
5050
+-----------+-----------+-----------+-----------+----------+-----------+-----------+-------------+------------+
5151

52-
53-
os> SELECT {DATE '2020-07-07'}, {D '2020-07-07'}, {TIME '01:01:01'}, {T '01:01:01'}, {TIMESTAMP '2020-07-07 01:01:01'}, {TS '2020-07-07 01:01:01'}
54-
fetched rows / total rows = 1/1
55-
+-----------------------+--------------------+---------------------+------------------+-------------------------------------+------------------------------+
56-
| {DATE '2020-07-07'} | {D '2020-07-07'} | {TIME '01:01:01'} | {T '01:01:01'} | {TIMESTAMP '2020-07-07 01:01:01'} | {TS '2020-07-07 01:01:01'} |
57-
|-----------------------+--------------------+---------------------+------------------+-------------------------------------+------------------------------|
58-
| 2020-07-07 | 2020-07-07 | 01:01:01 | 01:01:01 | 2020-07-07 01:01:01 | 2020-07-07 01:01:01 |
59-
+-----------------------+--------------------+---------------------+------------------+-------------------------------------+------------------------------+
60-
6152
Limitations
6253
-----------
6354

integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,103 +1288,4 @@ protected JSONObject executeQuery(String query) throws IOException {
12881288
Response response = client().performRequest(request);
12891289
return new JSONObject(getResponseBody(response));
12901290
}
1291-
1292-
@Test
1293-
public void testTimestampBracket() throws IOException {
1294-
JSONObject result = executeQuery("select {timestamp '2020-09-16 17:30:00'}");
1295-
verifySchema(result, schema("{timestamp '2020-09-16 17:30:00'}", null, "timestamp"));
1296-
verifyDataRows(result, rows("2020-09-16 17:30:00"));
1297-
1298-
result = executeQuery("select {ts '2020-09-16 17:30:00'}");
1299-
verifySchema(result, schema("{ts '2020-09-16 17:30:00'}", null, "timestamp"));
1300-
verifyDataRows(result, rows("2020-09-16 17:30:00"));
1301-
1302-
result = executeQuery("select {timestamp '2020-09-16 17:30:00.123'}");
1303-
verifySchema(result, schema("{timestamp '2020-09-16 17:30:00.123'}", null, "timestamp"));
1304-
verifyDataRows(result, rows("2020-09-16 17:30:00.123"));
1305-
1306-
result = executeQuery("select {ts '2020-09-16 17:30:00.123'}");
1307-
verifySchema(result, schema("{ts '2020-09-16 17:30:00.123'}", null, "timestamp"));
1308-
verifyDataRows(result, rows("2020-09-16 17:30:00.123"));
1309-
}
1310-
1311-
@Test
1312-
public void testTimeBracket() throws IOException {
1313-
JSONObject result = executeQuery("select {time '17:30:00'}");
1314-
verifySchema(result, schema("{time '17:30:00'}", null, "time"));
1315-
verifyDataRows(result, rows("17:30:00"));
1316-
1317-
result = executeQuery("select {t '17:30:00'}");
1318-
verifySchema(result, schema("{t '17:30:00'}", null, "time"));
1319-
verifyDataRows(result, rows("17:30:00"));
1320-
1321-
result = executeQuery("select {time '17:30:00'}");
1322-
verifySchema(result, schema("{time '17:30:00'}", null, "time"));
1323-
verifyDataRows(result, rows("17:30:00"));
1324-
1325-
result = executeQuery("select {t '17:30:00'}");
1326-
verifySchema(result, schema("{t '17:30:00'}", null, "time"));
1327-
verifyDataRows(result, rows("17:30:00"));
1328-
}
1329-
1330-
@Test
1331-
public void testDateBracket() throws IOException {
1332-
JSONObject result = executeQuery("select {date '2020-09-16'}");
1333-
verifySchema(result, schema("{date '2020-09-16'}", null, "date"));
1334-
verifyDataRows(result, rows("2020-09-16"));
1335-
1336-
result = executeQuery("select {d '2020-09-16'}");
1337-
verifySchema(result, schema("{d '2020-09-16'}", null, "date"));
1338-
verifyDataRows(result, rows("2020-09-16"));
1339-
}
1340-
1341-
private void compareBrackets(String query1, String query2, String datetime) throws IOException {
1342-
JSONObject result1 = executeQuery("select " + query1 + " '" + datetime + "'");
1343-
JSONObject result2 = executeQuery("select {" + query2 + " '" + datetime + "'}");
1344-
1345-
verifyDataRows(result1, rows(datetime));
1346-
verifyDataRows(result2, rows(datetime));
1347-
}
1348-
1349-
@Test
1350-
public void testBracketedEquivalent() throws IOException {
1351-
compareBrackets("timestamp", "timestamp", "2020-09-16 17:30:00");
1352-
compareBrackets("timestamp", "ts", "2020-09-16 17:30:00");
1353-
compareBrackets("timestamp", "timestamp", "2020-09-16 17:30:00.123");
1354-
compareBrackets("timestamp", "ts", "2020-09-16 17:30:00.123");
1355-
compareBrackets("date", "date", "2020-09-16");
1356-
compareBrackets("date", "d", "2020-09-16");
1357-
compareBrackets("time", "time", "17:30:00");
1358-
compareBrackets("time", "t", "17:30:00");
1359-
}
1360-
1361-
private void queryFails(String query) {
1362-
Request request = new Request("POST", QUERY_API_ENDPOINT);
1363-
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));
1364-
1365-
RequestOptions.Builder restOptionsBuilder = RequestOptions.DEFAULT.toBuilder();
1366-
restOptionsBuilder.addHeader("Content-Type", "application/json");
1367-
request.setOptions(restOptionsBuilder);
1368-
1369-
boolean fails = false;
1370-
1371-
try {
1372-
client().performRequest(request);
1373-
} catch(Exception ignored) {
1374-
fails = true;
1375-
}
1376-
1377-
assertTrue(fails);
1378-
}
1379-
1380-
@Test
1381-
public void testBracketFails() {
1382-
queryFails("select {time 'failure'}");
1383-
queryFails("select {t 'failure'}");
1384-
queryFails("select {date 'failure'}");
1385-
queryFails("select {d 'failure'}");
1386-
queryFails("select {timestamp 'failure'}");
1387-
queryFails("select {ts 'failure'}");
1388-
1389-
}
13901291
}

sql/src/main/antlr/OpenSearchSQLParser.g4

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ constant
185185
// Doesn't support the following types for now
186186
//| BIT_STRING
187187
//| NOT? nullLiteral=(NULL_LITERAL | NULL_SPEC_LITERAL)
188+
//| LEFT_BRACE dateType=(D | T | TS | DATE | TIME | TIMESTAMP) stringLiteral RIGHT_BRACE
188189
;
189190

190191
decimalLiteral
@@ -226,17 +227,14 @@ datetimeLiteral
226227

227228
dateLiteral
228229
: DATE date=stringLiteral
229-
| LEFT_BRACE (DATE | D) date=stringLiteral RIGHT_BRACE
230230
;
231231

232232
timeLiteral
233233
: TIME time=stringLiteral
234-
| LEFT_BRACE (TIME | T) time=stringLiteral RIGHT_BRACE
235234
;
236235

237236
timestampLiteral
238237
: TIMESTAMP timestamp=stringLiteral
239-
| LEFT_BRACE (TIMESTAMP | TS) timestamp=stringLiteral RIGHT_BRACE
240238
;
241239

242240
// Actually, these constants are shortcuts to the corresponding functions

sql/src/test/java/org/opensearch/sql/common/antlr/SyntaxParserTestBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.opensearch.sql.common.antlr;
22

33
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
import static org.junit.jupiter.api.Assertions.assertNull;
45
import static org.junit.jupiter.api.Assertions.assertThrows;
56

67
import lombok.AccessLevel;
78
import lombok.Getter;
89
import lombok.RequiredArgsConstructor;
10+
import org.opensearch.sql.sql.antlr.SQLSyntaxParser;
911

1012
/**
1113
* A base class for tests for SQL or PPL parser.

sql/src/test/java/org/opensearch/sql/sql/antlr/BracketedTimestampTest.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

sql/src/test/java/org/opensearch/sql/sql/antlr/SQLParserTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/*
2-
* Copyright OpenSearch Contributors
3-
* SPDX-License-Identifier: Apache-2.0
4-
*/
5-
6-
71
package org.opensearch.sql.sql.antlr;
82

93
import org.opensearch.sql.common.antlr.SyntaxParserTestBase;

0 commit comments

Comments
 (0)