Skip to content

Commit a87841e

Browse files
committed
SQL: Fix incorrect message for aliases (#31792)
Fix the naming in the verification message thrown for aliases over multiple indices with different mappings.
1 parent c3fde6c commit a87841e

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/analysis/index/IndexResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static IndexResolution merge(List<IndexResolution> resolutions, String indexWild
253253
// need the same mapping across all resolutions
254254
if (!merged.get().mapping().equals(resolution.get().mapping())) {
255255
return IndexResolution.invalid(
256-
"[" + indexWildcard + "] points to indices [" + resolution.get().name() + "] "
256+
"[" + indexWildcard + "] points to indices [" + merged.get().name() + "] "
257257
+ "and [" + resolution.get().name() + "] which have different mappings. "
258258
+ "When using multiple indices, the mappings must be identical.");
259259
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.sql.analysis.index;
7+
8+
import org.elasticsearch.test.ESTestCase;
9+
import org.elasticsearch.xpack.sql.type.EsField;
10+
import org.elasticsearch.xpack.sql.type.TypesTests;
11+
12+
import java.util.Arrays;
13+
import java.util.Map;
14+
15+
public class IndexResolverTests extends ESTestCase {
16+
17+
public void testMergeSameMapping() throws Exception {
18+
Map<String, EsField> oneMapping = TypesTests.loadMapping("mapping-basic.json", true);
19+
Map<String, EsField> sameMapping = TypesTests.loadMapping("mapping-basic.json", true);
20+
assertNotSame(oneMapping, sameMapping);
21+
assertEquals(oneMapping, sameMapping);
22+
23+
String wildcard = "*";
24+
IndexResolution resolution = IndexResolver.merge(
25+
Arrays.asList(IndexResolution.valid(new EsIndex("a", oneMapping)), IndexResolution.valid(new EsIndex("b", sameMapping))),
26+
wildcard);
27+
28+
assertTrue(resolution.isValid());
29+
30+
EsIndex esIndex = resolution.get();
31+
32+
assertEquals(wildcard, esIndex.name());
33+
assertEquals(sameMapping, esIndex.mapping());
34+
}
35+
36+
public void testMergeDifferentMapping() throws Exception {
37+
Map<String, EsField> oneMapping = TypesTests.loadMapping("mapping-basic.json", true);
38+
Map<String, EsField> sameMapping = TypesTests.loadMapping("mapping-basic.json", true);
39+
Map<String, EsField> differentMapping = TypesTests.loadMapping("mapping-numeric.json", true);
40+
41+
assertNotSame(oneMapping, sameMapping);
42+
assertEquals(oneMapping, sameMapping);
43+
assertNotEquals(oneMapping, differentMapping);
44+
45+
String wildcard = "*";
46+
IndexResolution resolution = IndexResolver.merge(
47+
Arrays.asList(IndexResolution.valid(new EsIndex("a", oneMapping)),
48+
IndexResolution.valid(new EsIndex("b", sameMapping)),
49+
IndexResolution.valid(new EsIndex("diff", differentMapping))),
50+
wildcard);
51+
52+
assertFalse(resolution.isValid());
53+
54+
MappingException ex = expectThrows(MappingException.class, () -> resolution.get());
55+
assertEquals(
56+
"[*] points to indices [a] and [diff] which have different mappings. "
57+
+ "When using multiple indices, the mappings must be identical.",
58+
ex.getMessage());
59+
}
60+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"properties" : {
3+
"byte" : {
4+
"type" : "byte"
5+
},
6+
"short" : {
7+
"type" : "short"
8+
},
9+
"integer" : {
10+
"type" : "integer"
11+
},
12+
"long" : {
13+
"type" : "long"
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)