-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Integration tests for LOOKUP JOIN over wider range of data types #126150
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
craigtaverner
merged 17 commits into
elastic:main
from
craigtaverner:lookup_join_types_it
May 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9b50f2b
Integration test for LOOKUP JOIN between various types
craigtaverner b296e34
Refactored to be easier to read and extend the tests
craigtaverner 19bb2a5
Support many combinations with errors and empty results
craigtaverner a388663
Reorder with private records at the bottom
craigtaverner 048c423
Support much wider range of types and mixed types
craigtaverner 183f463
Merge branch 'main' into lookup_join_types_it
craigtaverner bfc6ae3
Some fixes the javadocs
craigtaverner 3b774a3
Remove warnings
craigtaverner 031f370
Merge remote-tracking branch 'origin/main' into lookup_join_types_it
craigtaverner 056a723
Merge branch 'lookup_join_types_it' of github.com:craigtaverner/elast…
craigtaverner fc1b126
Added tests for DateTime
craigtaverner b39ebc5
Merge remote-tracking branch 'origin/main' into lookup_join_types_it
craigtaverner 71a0f59
Merge remote-tracking branch 'origin/main' into lookup_join_types_it
craigtaverner 8708f9b
Add negative tests for all unsupported types
craigtaverner 8d53897
Add support for scaled_float and some code-review changes
craigtaverner 9be9e9f
Merge remote-tracking branch 'origin/main' into lookup_join_types_it
craigtaverner 820d890
Fix mistake in scaled_float value and test non-unity scaling factor
craigtaverner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Integration test for LOOKUP JOIN between various types
- Loading branch information
commit 9b50f2bfca0068a6c7792d6bc1ea2ce6dabd3e4c
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
...l/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupJoinTypesIT.java
This file contains hidden or 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,137 @@ | ||
/* | ||
* 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.action; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.xpack.esql.core.type.DataType; | ||
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@ClusterScope(scope = SUITE, numClientNodes = 1, numDataNodes = 1) | ||
public class LookupJoinTypesIT extends ESIntegTestCase { | ||
|
||
private static final Map<DataType, DataType> compatibleJoinTypes = Map.of( | ||
DataType.KEYWORD, | ||
DataType.KEYWORD, | ||
DataType.TEXT, | ||
DataType.KEYWORD, | ||
DataType.INTEGER, | ||
DataType.INTEGER, | ||
DataType.FLOAT, | ||
DataType.FLOAT, | ||
DataType.DOUBLE, | ||
DataType.DOUBLE | ||
); | ||
|
||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return List.of(EsqlPlugin.class); | ||
} | ||
|
||
public void testLookupJoinTypes() { | ||
initIndexes(); | ||
initData(); | ||
for (Map.Entry<DataType, DataType> entry : compatibleJoinTypes.entrySet()) { | ||
String query = String.format( | ||
Locale.ROOT, | ||
"FROM index | LOOKUP JOIN %s ON field_%s | KEEP other", | ||
indexName(entry.getKey(), entry.getValue()), | ||
entry.getKey().esType() | ||
); | ||
try (var response = EsqlQueryRequestBuilder.newRequestBuilder(client()).query(query).get()) { | ||
Iterator<Object> results = response.response().column(0).iterator(); | ||
assertTrue("Expected at least one result for query: " + query, results.hasNext()); | ||
Object indexedResult = response.response().column(0).iterator().next(); | ||
assertThat("Expected valid result: " + query, indexedResult, equalTo("value")); | ||
} | ||
} | ||
} | ||
|
||
private void initIndexes() { | ||
// The main index will have many fields, one of each type to use in later type specific joins | ||
StringBuilder mainFields = new StringBuilder("{\n \"properties\" : {\n"); | ||
mainFields.append( | ||
compatibleJoinTypes.keySet() | ||
.stream() | ||
.map((l) -> "\"field_" + l.esType() + "\": { \"type\" : \"" + l.esType() + "\" }") | ||
.collect(Collectors.joining(",\n ")) | ||
); | ||
mainFields.append(" }\n}\n"); | ||
assertAcked(prepareCreate("index").setMapping(mainFields.toString())); | ||
|
||
Settings.Builder settings = Settings.builder() | ||
.put("index.number_of_shards", 1) | ||
.put("index.number_of_replicas", 0) | ||
.put("index.mode", "lookup"); | ||
compatibleJoinTypes.forEach( | ||
// Each lookup index will get a document with a field to join on, and a results field to get back | ||
(l, r) -> { assertAcked(prepareCreate(indexName(l, r)).setSettings(settings.build()).setMapping(String.format(Locale.ROOT, """ | ||
{ | ||
"properties" : { | ||
"field_%s": { "type" : "%s" }, | ||
"other": { "type" : "keyword" } | ||
} | ||
} | ||
""", l.esType(), r.esType()))); } | ||
); | ||
} | ||
|
||
private String indexName(DataType mainType, DataType lookupType) { | ||
return "index_" + mainType.esType() + "_" + lookupType.esType(); | ||
} | ||
|
||
private void initData() { | ||
List<String> mainProperties = new ArrayList<>(); | ||
int docId = 0; | ||
for (Map.Entry<DataType, DataType> entry : compatibleJoinTypes.entrySet()) { | ||
DataType mainType = entry.getKey(); | ||
DataType lookupType = entry.getValue(); | ||
String index = indexName(mainType, lookupType); | ||
String field = "field_" + mainType.esType(); | ||
String value = sampleDataFor(lookupType); | ||
String doc = String.format(Locale.ROOT, """ | ||
{ | ||
"%s": %s, | ||
"other": "value" | ||
} | ||
""", field, value); | ||
mainProperties.add(String.format(Locale.ROOT, "\"%s\": %s", field, value)); | ||
index(index, "" + (++docId), doc); | ||
refresh(index); | ||
} | ||
index("index", "1", String.format(Locale.ROOT, """ | ||
{ | ||
%s | ||
} | ||
""", String.join(",\n", mainProperties))); | ||
refresh("index"); | ||
} | ||
|
||
private String sampleDataFor(DataType type) { | ||
return switch (type) { | ||
case KEYWORD -> "\"key\""; | ||
case TEXT -> "\"key text\""; | ||
case INTEGER -> "1"; | ||
case FLOAT, DOUBLE -> "1.0"; | ||
default -> throw new IllegalArgumentException("Unsupported type: " + type); | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.