Skip to content
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

SQL: Fix incorrect message for aliases #31792

Merged
merged 3 commits into from
Jul 5, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static IndexResolution merge(List<IndexResolution> resolutions, String indexWild
// need the same mapping across all resolutions
if (!merged.get().mapping().equals(resolution.get().mapping())) {
return IndexResolution.invalid(
"[" + indexWildcard + "] points to indices [" + resolution.get().name() + "] "
"[" + indexWildcard + "] points to indices [" + merged.get().name() + "] "
+ "and [" + resolution.get().name() + "] which have different mappings. "
+ "When using multiple indices, the mappings must be identical.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.analysis.index;

import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.sql.type.EsField;
import org.elasticsearch.xpack.sql.type.TypesTests;

import java.util.Arrays;
import java.util.Map;

public class IndexResolverTests extends ESTestCase {

public void testMergeSameMapping() throws Exception {
Map<String, EsField> oneMapping = TypesTests.loadMapping("mapping-basic.json", true);
Map<String, EsField> sameMapping = TypesTests.loadMapping("mapping-basic.json", true);
assertNotSame(oneMapping, sameMapping);
assertEquals(oneMapping, sameMapping);

String wildcard = "*";
IndexResolution resolution = IndexResolver.merge(
Arrays.asList(IndexResolution.valid(new EsIndex("a", oneMapping)), IndexResolution.valid(new EsIndex("b", sameMapping))),
wildcard);

assertTrue(resolution.isValid());

EsIndex esIndex = resolution.get();

assertEquals(wildcard, esIndex.name());
assertEquals(sameMapping, esIndex.mapping());
}

public void testMergeDifferentMapping() throws Exception {
Map<String, EsField> oneMapping = TypesTests.loadMapping("mapping-basic.json", true);
Map<String, EsField> sameMapping = TypesTests.loadMapping("mapping-basic.json", true);
Map<String, EsField> differentMapping = TypesTests.loadMapping("mapping-numeric.json", true);

assertNotSame(oneMapping, sameMapping);
assertEquals(oneMapping, sameMapping);
assertNotEquals(oneMapping, differentMapping);

String wildcard = "*";
IndexResolution resolution = IndexResolver.merge(
Arrays.asList(IndexResolution.valid(new EsIndex("a", oneMapping)),
IndexResolution.valid(new EsIndex("b", sameMapping)),
IndexResolution.valid(new EsIndex("diff", differentMapping))),
Copy link
Contributor

@astefan astefan Jul 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth putting the different mapping as first in the List as a second test? (EsIndex("diff"...), EsIndex("same"..), EsIndex("one"))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is somewhat important for this test since the comparison is done between the first entry and the rest.
The order above tests that a and b pass and that a and diff fail - there are two comparisons applied.
Putting diff first will cause only one comparison since and and b are not compared.
A minor detail that was done on purpose.

wildcard);

assertFalse(resolution.isValid());

MappingException ex = expectThrows(MappingException.class, () -> resolution.get());
assertEquals(
"[*] points to indices [a] and [diff] which have different mappings. "
+ "When using multiple indices, the mappings must be identical.",
ex.getMessage());
}
}
16 changes: 16 additions & 0 deletions x-pack/plugin/sql/src/test/resources/mapping-numeric.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"properties" : {
"byte" : {
"type" : "byte"
},
"short" : {
"type" : "short"
},
"integer" : {
"type" : "integer"
},
"long" : {
"type" : "long"
}
}
}