Skip to content

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

Merged
merged 8 commits into from
Apr 30, 2025
Merged

Conversation

svilen-mihaylov-elastic
Copy link
Contributor

@svilen-mihaylov-elastic svilen-mihaylov-elastic commented Apr 25, 2025

Addresses #126603

There is a very large number of changes to auto-generated antlr files.

I've commented on the substantial changes.

@@ -87,6 +87,14 @@ field
: (qualifiedName ASSIGN)? booleanExpression
;

rerankFields
Copy link
Contributor Author

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
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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("""
Copy link
Contributor Author

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.

@svilen-mihaylov-elastic svilen-mihaylov-elastic changed the title Prevent unnamed fields [Draft] Prevent unnamed fields Apr 25, 2025
@@ -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()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change

@svilen-mihaylov-elastic svilen-mihaylov-elastic added the :Search Relevance/Search Catch all for Search Relevance label Apr 29, 2025
@@ -3613,6 +3613,19 @@ public void testResolveRerankFields() {
assertThat(rerank.scoreAttribute(), equalTo(getAttributeByName(relation.output(), MetadataAttribute.SCORE)));
}

{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test

@svilen-mihaylov-elastic svilen-mihaylov-elastic changed the title [Draft] Prevent unnamed fields .Prevent unnamed fields Apr 30, 2025
@svilen-mihaylov-elastic svilen-mihaylov-elastic changed the title .Prevent unnamed fields Prevent unnamed fields Apr 30, 2025
@svilen-mihaylov-elastic svilen-mihaylov-elastic marked this pull request as ready for review April 30, 2025 00:01
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Apr 30, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Contributor

@afoucret afoucret left a 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.

@afoucret afoucret merged commit 54c789d into elastic:main Apr 30, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants