@@ -328,7 +328,7 @@ public void testStatsWithoutAggsOrGroup() {
328328 }
329329
330330 public void testAggsWithGroupKeyAsAgg () {
331- var queries = new String [] { """
331+ var queries = new String []{ """
332332 row a = 1, b = 2
333333 | stats a by a
334334 """ , """
@@ -341,7 +341,7 @@ public void testAggsWithGroupKeyAsAgg() {
341341 """ , """
342342 row a = 1, b = 2
343343 | stats x = a by a
344- """ };
344+ """ };
345345
346346 for (String query : queries ) {
347347 expectVerificationError (query , "grouping key [a] already specified in the STATS BY clause" );
@@ -891,16 +891,16 @@ public void testInvalidQuotingAsLookupIndexPattern() {
891891 }
892892
893893 public void testIdentifierAsFieldName () {
894- String [] operators = new String [] { "==" , "!=" , ">" , "<" , ">=" , "<=" };
895- Class <?>[] expectedOperators = new Class <?>[] {
894+ String [] operators = new String []{ "==" , "!=" , ">" , "<" , ">=" , "<=" };
895+ Class <?>[] expectedOperators = new Class <?>[]{
896896 Equals .class ,
897897 Not .class ,
898898 GreaterThan .class ,
899899 LessThan .class ,
900900 GreaterThanOrEqual .class ,
901- LessThanOrEqual .class };
902- String []
identifiers =
new String []
{ "abc" ,
"`abc`" ,
"ab_c" ,
"a.b.c" ,
"@a" ,
"a.@b" ,
"`[email protected] `" };
903- String []
expectedIdentifiers =
new String []
{ "abc" ,
"abc" ,
"ab_c" ,
"a.b.c" ,
"@a" ,
"a.@b" ,
"[email protected] " };
901+ LessThanOrEqual .class };
902+ String []
identifiers =
new String []
{ "abc" ,
"`abc`" ,
"ab_c" ,
"a.b.c" ,
"@a" ,
"a.@b" ,
"`[email protected] `" };
903+ String []
expectedIdentifiers =
new String []
{ "abc" ,
"abc" ,
"ab_c" ,
"a.b.c" ,
"@a" ,
"a.@b" ,
"[email protected] " };
904904 LogicalPlan where ;
905905 for (int i = 0 ; i < operators .length ; i ++) {
906906 for (int j = 0 ; j < identifiers .length ; j ++) {
@@ -1033,7 +1033,7 @@ public void testSingleLineComments() {
10331033 }
10341034
10351035 public void testNewLines () {
1036- String [] delims = new String [] { "" , "\r " , "\n " , "\r \n " };
1036+ String [] delims = new String []{ "" , "\r " , "\n " , "\r \n " };
10371037 Function <String , String > queryFun = d -> d + "from " + d + " foo " + d + "| eval " + d + " x = concat(bar, \" baz\" )" + d ;
10381038 LogicalPlan reference = statement (queryFun .apply (delims [0 ]));
10391039 for (int i = 1 ; i < delims .length ; i ++) {
@@ -2941,13 +2941,13 @@ public void testNamedFunctionArgumentNotInMap() {
29412941
29422942 public void testNamedFunctionArgumentNotConstant () {
29432943 Map <String , String []> commands = Map .ofEntries (
2944- Map .entry ("eval x = {}" , new String [] { "31" , "35" }),
2945- Map .entry ("where {}" , new String [] { "28" , "32" }),
2946- Map .entry ("stats {}" , new String [] { "28" , "32" }),
2947- Map .entry ("stats agg() by {}" , new String [] { "37" , "41" }),
2948- Map .entry ("sort {}" , new String [] { "27" , "31" }),
2949- Map .entry ("dissect {} \" %{bar}\" " , new String [] { "30" , "34" }),
2950- Map .entry ("grok {} \" %{WORD:foo}\" " , new String [] { "27" , "31" })
2944+ Map .entry ("eval x = {}" , new String []{ "31" , "35" }),
2945+ Map .entry ("where {}" , new String []{ "28" , "32" }),
2946+ Map .entry ("stats {}" , new String []{ "28" , "32" }),
2947+ Map .entry ("stats agg() by {}" , new String []{ "37" , "41" }),
2948+ Map .entry ("sort {}" , new String []{ "27" , "31" }),
2949+ Map .entry ("dissect {} \" %{bar}\" " , new String []{ "30" , "34" }),
2950+ Map .entry ("grok {} \" %{WORD:foo}\" " , new String []{ "27" , "31" })
29512951 );
29522952
29532953 for (Map .Entry <String , String []> command : commands .entrySet ()) {
@@ -3176,7 +3176,7 @@ public void testValidJoinPattern() {
31763176 }
31773177
31783178 public void testInvalidFromPatterns () {
3179- var sourceCommands = Build .current ().isSnapshot () ? new String [] { "FROM" , "TS" } : new String [] { "FROM" };
3179+ var sourceCommands = Build .current ().isSnapshot () ? new String []{ "FROM" , "TS" } : new String []{ "FROM" };
31803180 var indexIsBlank = "Blank index specified in index pattern" ;
31813181 var remoteIsEmpty = "remote part is empty" ;
31823182 var invalidDoubleColonUsage = "invalid usage of :: separator" ;
@@ -3226,7 +3226,7 @@ public void testInvalidPatternsWithIntermittentQuotes() {
32263226 var randomIndex = randomIndexPattern ();
32273227 // Select an invalid char to sneak in.
32283228 // Note: some chars like '|' and '"' are excluded to generate a proper invalid name.
3229- Character [] invalidChars = { ' ' , '/' , '<' , '>' , '?' };
3229+ Character [] invalidChars = {' ' , '/' , '<' , '>' , '?' };
32303230 var randomInvalidChar = randomFrom (invalidChars );
32313231
32323232 // Construct the new invalid index pattern.
@@ -3664,7 +3664,7 @@ public void testInvalidFork() {
36643664 }
36653665
36663666 public void testFieldNamesAsCommands () throws Exception {
3667- String [] keywords = new String [] {
3667+ String [] keywords = new String []{
36683668 "dissect" ,
36693669 "drop" ,
36703670 "enrich" ,
@@ -3677,7 +3677,7 @@ public void testFieldNamesAsCommands() throws Exception {
36773677 "mv_expand" ,
36783678 "rename" ,
36793679 "sort" ,
3680- "stats" };
3680+ "stats" };
36813681 for (String keyword : keywords ) {
36823682 var plan = statement ("FROM test | STATS avg(" + keyword + ")" );
36833683 var aggregate = as (plan , Aggregate .class );
@@ -4724,32 +4724,96 @@ public void testUnclosedParenthesis() {
47244724 "ROW x = 1 | DROP x )" ,
47254725 "ROW a = [1, 2] | RENAME a =b)" ,
47264726 "ROW a = [1, 2] | MV_EXPAND a)" ,
4727- "from test | enrich a on b)" };
4727+ "from test | enrich a on b)" };
47284728 for (String q : queries ) {
47294729 expectError (q , "Invalid query" );
47304730 }
47314731 }
47324732
47334733 public void testBracketsInIndexNames () {
4734- expectError ("from test)" , "line 1:10: extraneous input ')' expecting <EOF>" );
47354734
4736- expectError ("from test | enrich foo)" , "line -1:-1: Invalid query [from test | enrich foo)]" );
4735+ List <String > patterns = List .of (
4736+ "(" ,
4737+ ")" ,
4738+ "()" ,
4739+ "(((" ,
4740+ ")))" ,
4741+ "(test" ,
4742+ "test)" ,
4743+ "(test)" ,
4744+ "te()st" ,
4745+ "concat(foo,bar)" ,
4746+ "((((()))))" ,
4747+ "(((abc)))" ,
4748+ "*()*" ,
4749+ "*test()*" );
4750+
4751+ for (String pattern : patterns ) {
4752+ expectErrorForBracketsWithoutQuotes (pattern );
4753+ expectSuccessForBracketsWithinQuotes (pattern );
4754+ }
47374755
4756+ expectError ("from test)" , "line 1:10: extraneous input ')' expecting <EOF>" );
4757+ expectError ("from te()st" , "line 1:8: token recognition error at: '('" );
4758+ expectError ("from test | enrich foo)" , "line -1:-1: Invalid query [from test | enrich foo)]" );
47384759 expectError ("from test | lookup join foo) on bar" , "line 1:28: token recognition error at: ')'" );
4760+ }
4761+
4762+ private void expectErrorForBracketsWithoutQuotes (String pattern ) {
4763+ expectThrows (
4764+ ParsingException .class ,
4765+ () -> processingCommand ("from " + pattern )
4766+ );
4767+
4768+ expectThrows (
4769+ ParsingException .class ,
4770+ () -> processingCommand ("from *:" + pattern )
4771+ );
4772+
4773+ expectThrows (
4774+ ParsingException .class ,
4775+ () -> processingCommand ("from remote1:" + pattern + ",remote2:" + pattern )
4776+ );
47394777
4740- LogicalPlan plan = statement ("from \" test)\" " );
4778+ expectThrows (
4779+ ParsingException .class ,
4780+ () -> processingCommand ("from test | lookup join " + pattern + " on bar" )
4781+ );
4782+
4783+ expectThrows (
4784+ ParsingException .class ,
4785+ () -> processingCommand ("from test | enrich " + pattern )
4786+ );
4787+ }
4788+
4789+ private void expectSuccessForBracketsWithinQuotes (String indexName ) {
4790+ LogicalPlan plan = statement ("from \" " + indexName + "\" " );
47414791 UnresolvedRelation from = as (plan , UnresolvedRelation .class );
4742- assertThat (from .indexPattern ().indexPattern (), is ("test)" ));
4792+ assertThat (from .indexPattern ().indexPattern (), is (indexName ));
47434793
4744- plan = statement ("from test | enrich \" foo)\" " );
4794+ plan = statement ("from \" *:" + indexName + "\" " );
4795+ from = as (plan , UnresolvedRelation .class );
4796+ assertThat (from .indexPattern ().indexPattern (), is ("*:" + indexName ));
4797+
4798+ plan = statement ("from \" remote1:" + indexName + ",remote2:" + indexName + "\" " );
4799+ from = as (plan , UnresolvedRelation .class );
4800+ assertThat (from .indexPattern ().indexPattern (), is ("remote1:" + indexName + ",remote2:" + indexName ));
4801+
4802+ plan = statement ("from test | enrich \" " + indexName + "\" " );
47454803 Enrich enrich = as (plan , Enrich .class );
4746- assertThat (enrich .policyName ().fold (FoldContext .small ()), is (BytesRefs .toBytesRef ("foo)" )));
4804+ assertThat (enrich .policyName ().fold (FoldContext .small ()), is (BytesRefs .toBytesRef (indexName )));
47474805 as (enrich .child (), UnresolvedRelation .class );
47484806
4749- plan = statement ("from test | lookup join \" foo)\" on bar" );
4750- LookupJoin lookup = as (plan , LookupJoin .class );
4751- UnresolvedRelation right = as (lookup .right (), UnresolvedRelation .class );
4752- assertThat (right .indexPattern ().indexPattern (), is ("foo)" ));
4807+ if (indexName .contains ("*" )) {
4808+ expectThrows (
4809+ ParsingException .class ,
4810+ () -> processingCommand ("from test | lookup join \" " + indexName + "\" on bar" )
4811+ );
4812+ } else {
4813+ plan = statement ("from test | lookup join \" " + indexName + "\" on bar" );
4814+ LookupJoin lookup = as (plan , LookupJoin .class );
4815+ UnresolvedRelation right = as (lookup .right (), UnresolvedRelation .class );
4816+ assertThat (right .indexPattern ().indexPattern (), is (indexName ));
4817+ }
47534818 }
4754-
47554819}
0 commit comments