-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Prevent unnamed fields #127416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent unnamed fields #127416
Conversation
@@ -87,6 +87,14 @@ field | |||
: (qualifiedName ASSIGN)? booleanExpression | |||
; | |||
|
|||
rerankFields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change
@@ -826,6 +826,30 @@ public List<Alias> visitFields(EsqlBaseParser.FieldsContext ctx) { | |||
return ctx != null ? visitList(this, ctx.field(), Alias.class) : new ArrayList<>(); | |||
} | |||
|
|||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change
@@ -3490,6 +3490,30 @@ private void assertEmptyEsRelation(LogicalPlan plan) { | |||
assertThat(esRelation.output(), equalTo(NO_FIELDS)); | |||
} | |||
|
|||
public void testResolveRerankInferenceId1() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change
assertThat(rerank.inferenceId(), equalTo(string("reranking-inference-id"))); | ||
} | ||
|
||
public void testResolveRerankInferenceId2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fails like this:
line 3:43: mismatched input '(' expecting {'=', ',', '.', 'with'}
org.elasticsearch.xpack.esql.parser.ParsingException: line 3:43: mismatched input '(' expecting {'=', ',', '.', 'with'}
at __randomizedtesting.SeedInfo.seed([44B54C6702F80BAB:54EBDBEBFE2717AA]:0)
at org.elasticsearch.xpack.esql.parser.EsqlParser$1.syntaxError(EsqlParser.java:198)
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
at org.elasticsearch.xpack.esql.parser.EsqlBaseParser.rerankCommand(EsqlBaseParser.java:4380)
at org.elasticsearch.xpack.esql.parser.EsqlBaseParser.processingCommand(EsqlBaseParser.java:722)
at org.elasticsearch.xpack.esql.parser.EsqlBaseParser.query(EsqlBaseParser.java:363)
at org.elasticsearch.xpack.esql.parser.EsqlBaseParser.singleStatement(EsqlBaseParser.java:246)
at org.elasticsearch.xpack.esql.parser.EsqlParser.invokeParser(EsqlParser.java:148)
at org.elasticsearch.xpack.esql.parser.EsqlParser.createStatement(EsqlParser.java:114)
at org.elasticsearch.xpack.esql.parser.EsqlParser.createStatement(EsqlParser.java:107)
at org.elasticsearch.xpack.esql.parser.EsqlParser.createStatement(EsqlParser.java:102)
at org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyze(AnalyzerTestUtils.java:128)
at org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyze(AnalyzerTestUtils.java:124)
at org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyze(AnalyzerTestUtils.java:120)
at org.elasticsearch.xpack.esql.analysis.AnalyzerTests.testResolveRerankInferenceId2(AnalyzerTests.java:3509)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1763)
at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:946)
at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:982)
at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:996)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.apache.lucene.tests.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:48)
at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
at org.apache.lucene.tests.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:45)
at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:843)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:490)
at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:955)
at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:840)
at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:891)
at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:902)
at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.tests.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:38)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.tests.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
at org.apache.lucene.tests.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:47)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
at com.carrotsearch.randomizedtesting.ThreadLeakControl.lambda$forkTimeoutingTask$0(ThreadLeakControl.java:850)
at java.base/java.lang.Thread.run(Thread.java:1447)
Caused by: org.antlr.v4.runtime.InputMismatchException
at org.antlr.v4.runtime.DefaultErrorStrategy.recoverInline(DefaultErrorStrategy.java:485)
at org.antlr.v4.runtime.Parser.match(Parser.java:208)
assumeTrue("Requires RERANK command", EsqlCapabilities.Cap.RERANK.isEnabled()); | ||
|
||
// Substring function is named, should work. | ||
LogicalPlan plan = analyze(""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parses correctly (but currently fails because the indexes do not exist). See the following test.
@@ -731,7 +731,8 @@ public PlanFactory visitRerankCommand(EsqlBaseParser.RerankCommandContext ctx) { | |||
); | |||
} | |||
|
|||
return p -> new Rerank(source, p, inferenceId(ctx.inferenceId), queryText, visitFields(ctx.fields())); | |||
// TODO: pass rerank context into visitFields? | |||
return p -> new Rerank(source, p, inferenceId(ctx.inferenceId), queryText, visitRerankFields(ctx.rerankFields())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/ParserUtils.java
Outdated
Show resolved
Hide resolved
@@ -3613,6 +3613,19 @@ public void testResolveRerankFields() { | |||
assertThat(rerank.scoreAttribute(), equalTo(getAttributeByName(relation.output(), MetadataAttribute.SCORE))); | |||
} | |||
|
|||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svilen-mihaylov-elastic This is great. Thank you for doing this.
Addresses #126603
There is a very large number of changes to auto-generated antlr files.
I've commented on the substantial changes.