Skip to content

Commit d253a55

Browse files
Change Parser to allow AND of expressions
1 parent db5f8c5 commit d253a55

File tree

20 files changed

+893
-559
lines changed

20 files changed

+893
-559
lines changed

.idea/runConfigurations/Debug_Elasticsearch__node_2_.xml

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Debug_Elasticsearch__node_3_.xml

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static TransportVersion def(int id) {
359359
public static final TransportVersion SEMANTIC_QUERY_MULTIPLE_INFERENCE_IDS = def(9_150_0_00);
360360
public static final TransportVersion ESQL_LOOKUP_JOIN_PRE_JOIN_FILTER = def(9_151_0_00);
361361
public static final TransportVersion INFERENCE_API_DISABLE_EIS_RATE_LIMITING = def(9_152_0_00);
362-
public static final TransportVersion ESQL_LOOKUP_JOIN_ON_EXPRESSION = def(9_143_0_00);
362+
public static final TransportVersion ESQL_LOOKUP_JOIN_ON_EXPRESSION = def(9_153_0_00);
363363

364364
/*
365365
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/lookup/QueryList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,5 @@ private IntFunction<Query> shapeQuery() {
461461
}
462462
}
463463

464-
protected record OnlySingleValueParams(Warnings warnings, String multiValueWarningMessage) {}
464+
public record OnlySingleValueParams(Warnings warnings, String multiValueWarningMessage) {}
465465
}

x-pack/plugin/esql/qa/testFixtures/src/main/resources/lookup-join-expression.csv-spec

Lines changed: 279 additions & 98 deletions
Large diffs are not rendered by default.

x-pack/plugin/esql/src/main/antlr/parser/Expression.g4

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ matchBooleanExpression
3030

3131
valueExpression
3232
: operatorExpression #valueExpressionDefault
33-
| left=operatorExpression comparisonOperator right=operatorExpression #comparison
33+
| comparisonExpression #comparison
34+
;
35+
36+
comparisonExpression
37+
: left=operatorExpression comparisonOperator right=operatorExpression
3438
;
3539

3640
operatorExpression

x-pack/plugin/esql/src/main/antlr/parser/Join.g4

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ joinTarget
1818
;
1919

2020
joinCondition
21-
: ON joinPredicate (COMMA joinPredicate)*
22-
;
23-
24-
joinPredicate
25-
: valueExpression
21+
: ON qualifiedName (COMMA qualifiedName)* #fieldBasedLookupJoin
22+
| ON comparisonExpression (AND comparisonExpression)* #expressionBasedLookupJoin
2623
;
2724

2825

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/BinaryComparisonQueryList.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ public BinaryComparisonQueryList(
3939
Block block,
4040
EsqlBinaryComparison binaryComparison,
4141
ClusterService clusterService,
42-
AliasFilter aliasFilter
42+
AliasFilter aliasFilter,
43+
Warnings warnings
4344
) {
44-
super(field, searchExecutionContext, aliasFilter, block, null);
45+
super(
46+
field,
47+
searchExecutionContext,
48+
aliasFilter,
49+
block,
50+
new OnlySingleValueParams(warnings, "LOOKUP JOIN encountered multi-value")
51+
);
4552
// swap left and right if the field is on the right
4653
// We get a filter in the form left_expr >= right_expr
4754
// here we will swap it to right_expr <= left_expr
@@ -62,9 +69,6 @@ public QueryList onlySingleValues(Warnings warnings, String multiValueWarningMes
6269

6370
@Override
6471
public Query doGetQuery(int position, int firstValueIndex, int valueCount) {
65-
if (valueCount == 0) {
66-
return null;
67-
}
6872
Object value = blockValueReader.apply(firstValueIndex);
6973
// create a new comparison with the value from the block as a literal
7074
EsqlBinaryComparison comparison = binaryComparison.getFunctionType()

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/ExpressionQueryList.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.lucene.search.Query;
1313
import org.elasticsearch.cluster.service.ClusterService;
1414
import org.elasticsearch.compute.data.Block;
15+
import org.elasticsearch.compute.operator.Warnings;
1516
import org.elasticsearch.compute.operator.lookup.LookupEnrichQueryGenerator;
1617
import org.elasticsearch.compute.operator.lookup.QueryList;
1718
import org.elasticsearch.index.mapper.MappedFieldType;
@@ -56,20 +57,21 @@ public ExpressionQueryList(
5657
PhysicalPlan rightPreJoinPlan,
5758
ClusterService clusterService,
5859
LookupFromIndexService.TransportRequest request,
59-
AliasFilter aliasFilter
60+
AliasFilter aliasFilter,
61+
Warnings warnings
6062
) {
6163
if (queryLists.size() < 2 && (rightPreJoinPlan instanceof FilterExec == false) && request.getJoinOnConditions() == null) {
6264
throw new IllegalArgumentException("ExpressionQueryList must have at least two QueryLists or a pre-join filter");
6365
}
6466
this.queryLists = queryLists;
6567
this.context = context;
6668
this.aliasFilter = aliasFilter;
67-
buildJoinOnConditions(request, clusterService);
69+
buildJoinOnConditions(request, clusterService, warnings);
6870
buildPreJoinFilter(rightPreJoinPlan, clusterService);
6971

7072
}
7173

72-
private void buildJoinOnConditions(LookupFromIndexService.TransportRequest request, ClusterService clusterService) {
74+
private void buildJoinOnConditions(LookupFromIndexService.TransportRequest request, ClusterService clusterService, Warnings warnings) {
7375
// we support 2 modes of operation:
7476
// Join on fields
7577
// Join on AND of binary comparisons
@@ -108,7 +110,8 @@ private void buildJoinOnConditions(LookupFromIndexService.TransportRequest reque
108110
block,
109111
binaryComparison,
110112
clusterService,
111-
aliasFilter
113+
aliasFilter,
114+
warnings
112115
)
113116
);
114117
matched = true;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/LookupFromIndexService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected LookupEnrichQueryGenerator queryList(
128128
if (queryLists.size() == 1 && physicalPlan instanceof FilterExec == false && request.joinOnConditions == null) {
129129
return queryLists.getFirst();
130130
}
131-
return new ExpressionQueryList(queryLists, context, physicalPlan, clusterService, request, aliasFilter);
131+
return new ExpressionQueryList(queryLists, context, physicalPlan, clusterService, request, aliasFilter, warnings);
132132

133133
}
134134

0 commit comments

Comments
 (0)