@@ -124,16 +124,6 @@ public void testRegex() throws IOException {
124124 String query =
125125 source (
126126 TEST_INDEX_DYNAMIC , "regex department=\" Eng.*\" | fields account_number, department" );
127- assertThrows (RuntimeException .class , () -> executeQuery (query ));
128- }
129-
130- @ Test
131- public void testCastAndRegex () throws IOException {
132- String query =
133- source (
134- TEST_INDEX_DYNAMIC ,
135- "eval department=CAST(department AS string) | regex department=\" Eng.*\" | fields"
136- + " account_number, department" );
137127 JSONObject result = executeQuery (query );
138128
139129 verifySchema (result , schema ("account_number" , "bigint" ), schema ("department" , "string" ));
@@ -145,40 +135,39 @@ public void testRex() throws IOException {
145135 String query =
146136 source (
147137 TEST_INDEX_DYNAMIC ,
148- "rex field=firstname \" (?<initial>[A-Z])\" | fields firstname , initial | head 1" );
138+ "rex field=department ' (?<initial>[A-Z])'" + " | fields department , initial | head 1" );
149139 JSONObject result = executeQuery (query );
150140
151- verifySchema (result , schema ("firstname " , "string" ), schema ("initial" , "string" ));
152- verifyDataRows (result , rows ("John " , "J " ));
141+ verifySchema (result , schema ("department " , "string" ), schema ("initial" , "string" ));
142+ verifyDataRows (result , rows ("Engineering " , "E " ));
153143 }
154144
155145 @ Test
156- public void testCastAndRex () throws IOException {
146+ public void testRexWithNumeric () throws IOException {
157147 String query =
158148 source (
159149 TEST_INDEX_DYNAMIC ,
160- "eval department=CAST(department AS string) | rex field=department '(?<initial>[A-Z])'"
161- + " | fields department, initial | head 1" );
150+ "rex field=salary '(?<initial>[0-9])'" + " | fields salary, initial | head 1" );
162151 JSONObject result = executeQuery (query );
163152
164- verifySchema (result , schema ("department " , "string " ), schema ("initial" , "string" ));
165- verifyDataRows (result , rows ("Engineering" , "E " ));
153+ verifySchema (result , schema ("salary " , "int " ), schema ("initial" , "string" ));
154+ verifyDataRows (result , rows (75000 , "7 " ));
166155 }
167156
168157 @ Test
169- public void testCastAndParse () throws IOException {
158+ public void testParse () throws IOException {
170159 String query =
171160 source (
172161 TEST_INDEX_DYNAMIC ,
173- "eval department=CAST(department AS string) | fields department | parse department"
174- + " '(?<initial>[A-Z]).*' | fields department, initial | head 1" );
162+ "parse department '(?<initial>[A-Z]).*' | fields department, initial | head 1" );
163+
175164 assertExplainYaml (
176165 query ,
177166 "calcite:\n "
178167 + " logical: |\n "
179168 + " LogicalSystemLimit(fetch=[200], type=[QUERY_SIZE_LIMIT])\n "
180169 + " LogicalSort(fetch=[1])\n "
181- + " LogicalProject(department=[SAFE_CAST( ITEM($9, 'department') )],"
170+ + " LogicalProject(department=[ITEM($9, 'department')],"
182171 + " initial=[ITEM(PARSE(SAFE_CAST(ITEM($9, 'department')),"
183172 + " '(?<initial>[A-Z]).*':VARCHAR, 'regex':VARCHAR), 'initial':VARCHAR)])\n "
184173 + " CalciteLogicalIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n "
@@ -188,7 +177,7 @@ public void testCastAndParse() throws IOException {
188177 + " expr#11=[ITEM($t9, $t10)], expr#12=[SAFE_CAST($t11)],"
189178 + " expr#13=['(?<initial>[A-Z]).*':VARCHAR], expr#14=['regex':VARCHAR],"
190179 + " expr#15=[PARSE($t12, $t13, $t14)], expr#16=['initial':VARCHAR], expr#17=[ITEM($t15,"
191- + " $t16)], department=[$t12 ], initial=[$t17])\n "
180+ + " $t16)], department=[$t11 ], initial=[$t17])\n "
192181 + " EnumerableLimit(fetch=[1])\n "
193182 + " CalciteEnumerableIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n " );
194183
@@ -235,28 +224,41 @@ public void testRevers() throws IOException {
235224
236225 @ Test
237226 public void testBin () throws IOException {
238- String query = source (TEST_INDEX_DYNAMIC , "bin salary span=10000 | head 1" );
227+ String query =
228+ source (TEST_INDEX_DYNAMIC , "bin salary span=10000 | fields account_number, salary" );
239229 JSONObject result = executeQuery (query );
240230
241- verifySchema (
242- result ,
243- schema ("account_number" , "bigint" ),
244- schema ("firstname" , "string" ),
245- schema ("lastname" , "string" ),
246- schema ("salary" , "string" ),
247- schema ("city" , "string" ),
248- schema ("department" , "string" ),
249- schema ("json" , "string" ));
231+ assertExplainYaml (
232+ query ,
233+ "calcite:\n "
234+ + " logical: |\n "
235+ + " LogicalSystemLimit(fetch=[200], type=[QUERY_SIZE_LIMIT])\n "
236+ + " LogicalProject(account_number=[$0], salary=[SPAN_BUCKET(ITEM($9, 'salary'),"
237+ + " 10000)])\n "
238+ + " CalciteLogicalIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n "
239+ + " physical: |\n "
240+ + " EnumerableCalc(expr#0..9=[{inputs}], expr#10=['salary'], expr#11=[ITEM($t9,"
241+ + " $t10)], expr#12=[10000], expr#13=[SPAN_BUCKET($t11, $t12)], account_number=[$t0],"
242+ + " salary=[$t13])\n "
243+ + " EnumerableLimit(fetch=[200])\n "
244+ + " CalciteEnumerableIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n " );
245+
246+ verifySchema (result , schema ("account_number" , "bigint" ), schema ("salary" , "string" ));
250247 verifyDataRows (
251- result , rows (1 , "John" , "Doe" , "70000-80000" , "NYC" , "{\" n\" :1}" , "Engineering" ));
248+ result ,
249+ rows (1 , "70000-80000" ),
250+ rows (2 , "60000-70000" ),
251+ rows (3 , null ),
252+ rows (4 , "80000-90000" ),
253+ rows (5 , "60000-70000" ));
252254 }
253255
254256 @ Test
255- public void testCastAndPatterns () throws IOException {
257+ public void testPatterns () throws IOException {
256258 String query =
257259 source (
258260 TEST_INDEX_DYNAMIC ,
259- "eval department=CAST(department as string) | patterns department method=simple_pattern"
261+ "patterns department method=simple_pattern"
260262 + " | fields department, patterns_field | head 1" );
261263 JSONObject result = executeQuery (query );
262264
@@ -265,12 +267,12 @@ public void testCastAndPatterns() throws IOException {
265267 }
266268
267269 @ Test
268- public void testCastAndPatternsWithAggregation () throws IOException {
270+ public void testPatternsWithAggregation () throws IOException {
269271 // TODO:
270272 String query =
271273 source (
272274 TEST_INDEX_DYNAMIC ,
273- "eval department=CAST(department as string) | patterns department mode=aggregation"
275+ "patterns department mode=aggregation"
274276 + " method=simple_pattern | fields patterns_field, pattern_count, sample_logs |"
275277 + " head 1" );
276278 JSONObject result = executeQuery (query );
@@ -490,34 +492,29 @@ public void testEval() throws IOException {
490492 String query =
491493 source (
492494 TEST_INDEX_DYNAMIC ,
493- "eval salary = cast(salary as int) * 2 | fields firstname,"
494- + " lastname, salary | head 1" );
495+ "eval salary = 1 + salary * 2 | fields account_number, salary | head 1" );
495496
496497 assertExplainYaml (
497498 query ,
498499 "calcite:\n "
499500 + " logical: |\n "
500501 + " LogicalSystemLimit(fetch=[200], type=[QUERY_SIZE_LIMIT])\n "
501502 + " LogicalSort(fetch=[1])\n "
502- + " LogicalProject(firstname =[$1 ], lastname=[$2], salary=[ *(SAFE_CAST(ITEM($9,"
503- + " 'salary')), 2)])\n "
503+ + " LogicalProject(account_number =[$0 ], salary=[+(1, *(SAFE_CAST(ITEM($9,"
504+ + " 'salary')), 2.0E0:DOUBLE) )])\n "
504505 + " CalciteLogicalIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n "
505506 + " physical: |\n "
506507 + " EnumerableLimit(fetch=[200])\n "
507- + " EnumerableCalc(expr#0..9=[{inputs}], expr#10=['salary'], expr#11=[ITEM($t9,"
508- + " $t10)], expr#12=[SAFE_CAST($t11)], expr#13=[2], expr#14=[*($t12, $t13)],"
509- + " firstname=[$t1], lastname=[$t2], salary=[$t14])\n "
508+ + " EnumerableCalc(expr#0..9=[{inputs}], expr#10=[1], expr#11=['salary'],"
509+ + " expr#12=[ITEM($t9, $t11)], expr#13=[SAFE_CAST($t12)], expr#14=[2.0E0:DOUBLE],"
510+ + " expr#15=[*($t13, $t14)], expr#16=[+($t10, $t15)], account_number=[$t0],"
511+ + " salary=[$t16])\n "
510512 + " EnumerableLimit(fetch=[1])\n "
511- + " CalciteEnumerableIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n "
512- + "" );
513+ + " CalciteEnumerableIndexScan(table=[[OpenSearch, test_dynamic_fields]])\n " );
513514
514515 JSONObject result = executeQuery (query );
515516
516- verifySchema (
517- result ,
518- schema ("firstname" , "string" ),
519- schema ("lastname" , "string" ),
520- schema ("salary" , "int" ));
517+ verifySchema (result , schema ("account_number" , "bigint" ), schema ("salary" , "double" ));
521518 }
522519
523520 private void createTestIndexWithUnmappedFields () throws IOException {
0 commit comments