Skip to content

Commit 9469b68

Browse files
Add support for date_nanos and tests. (#337) (opensearch-project#1976)
* Add support for `date_nanos` and tests. (#337) * Add support for `date_nanos` and tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Add more IT. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> * Typo fix in IT. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR feedback. Signed-off-by: Yury-Fridlyand <[email protected]> * Spotless Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]> (cherry picked from commit 752da21) Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 8313c34 commit 9469b68

File tree

10 files changed

+152
-25
lines changed

10 files changed

+152
-25
lines changed

integ-test/src/test/java/org/opensearch/sql/ppl/DataTypeIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void test_nonnumeric_data_types() throws IOException {
5050
schema("text_value", "string"),
5151
schema("binary_value", "binary"),
5252
schema("date_value", "timestamp"),
53+
schema("date_nanos_value", "timestamp"),
5354
schema("ip_value", "ip"),
5455
schema("object_value", "struct"),
5556
schema("nested_value", "array"),

integ-test/src/test/java/org/opensearch/sql/ppl/SystemFunctionIT.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,31 @@ public void typeof_opensearch_types() throws IOException {
5858
verifyDataRows(response,
5959
rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
6060

61-
response = executeQuery(String.format("source=%s | eval "
62-
+ "`text` = typeof(text_value), `date` = typeof(date_value),"
63-
+ "`boolean` = typeof(boolean_value), `object` = typeof(object_value),"
64-
+ "`keyword` = typeof(keyword_value), `ip` = typeof(ip_value),"
65-
+ "`binary` = typeof(binary_value), `geo_point` = typeof(geo_point_value)"
66-
// TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
67-
//+ ", `nested` = typeof(nested_value)"
68-
+ " | fields `text`, `date`, `boolean`, `object`, `keyword`, `ip`, `binary`, `geo_point`",
69-
TEST_INDEX_DATATYPE_NONNUMERIC));
70-
verifyDataRows(response,
71-
rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD",
72-
"IP", "BINARY", "GEO_POINT"));
61+
response =
62+
executeQuery(
63+
String.format(
64+
"source=%s | eval `text` = typeof(text_value), `date` = typeof(date_value),"
65+
+ " `date_nanos` = typeof(date_nanos_value),`boolean` = typeof(boolean_value),"
66+
+ " `object` = typeof(object_value),`keyword` = typeof(keyword_value), `ip` ="
67+
+ " typeof(ip_value),`binary` = typeof(binary_value), `geo_point` ="
68+
+ " typeof(geo_point_value)"
69+
// TODO activate this test once `ARRAY` type supported, see
70+
// ExpressionAnalyzer::isTypeNotSupported
71+
// + ", `nested` = typeof(nested_value)"
72+
+ " | fields `text`, `date`, `date_nanos`, `boolean`, `object`, `keyword`,"
73+
+ " `ip`, `binary`, `geo_point`",
74+
TEST_INDEX_DATATYPE_NONNUMERIC));
75+
verifyDataRows(
76+
response,
77+
rows(
78+
"TEXT",
79+
"TIMESTAMP",
80+
"TIMESTAMP",
81+
"BOOLEAN",
82+
"OBJECT",
83+
"KEYWORD",
84+
"IP",
85+
"BINARY",
86+
"GEO_POINT"));
7387
}
7488
}

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package org.opensearch.sql.sql;
88

9+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATATYPE_NONNUMERIC;
910
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE_FORMATS;
1011
import static org.opensearch.sql.legacy.plugin.RestSqlAction.QUERY_API_ENDPOINT;
1112
import static org.opensearch.sql.util.MatcherUtils.rows;
@@ -30,6 +31,7 @@ public class DateTimeFormatsIT extends SQLIntegTestCase {
3031
public void init() throws Exception {
3132
super.init();
3233
loadIndex(Index.DATE_FORMATS);
34+
loadIndex(Index.DATA_TYPE_NONNUMERIC);
3335
}
3436

3537
@Test
@@ -120,6 +122,94 @@ public void testNumericFormats() {
120122
rows("1970-01-02 03:55:00", "1970-01-01 00:01:40.5"));
121123
}
122124

125+
@Test
126+
@SneakyThrows
127+
public void testDateNanosWithFormats() {
128+
String query =
129+
String.format("SELECT hour_minute_second_OR_t_time" + " FROM %s", TEST_INDEX_DATE_FORMATS);
130+
JSONObject result = executeQuery(query);
131+
verifySchema(result, schema("hour_minute_second_OR_t_time", null, "time"));
132+
verifyDataRows(result, rows("09:07:42"), rows("07:07:42.123456789"));
133+
}
134+
135+
@Test
136+
@SneakyThrows
137+
public void testDateNanosWithFunctions() {
138+
// in memory funcs
139+
String query =
140+
String.format(
141+
"SELECT"
142+
+ " hour_minute_second_OR_t_time > TIME '08:07:00',"
143+
+ " hour_minute_second_OR_t_time < TIME '08:07:00',"
144+
+ " hour_minute_second_OR_t_time = t_time_no_millis,"
145+
+ " hour_minute_second_OR_t_time <> strict_t_time,"
146+
+ " hour_minute_second_OR_t_time >= t_time"
147+
+ " FROM %s",
148+
TEST_INDEX_DATE_FORMATS);
149+
JSONObject result = executeQuery(query);
150+
verifySchema(
151+
result,
152+
schema("hour_minute_second_OR_t_time > TIME '08:07:00'", null, "boolean"),
153+
schema("hour_minute_second_OR_t_time < TIME '08:07:00'", null, "boolean"),
154+
schema("hour_minute_second_OR_t_time = t_time_no_millis", null, "boolean"),
155+
schema("hour_minute_second_OR_t_time <> strict_t_time", null, "boolean"),
156+
schema("hour_minute_second_OR_t_time >= t_time", null, "boolean"));
157+
verifyDataRows(
158+
result, rows(true, false, true, false, true), rows(false, true, false, true, false));
159+
// push down
160+
query =
161+
String.format(
162+
"SELECT hour_minute_second_OR_t_time"
163+
+ " FROM %s WHERE hour_minute_second_OR_t_time > TIME '08:07:00'",
164+
TEST_INDEX_DATE_FORMATS);
165+
result = executeQuery(query);
166+
verifySchema(result, schema("hour_minute_second_OR_t_time", null, "time"));
167+
verifyDataRows(result, rows("09:07:42"));
168+
query =
169+
String.format(
170+
"SELECT hour_minute_second_OR_t_time"
171+
+ " FROM %s WHERE hour_minute_second_OR_t_time < TIME '08:07:00'",
172+
TEST_INDEX_DATE_FORMATS);
173+
result = executeQuery(query);
174+
verifySchema(result, schema("hour_minute_second_OR_t_time", null, "time"));
175+
verifyDataRows(result, rows("07:07:42.123456789"));
176+
}
177+
178+
@Test
179+
@SneakyThrows
180+
public void testDateNanosOrderBy() {
181+
String query =
182+
String.format(
183+
"SELECT hour_minute_second_OR_t_time"
184+
+ " FROM %s ORDER BY hour_minute_second_OR_t_time ASC",
185+
TEST_INDEX_DATE_FORMATS);
186+
JSONObject result = executeQuery(query);
187+
verifySchema(result, schema("hour_minute_second_OR_t_time", null, "time"));
188+
verifyDataRows(result, rows("07:07:42.123456789"), rows("09:07:42"));
189+
}
190+
191+
@Test
192+
@SneakyThrows
193+
public void testDateNanosGroupBy() {
194+
String query =
195+
String.format(
196+
"SELECT count(*)" + " FROM %s GROUP BY hour_minute_second_OR_t_time",
197+
TEST_INDEX_DATE_FORMATS);
198+
JSONObject result = executeQuery(query);
199+
verifySchema(result, schema("count(*)", null, "integer"));
200+
verifyDataRows(result, rows(1), rows(1));
201+
}
202+
203+
@Test
204+
@SneakyThrows
205+
public void testDateNanosWithNanos() {
206+
String query =
207+
String.format("SELECT date_nanos_value" + " FROM %s", TEST_INDEX_DATATYPE_NONNUMERIC);
208+
JSONObject result = executeQuery(query);
209+
verifySchema(result, schema("date_nanos_value", null, "timestamp"));
210+
verifyDataRows(result, rows("2019-03-24 01:34:46.123456789"));
211+
}
212+
123213
protected JSONObject executeQuery(String query) throws IOException {
124214
Request request = new Request("POST", QUERY_API_ENDPOINT);
125215
request.setJsonEntity(String.format(Locale.ROOT, "{\n" + " \"query\": \"%s\"\n" + "}", query));

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,29 @@ public void typeof_opensearch_types() {
4747
verifyDataRows(response,
4848
rows("DOUBLE", "LONG", "INTEGER", "BYTE", "SHORT", "FLOAT", "FLOAT", "DOUBLE"));
4949

50-
response = executeJdbcRequest(String.format("SELECT typeof(text_value),"
51-
+ "typeof(date_value), typeof(boolean_value), typeof(object_value), typeof(keyword_value),"
52-
+ "typeof(ip_value), typeof(binary_value), typeof(geo_point_value)"
53-
// TODO activate this test once `ARRAY` type supported, see ExpressionAnalyzer::isTypeNotSupported
54-
//+ ", typeof(nested_value)"
55-
+ " from %s;", TEST_INDEX_DATATYPE_NONNUMERIC));
56-
verifyDataRows(response,
57-
rows("TEXT", "TIMESTAMP", "BOOLEAN", "OBJECT", "KEYWORD",
58-
"IP", "BINARY", "GEO_POINT"));
50+
response =
51+
executeJdbcRequest(
52+
String.format(
53+
"SELECT typeof(text_value),typeof(date_value), typeof(date_nanos_value),"
54+
+ " typeof(boolean_value), typeof(object_value),"
55+
+ " typeof(keyword_value),typeof(ip_value), typeof(binary_value),"
56+
+ " typeof(geo_point_value)"
57+
// TODO activate this test once `ARRAY` type supported, see
58+
// ExpressionAnalyzer::isTypeNotSupported
59+
// + ", typeof(nested_value)"
60+
+ " from %s;",
61+
TEST_INDEX_DATATYPE_NONNUMERIC));
62+
verifyDataRows(
63+
response,
64+
rows(
65+
"TEXT",
66+
"TIMESTAMP",
67+
"TIMESTAMP",
68+
"BOOLEAN",
69+
"OBJECT",
70+
"KEYWORD",
71+
"IP",
72+
"BINARY",
73+
"GEO_POINT"));
5974
}
6075
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{"index":{"_id":"1"}}
2-
{"boolean_value": true, "keyword_value": "keyword", "text_value": "text", "binary_value": "U29tZSBiaW5hcnkgYmxvYg==", "date_value": "2020-10-13 13:00:00", "ip_value": "127.0.0.1", "object_value": {"first": "Dale", "last": "Dale"}, "nested_value": [{"first" : "John", "last" : "Smith"}, {"first" : "Alice", "last" : "White"}], "geo_point_value": { "lat": 40.71, "lon": 74.00 }}
2+
{"boolean_value": true, "keyword_value": "keyword", "text_value": "text", "binary_value": "U29tZSBiaW5hcnkgYmxvYg==", "date_value": "2020-10-13 13:00:00", "date_nanos_value": "2019-03-23T21:34:46.123456789-04:00", "ip_value": "127.0.0.1", "object_value": {"first": "Dale", "last": "Dale"}, "nested_value": [{"first" : "John", "last" : "Smith"}, {"first" : "Alice", "last" : "White"}], "geo_point_value": { "lat": 40.71, "lon": 74.00 }}

0 commit comments

Comments
 (0)