6
6
7
7
package org .opensearch .sql .sql ;
8
8
9
+ import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DATATYPE_NONNUMERIC ;
9
10
import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DATE_FORMATS ;
10
11
import static org .opensearch .sql .legacy .plugin .RestSqlAction .QUERY_API_ENDPOINT ;
11
12
import static org .opensearch .sql .util .MatcherUtils .rows ;
@@ -30,6 +31,7 @@ public class DateTimeFormatsIT extends SQLIntegTestCase {
30
31
public void init () throws Exception {
31
32
super .init ();
32
33
loadIndex (Index .DATE_FORMATS );
34
+ loadIndex (Index .DATA_TYPE_NONNUMERIC );
33
35
}
34
36
35
37
@ Test
@@ -120,6 +122,94 @@ public void testNumericFormats() {
120
122
rows ("1970-01-02 03:55:00" , "1970-01-01 00:01:40.5" ));
121
123
}
122
124
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
+
123
213
protected JSONObject executeQuery (String query ) throws IOException {
124
214
Request request = new Request ("POST" , QUERY_API_ENDPOINT );
125
215
request .setJsonEntity (String .format (Locale .ROOT , "{\n " + " \" query\" : \" %s\" \n " + "}" , query ));
0 commit comments