SQL: concrete indices array size bug fix (#43878)
* The created array didn't have the correct initial size while attempting to resolve multiple indices (cherry picked from commit 341006e9913e831408f5bbc7f8ad8c453a7f630e)
This commit is contained in:
parent
44781e415e
commit
9957b66d2e
|
@ -497,7 +497,7 @@ public class IndexResolver {
|
|||
if (unmappedIndices.isEmpty() == true) {
|
||||
concreteIndices = asList(capIndices);
|
||||
} else {
|
||||
concreteIndices = new ArrayList<>(capIndices.length - unmappedIndices.size() + 1);
|
||||
concreteIndices = new ArrayList<>(capIndices.length);
|
||||
for (String capIndex : capIndices) {
|
||||
// add only indices that have a mapping
|
||||
if (unmappedIndices.contains(capIndex) == false) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.elasticsearch.xpack.sql.type.DataType;
|
||||
import org.elasticsearch.xpack.sql.type.EsField;
|
||||
import org.elasticsearch.xpack.sql.type.InvalidMappedField;
|
||||
import org.elasticsearch.xpack.sql.type.KeywordEsField;
|
||||
import org.elasticsearch.xpack.sql.type.TypesTests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -164,8 +165,6 @@ public class IndexResolverTests extends ESTestCase {
|
|||
((InvalidMappedField) esField).errorMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testSeparateSameMappingDifferentIndices() throws Exception {
|
||||
Map<String, EsField> oneMapping = TypesTests.loadMapping("mapping-basic.json", true);
|
||||
Map<String, EsField> sameMapping = TypesTests.loadMapping("mapping-basic.json", true);
|
||||
|
@ -192,6 +191,26 @@ public class IndexResolverTests extends ESTestCase {
|
|||
assertEqualsMaps(incompatible, indices.get(1).mapping());
|
||||
}
|
||||
|
||||
// covers the scenario described in https://github.com/elastic/elasticsearch/issues/43876
|
||||
public void testMultipleCompatibleIndicesWithDifferentFields() {
|
||||
int indicesCount = randomIntBetween(2, 15);
|
||||
EsIndex[] expectedIndices = new EsIndex[indicesCount];
|
||||
|
||||
// each index will have one field with different name than all others
|
||||
for (int i = 0; i < indicesCount; i++) {
|
||||
Map<String, EsField> mapping = new HashMap<>(1);
|
||||
String fieldName = "field" + (i + 1);
|
||||
mapping.put(fieldName, new KeywordEsField(fieldName));
|
||||
expectedIndices[i] = new EsIndex("index" + (i + 1), mapping);
|
||||
}
|
||||
|
||||
List<EsIndex> actualIndices = separate(expectedIndices);
|
||||
assertEquals(indicesCount, actualIndices.size());
|
||||
for (int i = 0; i < indicesCount; i++) {
|
||||
assertEqualsMaps(expectedIndices[i].mapping(), actualIndices.get(i).mapping());
|
||||
}
|
||||
}
|
||||
|
||||
public static IndexResolution merge(EsIndex... indices) {
|
||||
return IndexResolver.mergedMappings("*", Stream.of(indices).map(EsIndex::name).toArray(String[]::new), fromMappings(indices));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue