1111
1212import org .apache .lucene .search .IndexSearcher ;
1313import org .elasticsearch .Build ;
14- import org .elasticsearch .common .logging .LoggerMessageFormat ;
1514import org .elasticsearch .common .settings .Settings ;
1615import org .elasticsearch .core .Tuple ;
1716import org .elasticsearch .index .IndexMode ;
@@ -437,40 +436,6 @@ public void testQueryStringFunctionConjunctionWhereOperands() {
437436 assertThat (query .query ().toString (), is (expected .toString ()));
438437 }
439438
440- /**
441- * Expecting
442- * LimitExec[1000[INTEGER]]
443- * \_ExchangeExec[[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gender{f}#5, job{f}#10, job.raw{f}#11, languages{f}#6, last_n
444- * ame{f}#7, long_noidx{f}#12, salary{f}#8],false]
445- * \_ProjectExec[[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gender{f}#5, job{f}#10, job.raw{f}#11, languages{f}#6, last_n
446- * ame{f}#7, long_noidx{f}#12, salary{f}#8]]
447- * \_FieldExtractExec[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gen]
448- * \_EsQueryExec[test], indexMode[standard], query[{"bool":{"should":[{"query_string":{"query":"last_name: Smith","fields":[]}},
449- * {"esql_single_value":{"field":"emp_no","next":{"range":{"emp_no":{"gt":10010,"boost":1.0}}},"source":"emp_no > 10010@2:37"}}],
450- * "boost":1.0}}][_doc{f}#13], limit[1000], sort[] estimatedRowSize[324]
451- */
452- public void testQueryStringFunctionDisjunctionWhereClauses () {
453- assumeTrue ("skipping because QSTR_FUNCTION is not enabled" , EsqlCapabilities .Cap .QSTR_FUNCTION .isEnabled ());
454- String queryText = """
455- from test
456- | where qstr("last_name: Smith") or emp_no > 10010
457- """ ;
458- var plan = plannerOptimizer .plan (queryText , IS_SV_STATS );
459-
460- var limit = as (plan , LimitExec .class );
461- var exchange = as (limit .child (), ExchangeExec .class );
462- var project = as (exchange .child (), ProjectExec .class );
463- var field = as (project .child (), FieldExtractExec .class );
464- var query = as (field .child (), EsQueryExec .class );
465- assertThat (query .limit ().fold (), is (1000 ));
466-
467- Source filterSource = new Source (2 , 36 , "emp_no > 10000" );
468- var range = wrapWithSingleQuery (queryText , QueryBuilders .rangeQuery ("emp_no" ).gt (10010 ), "emp_no" , filterSource );
469- var queryString = QueryBuilders .queryStringQuery ("last_name: Smith" );
470- var expected = QueryBuilders .boolQuery ().should (queryString ).should (range );
471- assertThat (query .query ().toString (), is (expected .toString ()));
472- }
473-
474439 /**
475440 * Expecting
476441 * LimitExec[1000[INTEGER]]
@@ -637,40 +602,6 @@ public void testMatchFunctionConjunctionWhereOperands() {
637602 assertThat (query .query ().toString (), is (expected .toString ()));
638603 }
639604
640- /**
641- * Expecting
642- * LimitExec[1000[INTEGER]]
643- * \_ExchangeExec[[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gender{f}#5, job{f}#10, job.raw{f}#11, languages{f}#6, last_n
644- * ame{f}#7, long_noidx{f}#12, salary{f}#8],false]
645- * \_ProjectExec[[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gender{f}#5, job{f}#10, job.raw{f}#11, languages{f}#6, last_n
646- * ame{f}#7, long_noidx{f}#12, salary{f}#8]]
647- * \_FieldExtractExec[_meta_field{f}#9, emp_no{f}#3, first_name{f}#4, gen]
648- * \_EsQueryExec[test], indexMode[standard], query[{"bool":{"should":[{"match":{"last_name":{"query":"Smith"}}},
649- * {"esql_single_value":{"field":"emp_no","next":{"range":{"emp_no":{"gt":10010,"boost":1.0}}},"source":"emp_no > 10010@2:38"}}],
650- * "boost":1.0}}][_doc{f}#14], limit[1000], sort[] estimatedRowSize[324]
651- */
652- public void testMatchFunctionDisjunctionWhereClauses () {
653- assumeTrue ("skipping because MATCH function is not enabled" , EsqlCapabilities .Cap .MATCH_FUNCTION .isEnabled ());
654- String queryText = """
655- from test
656- | where match(last_name, "Smith") or emp_no > 10010
657- """ ;
658- var plan = plannerOptimizer .plan (queryText , IS_SV_STATS );
659-
660- var limit = as (plan , LimitExec .class );
661- var exchange = as (limit .child (), ExchangeExec .class );
662- var project = as (exchange .child (), ProjectExec .class );
663- var field = as (project .child (), FieldExtractExec .class );
664- var query = as (field .child (), EsQueryExec .class );
665- assertThat (query .limit ().fold (), is (1000 ));
666-
667- Source filterSource = new Source (2 , 37 , "emp_no > 10000" );
668- var range = wrapWithSingleQuery (queryText , QueryBuilders .rangeQuery ("emp_no" ).gt (10010 ), "emp_no" , filterSource );
669- var queryString = QueryBuilders .matchQuery ("last_name" , "Smith" );
670- var expected = QueryBuilders .boolQuery ().should (queryString ).should (range );
671- assertThat (query .query ().toString (), is (expected .toString ()));
672- }
673-
674605 /**
675606 * Expecting
676607 * LimitExec[1000[INTEGER]]
@@ -742,73 +673,6 @@ public void testMatchFunctionMultipleWhereClauses() {
742673 assertThat (query .query ().toString (), is (expected .toString ()));
743674 }
744675
745- public void testQueryStringWithDisjunctionsThatCannotBePushedDown () {
746- assumeTrue ("skipping because QSTR is not enabled" , EsqlCapabilities .Cap .QSTR_FUNCTION .isEnabled ());
747-
748- checkWithDisjunctionsThatCannotBePushedDown ("QSTR" , "qstr(\" first_name: Anna\" )" );
749- }
750-
751- public void testMatchWithDisjunctionsThatCannotBePushedDown () {
752- assumeTrue ("skipping because MATCH function is not enabled" , EsqlCapabilities .Cap .MATCH_FUNCTION .isEnabled ());
753-
754- checkWithDisjunctionsThatCannotBePushedDown ("MATCH" , "match(first_name, \" Anna\" )" );
755- }
756-
757- private void checkWithDisjunctionsThatCannotBePushedDown (String functionName , String functionInvocation ) {
758- VerificationException ve = expectThrows (
759- VerificationException .class ,
760- () -> plannerOptimizer .plan ("from test | where " + functionInvocation + " or length(first_name) > 12" , IS_SV_STATS )
761- );
762- assertThat (
763- ve .getMessage (),
764- containsString (
765- LoggerMessageFormat .format (
766- null ,
767- "1:19: Invalid condition [{} or length(first_name) > 12]. "
768- + "Function {} can't be used as part of an or condition that includes [length(first_name) > 12]" ,
769- functionInvocation ,
770- functionName
771- )
772- )
773- );
774- ve = expectThrows (
775- VerificationException .class ,
776- () -> plannerOptimizer .plan (
777- "from test | where (" + functionInvocation + " and emp_no < 1000) or (length(first_name) > 12 and emp_no > 1000)" ,
778- IS_SV_STATS
779- )
780- );
781- assertThat (
782- ve .getMessage (),
783- containsString (
784- LoggerMessageFormat .format (
785- null ,
786- "1:19: Invalid condition [({} and emp_no < 1000) or (length(first_name) > 12 and emp_no > 1000)]. "
787- + "Function {} can't be used as part of an or condition that includes [length(first_name) > 12 and emp_no > 1000]" ,
788- functionInvocation ,
789- functionName
790- )
791- )
792- );
793- }
794-
795- public void testMatchFunctionDisjunctionNonPushableClauses () {
796- assumeTrue ("skipping because MATCH function is not enabled" , EsqlCapabilities .Cap .MATCH_FUNCTION .isEnabled ());
797- String queryText = """
798- from test
799- | where match(first_name, "Peter") or length(last_name) > 10
800- """ ;
801-
802- VerificationException ve = expectThrows (VerificationException .class , () -> plannerOptimizer .plan (queryText , IS_SV_STATS ));
803- assertThat (
804- ve .getMessage (),
805- containsString (
806- "Invalid condition [match(first_name, \" Peter\" ) or length(last_name) > 10]. "
807- + "Function MATCH can't be used as part of an or condition that includes [length(last_name) > 10]"
808- )
809- );
810- }
811-
812676 public void testMatchFunctionIsNotNullable () {
813677 assumeTrue ("skipping because MATCH function is not enabled" , EsqlCapabilities .Cap .MATCH_FUNCTION .isEnabled ());
814678
@@ -823,40 +687,6 @@ public void testMatchFunctionIsNotNullable() {
823687 );
824688 }
825689
826- /**
827- * Expected:
828- * LimitExec[1000[INTEGER]]
829- * \_ExchangeExec[[_meta_field{f}#10, emp_no{f}#4, first_name{f}#5, gender{f}#6, job{f}#11, job.raw{f}#12, languages{f}#7, last_
830- * name{f}#8, long_noidx{f}#13, salary{f}#9],false]
831- * \_ProjectExec[[_meta_field{f}#10, emp_no{f}#4, first_name{f}#5, gender{f}#6, job{f}#11, job.raw{f}#12, languages{f}#7, last_
832- * name{f}#8, long_noidx{f}#13, salary{f}#9]]
833- * \_FieldExtractExec[_meta_field{f}#10, emp_no{f}#4, first_name{f}
834- * \_EsQueryExec[test], indexMode[standard],
835- * query[{"bool":{"should":[{"match":{"first_name":{"query":"Peter"}}},{"esql_single_value":{"field":"last_name",
836- * "next":{"term":{"last_name":{"value":"Griffin"}}},"source":"last_name == \"Griffin\"@2:39"}}],"boost":1.0}}]
837- */
838- public void testMatchFunctionDisjunctionPushableClauses () {
839- assumeTrue ("skipping because MATCH function is not enabled" , EsqlCapabilities .Cap .MATCH_FUNCTION .isEnabled ());
840- String queryText = """
841- from test
842- | where match(first_name, "Peter") or last_name == "Griffin"
843- """ ;
844- var plan = plannerOptimizer .plan (queryText , IS_SV_STATS );
845-
846- var limit = as (plan , LimitExec .class );
847- var exchange = as (limit .child (), ExchangeExec .class );
848- var project = as (exchange .child (), ProjectExec .class );
849- var field = as (project .child (), FieldExtractExec .class );
850- var query = as (field .child (), EsQueryExec .class );
851- assertThat (query .limit ().fold (), is (1000 ));
852-
853- var queryStringLeft = QueryBuilders .matchQuery ("first_name" , "Peter" );
854- Source termSource = new Source (2 , 38 , "last_name == \" Griffin\" " );
855- var queryStringRight = wrapWithSingleQuery (queryText , QueryBuilders .termQuery ("last_name" , "Griffin" ), "last_name" , termSource );
856- var expected = QueryBuilders .boolQuery ().should (queryStringLeft ).should (queryStringRight );
857- assertThat (query .query ().toString (), is (expected .toString ()));
858- }
859-
860690 /**
861691 * Expecting
862692 * LimitExec[1000[INTEGER]]
0 commit comments