-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make search functions translation aware (#118355)
* Introduce TranslationAware interface * Serialize query builder * Fix EsqlNodeSubclassTests * Add javadoc * Address review comments * Revert changes on making constructors private
- Loading branch information
Showing
10 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...sql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TranslationAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.core.expression; | ||
|
||
import org.elasticsearch.xpack.esql.core.planner.TranslatorHandler; | ||
import org.elasticsearch.xpack.esql.core.querydsl.query.Query; | ||
|
||
/** | ||
* Expressions can implement this interface to control how they would be translated and pushed down as Lucene queries. | ||
* When an expression implements {@link TranslationAware}, we call {@link #asQuery(TranslatorHandler)} to get the | ||
* {@link Query} translation, instead of relying on the registered translators from EsqlExpressionTranslators. | ||
*/ | ||
public interface TranslationAware { | ||
Query asQuery(TranslatorHandler translatorHandler); | ||
} |
35 changes: 35 additions & 0 deletions
35
...ava/org/elasticsearch/xpack/esql/core/querydsl/query/TranslationAwareExpressionQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.core.querydsl.query; | ||
|
||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
|
||
/** | ||
* Expressions that store their own {@link QueryBuilder} and implement | ||
* {@link org.elasticsearch.xpack.esql.core.expression.TranslationAware} can use {@link TranslationAwareExpressionQuery} | ||
* to wrap their {@link QueryBuilder}, instead of using the other existing {@link Query} implementations. | ||
*/ | ||
public class TranslationAwareExpressionQuery extends Query { | ||
private final QueryBuilder queryBuilder; | ||
|
||
public TranslationAwareExpressionQuery(Source source, QueryBuilder queryBuilder) { | ||
super(source); | ||
this.queryBuilder = queryBuilder; | ||
} | ||
|
||
@Override | ||
public QueryBuilder asBuilder() { | ||
return queryBuilder; | ||
} | ||
|
||
@Override | ||
protected String innerToString() { | ||
return queryBuilder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.