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_WEBLOGS ;
911import static org .opensearch .sql .util .MatcherUtils .rows ;
1618import org .junit .jupiter .api .Test ;
1719import org .opensearch .client .Request ;
1820import org .opensearch .sql .legacy .TestsConstants ;
21+ import org .opensearch .sql .ppl .PPLIntegTestCase ;
1922
20- public class CalcitePPLCaseFunctionIT extends CalcitePPLIntegTestCase {
23+ public class CalcitePPLCaseFunctionIT extends PPLIntegTestCase {
2124 @ Override
22- public void init () throws IOException {
25+ public void init () throws Exception {
2326 super .init ();
27+ enableCalcite ();
28+ disallowCalciteFallback ();
29+
2430 loadIndex (Index .WEBLOG );
2531 appendDataForBadResponse ();
2632 }
@@ -53,21 +59,18 @@ private void appendDataForBadResponse() throws IOException {
5359 }
5460
5561 @ Test
56- public void testCaseWhenWithCast () {
62+ public void testCaseWhenWithCast () throws IOException {
5763 JSONObject actual =
5864 executeQuery (
5965 String .format (
60- """
61- source=%s
62- | eval status =
63- case(
64- cast(response as int) >= 200 AND cast(response as int) < 300, "Success",
65- cast(response as int) >= 300 AND cast(response as int) < 400, "Redirection",
66- cast(response as int) >= 400 AND cast(response as int) < 500, "Client Error",
67- cast(response as int) >= 500 AND cast(response as int) < 600, "Server Error"
68- else concat("Incorrect HTTP status code for", url))
69- | where status != "Success" | fields host, method, message, bytes, response, url, status
70- """ ,
66+ "source=%s| eval status = case( cast(response as int) >= 200 AND"
67+ + " cast(response as int) < 300, 'Success', cast(response as int) >= 300"
68+ + " AND cast(response as int) < 400, 'Redirection', cast(response as"
69+ + " int) >= 400 AND cast(response as int) < 500, 'Client Error', "
70+ + " cast(response as int) >= 500 AND cast(response as int) < 600, 'Server"
71+ + " Error' else concat('Incorrect HTTP status code for', url))| where"
72+ + " status != 'Success' | fields host, method, message, bytes, response, url,"
73+ + " status" ,
7174 TEST_INDEX_WEBLOGS ));
7275 verifySchema (
7376 actual ,
@@ -102,20 +105,17 @@ else concat("Incorrect HTTP status code for", url))
102105 }
103106
104107 @ Test
105- public void testCaseWhenNoElse () {
108+ public void testCaseWhenNoElse () throws IOException {
106109 JSONObject actual =
107110 executeQuery (
108111 String .format (
109- """
110- source=%s
111- | eval status =
112- case(
113- cast(response as int) >= 200 AND cast(response as int) < 300, "Success",
114- cast(response as int) >= 300 AND cast(response as int) < 400, "Redirection",
115- cast(response as int) >= 400 AND cast(response as int) < 500, "Client Error",
116- cast(response as int) >= 500 AND cast(response as int) < 600, "Server Error")
117- | where isnull(status) OR status != "Success" | fields host, method, message, bytes, response, url, status
118- """ ,
112+ "source=%s| eval status = case( cast(response as int) >= 200 AND"
113+ + " cast(response as int) < 300, 'Success', cast(response as int) >= 300"
114+ + " AND cast(response as int) < 400, 'Redirection', cast(response as"
115+ + " int) >= 400 AND cast(response as int) < 500, 'Client Error', "
116+ + " cast(response as int) >= 500 AND cast(response as int) < 600, 'Server"
117+ + " Error')| where isnull(status) OR status != 'Success' | fields host, method,"
118+ + " message, bytes, response, url, status" ,
119119 TEST_INDEX_WEBLOGS ));
120120 verifySchema (
121121 actual ,
@@ -143,21 +143,16 @@ public void testCaseWhenNoElse() {
143143 }
144144
145145 @ Test
146- public void testCaseWhenWithIn () {
146+ public void testCaseWhenWithIn () throws IOException {
147147 JSONObject actual =
148148 executeQuery (
149149 String .format (
150- """
151- source=%s
152- | eval status =
153- case(
154- response in ('200'), "Success",
155- response in ('300', '301'), "Redirection",
156- response in ('400', '403'), "Client Error",
157- response in ('500', '505'), "Server Error"
158- else concat("Incorrect HTTP status code for", url))
159- | where status != "Success" | fields host, method, message, bytes, response, url, status
160- """ ,
150+ "source=%s | eval status = case( response in ('200'), 'Success', "
151+ + " response in ('300', '301'), 'Redirection', response in"
152+ + " ('400', '403'), 'Client Error', response in ('500', '505'),"
153+ + " 'Server Error' else concat('Incorrect HTTP status code for',"
154+ + " url)) | where status != 'Success' | fields host, method, message, bytes,"
155+ + " response, url, status" ,
161156 TEST_INDEX_WEBLOGS ));
162157 verifySchema (
163158 actual ,
@@ -192,21 +187,19 @@ else concat("Incorrect HTTP status code for", url))
192187 }
193188
194189 @ Test
195- public void testCaseWhenInFilter () {
190+ public void testCaseWhenInFilter () throws IOException {
196191 JSONObject actual =
197192 executeQuery (
198193 String .format (
199- """
200- source=%s
201- | where not true =
202- case(
203- response in ('200'), true,
204- response in ('300', '301'), false,
205- response in ('400', '403'), false,
206- response in ('500', '505'), false
207- else false)
208- | fields host, method, message, bytes, response, url
209- """ ,
194+ "source=%s"
195+ + "| where not true ="
196+ + " case("
197+ + " response in ('200'), true,"
198+ + " response in ('300', '301'), false,"
199+ + " response in ('400', '403'), false,"
200+ + " response in ('500', '505'), false"
201+ + " else false)"
202+ + "| fields host, method, message, bytes, response, url" ,
210203 TEST_INDEX_WEBLOGS ));
211204 verifySchema (
212205 actual ,
@@ -225,24 +218,22 @@ response in ('500', '505'), false
225218 }
226219
227220 @ Test
228- public void testCaseWhenInSubquery () {
221+ public void testCaseWhenInSubquery () throws IOException {
229222 JSONObject actual =
230223 executeQuery (
231224 String .format (
232- """
233- source=%s
234- | where response in [
235- source = %s
236- | eval new_response = case(
237- response in ('200'), "201",
238- response in ('300', '301'), "301",
239- response in ('400', '403'), "403",
240- response in ('500', '505'), "500"
241- else concat("Incorrect HTTP status code for", url))
242- | fields new_response
243- ]
244- | fields host, method, message, bytes, response, url
245- """ ,
225+ "source=%s"
226+ + "| where response in ["
227+ + " source = %s"
228+ + " | eval new_response = case("
229+ + " response in ('200'), '201',"
230+ + " response in ('300', '301'), '301',"
231+ + " response in ('400', '403'), '403',"
232+ + " response in ('500', '505'), '500'"
233+ + " else concat('Incorrect HTTP status code for', url))"
234+ + " | fields new_response"
235+ + " ]"
236+ + "| fields host, method, message, bytes, response, url" ,
246237 TEST_INDEX_WEBLOGS , TEST_INDEX_WEBLOGS ));
247238 verifySchema (
248239 actual ,
0 commit comments