11/*
2- * Copyright OpenSearch Contributors
3- * SPDX-License-Identifier: Apache-2.0
2+ *
3+ * * Copyright OpenSearch Contributors
4+ * * SPDX-License-Identifier: Apache-2.0
5+ *
46 */
57
6- package org .opensearch .sql .calcite .standalone ;
8+ package org .opensearch .sql .calcite .remote ;
79
810import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DATATYPE_NONNUMERIC ;
911import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_DATATYPE_NUMERIC ;
1012import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_STATE_COUNTRY ;
1113import static org .opensearch .sql .legacy .TestsConstants .TEST_INDEX_STATE_COUNTRY_WITH_NULL ;
14+ import static org .opensearch .sql .util .MatcherUtils .assertJsonEquals ;
1215import static org .opensearch .sql .util .MatcherUtils .rows ;
1316import static org .opensearch .sql .util .MatcherUtils .schema ;
1417import static org .opensearch .sql .util .MatcherUtils .verifyDataRows ;
1821import org .json .JSONObject ;
1922import org .junit .Test ;
2023import org .opensearch .sql .common .antlr .SyntaxCheckException ;
24+ import org .opensearch .sql .ppl .PPLIntegTestCase ;
2125
22- public class CalcitePPLCastFunctionIT extends CalcitePPLIntegTestCase {
26+ public class CalcitePPLCastFunctionIT extends PPLIntegTestCase {
2327 @ Override
24- public void init () throws IOException {
28+ public void init () throws Exception {
2529 super .init ();
30+ enableCalcite ();
31+ disallowCalciteFallback ();
32+
2633 loadIndex (Index .STATE_COUNTRY );
2734 loadIndex (Index .STATE_COUNTRY_WITH_NULL );
2835 loadIndex (Index .DATA_TYPE_NUMERIC );
2936 loadIndex (Index .DATA_TYPE_NONNUMERIC );
3037 }
3138
3239 @ Test
33- public void testCast () {
40+ public void testCast () throws IOException {
3441 JSONObject actual =
3542 executeQuery (
3643 String .format (
@@ -42,7 +49,7 @@ public void testCast() {
4249 }
4350
4451 @ Test
45- public void testCastOverriding () {
52+ public void testCastOverriding () throws IOException {
4653 JSONObject actual =
4754 executeQuery (
4855 String .format (
@@ -56,7 +63,7 @@ public void testCastOverriding() {
5663
5764 @ Test
5865 public void testCastToUnknownType () {
59- assertThrows (
66+ assertThrowsWithReplace (
6067 SyntaxCheckException .class ,
6168 () ->
6269 executeQuery (
@@ -66,7 +73,7 @@ public void testCastToUnknownType() {
6673 }
6774
6875 @ Test
69- public void testChainedCast () {
76+ public void testChainedCast () throws IOException {
7077 JSONObject actual =
7178 executeQuery (
7279 String .format (
@@ -80,14 +87,14 @@ public void testChainedCast() {
8087 }
8188
8289 @ Test
83- public void testCastNullValues () {
84- String actual =
85- execute (
90+ public void testCastNullValues () throws IOException {
91+ JSONObject actual =
92+ executeQuery (
8693 String .format (
8794 "source=%s | eval a = cast(state as string) | fields a" ,
8895 TEST_INDEX_STATE_COUNTRY_WITH_NULL ));
8996
90- assertEquals (
97+ assertJsonEquals (
9198 "{\n "
9299 + " \" schema\" : [\n "
93100 + " {\n "
@@ -118,17 +125,17 @@ public void testCastNullValues() {
118125 + " \" total\" : 6,\n "
119126 + " \" size\" : 6\n "
120127 + "}" ,
121- actual );
128+ actual . toString () );
122129 }
123130
124131 @ Test
125- public void testCastToUnsupportedType () {
126- String actual =
127- execute (
132+ public void testCastToUnsupportedType () throws IOException {
133+ JSONObject actual =
134+ executeQuery (
128135 String .format (
129136 "source=%s | eval a = cast(name as boolean) | fields a" , TEST_INDEX_STATE_COUNTRY ));
130137
131- assertEquals (
138+ assertJsonEquals (
132139 "{\n "
133140 + " \" schema\" : [\n "
134141 + " {\n "
@@ -153,11 +160,11 @@ public void testCastToUnsupportedType() {
153160 + " \" total\" : 4,\n "
154161 + " \" size\" : 4\n "
155162 + "}" ,
156- actual );
163+ actual . toString () );
157164 }
158165
159166 @ Test
160- public void testCastLiteralToBoolean () {
167+ public void testCastLiteralToBoolean () throws IOException {
161168 // In OpenSearch V2:
162169 // POST /_plugins/_ppl
163170 // {
@@ -210,12 +217,12 @@ public void testCastLiteralToBoolean() {
210217 TEST_INDEX_DATATYPE_NUMERIC ));
211218 verifyDataRows (actual , rows (true ));
212219
213- String actualString =
214- execute (
220+ actual =
221+ executeQuery (
215222 String .format (
216223 "source=%s | eval a = cast('2' as boolean) | fields a | head 1" ,
217224 TEST_INDEX_DATATYPE_NUMERIC ));
218- assertEquals (
225+ assertJsonEquals (
219226 ""
220227 + "{\n "
221228 + " \" schema\" : [\n "
@@ -232,7 +239,7 @@ public void testCastLiteralToBoolean() {
232239 + " \" total\" : 1,\n "
233240 + " \" size\" : 1\n "
234241 + "}" ,
235- actualString );
242+ actual . toString () );
236243
237244 actual =
238245 executeQuery (
@@ -241,12 +248,12 @@ public void testCastLiteralToBoolean() {
241248 TEST_INDEX_DATATYPE_NUMERIC ));
242249 verifyDataRows (actual , rows (false ));
243250
244- actualString =
245- execute (
251+ actual =
252+ executeQuery (
246253 String .format (
247254 "source=%s | eval a = cast('aa' as boolean) | fields a | head 1" ,
248255 TEST_INDEX_DATATYPE_NUMERIC ));
249- assertEquals (
256+ assertJsonEquals (
250257 ""
251258 + "{\n "
252259 + " \" schema\" : [\n "
@@ -263,11 +270,11 @@ public void testCastLiteralToBoolean() {
263270 + " \" total\" : 1,\n "
264271 + " \" size\" : 1\n "
265272 + "}" ,
266- actualString );
273+ actual . toString () );
267274 }
268275
269276 @ Test
270- public void testCastINT () {
277+ public void testCastINT () throws IOException {
271278 JSONObject actual =
272279 executeQuery (
273280 String .format (
@@ -305,7 +312,7 @@ public void testCastINT() {
305312 }
306313
307314 @ Test
308- public void testCastLONG () {
315+ public void testCastLONG () throws IOException {
309316 JSONObject actual =
310317 executeQuery (
311318 String .format (
@@ -336,7 +343,7 @@ public void testCastLONG() {
336343 }
337344
338345 @ Test
339- public void testCastFLOAT () {
346+ public void testCastFLOAT () throws IOException {
340347 JSONObject actual =
341348 executeQuery (
342349 String .format (
@@ -367,7 +374,7 @@ public void testCastFLOAT() {
367374 }
368375
369376 @ Test
370- public void testCastDOUBLE () {
377+ public void testCastDOUBLE () throws IOException {
371378 JSONObject actual =
372379 executeQuery (
373380 String .format (
@@ -398,7 +405,7 @@ public void testCastDOUBLE() {
398405 }
399406
400407 @ Test
401- public void testCastBOOLEAN () {
408+ public void testCastBOOLEAN () throws IOException {
402409 JSONObject actual ;
403410 actual =
404411 executeQuery (
@@ -444,7 +451,7 @@ public void testCastBOOLEAN() {
444451 }
445452
446453 @ Test
447- public void testCastNumericSTRING () {
454+ public void testCastNumericSTRING () throws IOException {
448455 JSONObject actual =
449456 executeQuery (
450457 String .format (
0 commit comments