2929import org .junit .rules .TestRule ;
3030
3131import java .io .IOException ;
32- import java .util .ArrayList ;
3332import java .util .List ;
3433import java .util .Map ;
3534import java .util .Set ;
@@ -205,25 +204,24 @@ private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder reques
205204 }
206205 }
207206
208- private <C , V > void assertResultMapForLike (
207+ private <C , V > void assertResultMapWithCapabilities (
209208 boolean includeCCSMetadata ,
210209 Map <String , Object > result ,
211210 C columns ,
212211 V values ,
213212 boolean remoteOnly ,
214- boolean requireLikeListCapability
213+ List < String > fullResultCapabilities
215214 ) throws IOException {
216- List <String > requiredCapabilities = new ArrayList <>(List .of ("like_on_index_fields" ));
217- if (requireLikeListCapability ) {
218- requiredCapabilities .add ("like_list_on_index_fields" );
219- }
220215 // the feature is completely supported if both local and remote clusters support it
221- boolean isSupported = capabilitiesSupportedNewAndOld ( requiredCapabilities );
222-
216+ // otherwise we expect a partial result, and will not check the data
217+ boolean isSupported = capabilitiesSupportedNewAndOld ( fullResultCapabilities );
223218 if (isSupported ) {
224219 assertResultMap (includeCCSMetadata , result , columns , values , remoteOnly );
225220 } else {
226- logger .info ("--> skipping data check for like index test, cluster does not support like index feature" );
221+ logger .info (
222+ "--> skipping data check for a test, cluster does not support all of [{}] capabilities" ,
223+ String .join ("," , fullResultCapabilities )
224+ );
227225 // just verify that we did not get a partial result
228226 var clusters = result .get ("_clusters" );
229227 var reason = "unexpected partial results" + (clusters != null ? ": _clusters=" + clusters : "" );
@@ -526,7 +524,7 @@ public void testLikeIndex() throws Exception {
526524 """ , includeCCSMetadata );
527525 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
528526 var values = List .of (List .of (remoteDocs .size (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ));
529- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
527+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List . of ( "like_on_index_fields" ) );
530528 }
531529
532530 public void testLikeIndexLegacySettingNoResults () throws Exception {
@@ -548,7 +546,7 @@ public void testLikeIndexLegacySettingNoResults() throws Exception {
548546 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
549547 // we expect empty result, since the setting is false
550548 var values = List .of ();
551- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
549+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List . of ( "like_on_index_fields" ) );
552550 }
553551 }
554552
@@ -572,7 +570,7 @@ public void testLikeIndexLegacySettingResults() throws Exception {
572570 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
573571 // we expect results, since the setting is false, but there is : in the LIKE query
574572 var values = List .of (List .of (remoteDocs .size (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ));
575- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
573+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List . of ( "like_on_index_fields" ) );
576574 }
577575 }
578576
@@ -586,7 +584,7 @@ public void testNotLikeIndex() throws Exception {
586584 """ , includeCCSMetadata );
587585 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
588586 var values = List .of (List .of (localDocs .size (), localIndex ));
589- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
587+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List . of ( "like_on_index_fields" ) );
590588 }
591589
592590 public void testLikeListIndex () throws Exception {
@@ -601,7 +599,14 @@ public void testLikeListIndex() throws Exception {
601599 """ , includeCCSMetadata );
602600 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
603601 var values = List .of (List .of (remoteDocs .size (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ));
604- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , true );
602+ assertResultMapWithCapabilities (
603+ includeCCSMetadata ,
604+ result ,
605+ columns ,
606+ values ,
607+ false ,
608+ List .of ("like_on_index_fields" , "like_list_on_index_fields" )
609+ );
605610 }
606611
607612 public void testNotLikeListIndex () throws Exception {
@@ -615,7 +620,14 @@ public void testNotLikeListIndex() throws Exception {
615620 """ , includeCCSMetadata );
616621 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
617622 var values = List .of (List .of (localDocs .size (), localIndex ));
618- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , true );
623+ assertResultMapWithCapabilities (
624+ includeCCSMetadata ,
625+ result ,
626+ columns ,
627+ values ,
628+ false ,
629+ List .of ("like_on_index_fields" , "like_list_on_index_fields" )
630+ );
619631 }
620632
621633 public void testNotLikeListKeyword () throws Exception {
@@ -633,7 +645,14 @@ public void testNotLikeListKeyword() throws Exception {
633645 List .of ((int ) remoteDocs .stream ().filter (filter ).count (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ),
634646 List .of ((int ) localDocs .stream ().filter (filter ).count (), localIndex )
635647 );
636- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , true );
648+ assertResultMapWithCapabilities (
649+ includeCCSMetadata ,
650+ result ,
651+ columns ,
652+ values ,
653+ false ,
654+ List .of ("like_on_index_fields" , "like_list_on_index_fields" )
655+ );
637656 }
638657
639658 public void testRLikeIndex () throws Exception {
@@ -646,7 +665,7 @@ public void testRLikeIndex() throws Exception {
646665 """ , includeCCSMetadata );
647666 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
648667 var values = List .of (List .of (remoteDocs .size (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ));
649- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
668+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List . of ( "like_on_index_fields" ) );
650669 }
651670
652671 public void testNotRLikeIndex () throws Exception {
@@ -659,7 +678,37 @@ public void testNotRLikeIndex() throws Exception {
659678 """ , includeCCSMetadata );
660679 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
661680 var values = List .of (List .of (localDocs .size (), localIndex ));
662- assertResultMapForLike (includeCCSMetadata , result , columns , values , false , false );
681+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List .of ("like_on_index_fields" ));
682+ }
683+
684+ public void testRLikeListIndex () throws Exception {
685+ assumeTrue ("not supported" , capabilitiesSupportedNewAndOld (List .of ("rlike_with_list_of_patterns" )));
686+ boolean includeCCSMetadata = includeCCSMetadata ();
687+ Map <String , Object > result = run ("""
688+ FROM test-local-index,*:test-remote-index METADATA _index
689+ | WHERE _index RLIKE (".*remote.*", ".*not-exist.*")
690+ | STATS c = COUNT(*) BY _index
691+ | SORT _index ASC
692+ """ , includeCCSMetadata );
693+ var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
694+ var values = List .of (List .of (remoteDocs .size (), REMOTE_CLUSTER_NAME + ":" + remoteIndex ));
695+ // we depend on the code in like_on_index_fields to serialize an ExpressionQueryBuilder
696+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List .of ("like_on_index_fields" ));
697+ }
698+
699+ public void testNotRLikeListIndex () throws Exception {
700+ assumeTrue ("not supported" , capabilitiesSupportedNewAndOld (List .of ("rlike_with_list_of_patterns" )));
701+ boolean includeCCSMetadata = includeCCSMetadata ();
702+ Map <String , Object > result = run ("""
703+ FROM test-local-index,*:test-remote-index METADATA _index
704+ | WHERE _index NOT RLIKE (".*remote.*", ".*not-exist.*")
705+ | STATS c = COUNT(*) BY _index
706+ | SORT _index ASC
707+ """ , includeCCSMetadata );
708+ var columns = List .of (Map .of ("name" , "c" , "type" , "long" ), Map .of ("name" , "_index" , "type" , "keyword" ));
709+ var values = List .of (List .of (localDocs .size (), localIndex ));
710+ // we depend on the code in like_on_index_fields to serialize an ExpressionQueryBuilder
711+ assertResultMapWithCapabilities (includeCCSMetadata , result , columns , values , false , List .of ("like_on_index_fields" ));
663712 }
664713
665714 private RestClient remoteClusterClient () throws IOException {
0 commit comments