1313import java .io .IOException ;
1414import org .json .JSONObject ;
1515import org .junit .jupiter .api .Test ;
16+ import org .opensearch .client .Request ;
1617
1718public class CalcitePPLConditionBuiltinFunctionIT extends CalcitePPLIntegTestCase {
1819 @ Override
1920 public void init () throws IOException {
2021 super .init ();
2122 loadIndex (Index .STATE_COUNTRY );
2223 loadIndex (Index .STATE_COUNTRY_WITH_NULL );
24+ Request request1 =
25+ new Request ("PUT" , "/" + TEST_INDEX_STATE_COUNTRY_WITH_NULL + "/_doc/7?refresh=true" );
26+ request1 .setJsonEntity (
27+ "{\" name\" :\" "
28+ + " \" ,\" age\" :27,\" state\" :\" B.C\" ,\" country\" :\" Canada\" ,\" year\" :2023,\" month\" :4}" );
29+ client ().performRequest (request1 );
30+ Request request2 =
31+ new Request ("PUT" , "/" + TEST_INDEX_STATE_COUNTRY_WITH_NULL + "/_doc/8?refresh=true" );
32+ request2 .setJsonEntity (
33+ "{\" name\" :\" \" ,\" age\" :57,\" state\" :\" B.C\" ,\" country\" :\" Canada\" ,\" year\" :2023,\" month\" :4}" );
34+ client ().performRequest (request2 );
2335 }
2436
2537 @ Test
@@ -44,7 +56,15 @@ public void testIsNotNull() {
4456
4557 verifySchema (actual , schema ("name" , "string" ));
4658
47- verifyDataRows (actual , rows ("John" ), rows ("Jane" ), rows ("Jake" ), rows ("Hello" ), rows ("Kevin" ));
59+ verifyDataRows (
60+ actual ,
61+ rows ("John" ),
62+ rows ("Jane" ),
63+ rows ("Jake" ),
64+ rows ("Hello" ),
65+ rows ("Kevin" ),
66+ rows (" " ),
67+ rows ("" ));
4868 }
4969
5070 @ Test
@@ -64,7 +84,9 @@ public void testNullIf() {
6484 rows (null , 10 ),
6585 rows ("Jake" , 70 ),
6686 rows ("Kevin" , null ),
67- rows ("Hello" , 30 ));
87+ rows ("Hello" , 30 ),
88+ rows (" " , 27 ),
89+ rows ("" , 57 ));
6890 }
6991
7092 @ Test
@@ -85,7 +107,9 @@ public void testNullIfWithExpression() {
85107 rows (null , null ),
86108 rows ("Jake" , "HJake" ),
87109 rows ("Kevin" , "HKevin" ),
88- rows ("Hello" , null ));
110+ rows ("Hello" , null ),
111+ rows (" " , "H " ),
112+ rows ("" , "H" ));
89113 }
90114
91115 @ Test
@@ -105,7 +129,9 @@ public void testIfNull() {
105129 rows ("Unknown" , 10 ),
106130 rows ("Jake" , 70 ),
107131 rows ("Kevin" , null ),
108- rows ("Hello" , 30 ));
132+ rows ("Hello" , 30 ),
133+ rows (" " , 27 ),
134+ rows ("" , 57 ));
109135 }
110136
111137 @ Test
@@ -146,7 +172,9 @@ public void testIf() {
146172 rows ("young" , 20 ),
147173 rows ("young" , 10 ),
148174 rows ("old" , 70 ),
149- rows ("young" , 30 ));
175+ rows ("young" , 30 ),
176+ rows ("young" , 27 ),
177+ rows ("old" , 57 ));
150178 }
151179
152180 @ Test
@@ -162,4 +190,51 @@ public void testIfWithLike() {
162190 verifyDataRows (
163191 actual , rows (0.0 , "John" ), rows (0.0 , "Jane" ), rows (0.0 , "Jake" ), rows (1.0 , "Hello" ));
164192 }
193+
194+ @ Test
195+ public void testIsPresent () throws IOException {
196+ JSONObject actual =
197+ executeQuery (
198+ String .format (
199+ "source=%s | where ispresent(name) | fields name, age" ,
200+ TEST_INDEX_STATE_COUNTRY_WITH_NULL ));
201+
202+ verifySchema (actual , schema ("name" , "string" ), schema ("age" , "integer" ));
203+
204+ verifyDataRows (
205+ actual ,
206+ rows ("Jake" , 70 ),
207+ rows ("Hello" , 30 ),
208+ rows ("John" , 25 ),
209+ rows ("Jane" , 20 ),
210+ rows ("Kevin" , null ),
211+ rows (" " , 27 ),
212+ rows ("" , 57 ));
213+ }
214+
215+ @ Test
216+ public void testIsEmpty () throws IOException {
217+ JSONObject actual =
218+ executeQuery (
219+ String .format (
220+ "source=%s | where isempty(name) | fields name, age" ,
221+ TEST_INDEX_STATE_COUNTRY_WITH_NULL ));
222+
223+ verifySchema (actual , schema ("name" , "string" ), schema ("age" , "integer" ));
224+
225+ verifyDataRows (actual , rows (null , 10 ), rows ("" , 57 ));
226+ }
227+
228+ @ Test
229+ public void testIsBlank () throws IOException {
230+ JSONObject actual =
231+ executeQuery (
232+ String .format (
233+ "source=%s | where isblank(name) | fields name, age" ,
234+ TEST_INDEX_STATE_COUNTRY_WITH_NULL ));
235+
236+ verifySchema (actual , schema ("name" , "string" ), schema ("age" , "integer" ));
237+
238+ verifyDataRows (actual , rows (null , 10 ), rows (" " , 27 ), rows ("" , 57 ));
239+ }
165240}
0 commit comments