Skip to content

Fix union types in CCS (#128111) #128207

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 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/128111.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 128111
summary: Fix union types in CCS
area: ES|QL
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public static org.elasticsearch.Version remoteClusterVersion() {
return prop != null ? org.elasticsearch.Version.fromString(prop) : org.elasticsearch.Version.CURRENT;
}

public static org.elasticsearch.Version bwcVersion() {
org.elasticsearch.Version local = localClusterVersion();
org.elasticsearch.Version remote = remoteClusterVersion();
return local.before(remote) ? local : remote;
}

private static Version distributionVersion(String key) {
final String val = System.getProperty(key);
return val != null ? Version.fromString(val) : Version.CURRENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,29 @@ private void clearSkipUnavailable() {
.setPersistentSettings(settingsBuilder.build())
.get();
}

public void testMultiTypes() throws Exception {
Client remoteClient = client(REMOTE_CLUSTER_1);
int totalDocs = 0;
for (String type : List.of("integer", "long")) {
String index = "conflict-index-" + type;
assertAcked(remoteClient.admin().indices().prepareCreate(index).setMapping("port", "type=" + type));
int numDocs = between(1, 10);
for (int i = 0; i < numDocs; i++) {
remoteClient.prepareIndex(index).setId(Integer.toString(i)).setSource("port", i).get();
}
remoteClient.admin().indices().prepareRefresh(index).get();
totalDocs += numDocs;
}
for (String castFunction : List.of("TO_LONG", "TO_INT")) {
EsqlQueryRequest request = new EsqlQueryRequest();
request.query("FROM *:conflict-index-* | EVAL port=" + castFunction + "(port) | WHERE port is NOT NULL | STATS COUNT(port)");
try (EsqlQueryResponse resp = runQuery(request)) {
List<List<Object>> values = getValuesList(resp);
assertThat(values, hasSize(1));
assertThat(values.get(0), hasSize(1));
assertThat(values.get(0).get(0), equalTo((long) totalDocs));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private BlockLoader getBlockLoaderFor(int shardId, Attribute attr, MappedFieldTy
BlockLoader blockLoader = shardContext.blockLoader(getFieldName(attr), isUnsupported, fieldExtractPreference);
MultiTypeEsField unionTypes = findUnionTypes(attr);
if (unionTypes != null) {
String indexName = shardContext.ctx.index().getName();
// Use the fully qualified name `cluster:index-name` because multiple types are resolved on coordinator with the cluster prefix
String indexName = shardContext.ctx.getFullyQualifiedIndex().getName();
Expression conversion = unionTypes.getConversionExpressionForIndex(indexName);
return conversion == null
? BlockLoader.CONSTANT_NULLS
Expand Down