Skip to content

Commit

Permalink
[opendistro-for-elasticsearch#46] fix semantic logic of unknown index…
Browse files Browse the repository at this point in the history
… check; delete useless test case
  • Loading branch information
zhongnansu committed Jun 6, 2019
1 parent e10f125 commit 0042559
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean visit(MySqlSelectQueryBlock query) {
collect(query.getFrom(), indexToType, curScope().getAliases());
curScope().setMapper(getMappings(indexToType));
if ((this.filterType == TermRewriterFilter.COMMA || this.filterType == TermRewriterFilter.MULTI_QUERY)
&& !hasUnknownIndex(curScope())) {
&& hasUnknownIndex(curScope())) {
throw new VerificationException("Unknown index " + indexToType.keySet());
}
return true;
Expand Down Expand Up @@ -212,13 +212,13 @@ public boolean isValidIdentifierForTerm(SQLIdentifierExpr expr) {

public boolean hasUnknownIndex(TermFieldScope scope) {
if (scope.getMapper().isEmpty()) {
return false;
return true;
}

// We need finalMapping to lookup for rewriting
FieldMappings fieldMappings = curScope().getMapper().firstMapping().firstMapping();
curScope().setFinalMapping(fieldMappings);
return true;
return false;
}

public IndexMappings getMappings(Map<String, String> indexToType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ public void testNonResolvingIndexPatternWithNonExistingIndex() throws IOExceptio
}
}

@Test
@Ignore("allow non-identical mapping when query multi-index")
public void testNonIdenticalMappings() throws IOException {
try {
explainQuery(String.format(Locale.ROOT, "SELECT firstname, birthdate FROM %s, %s " +
"WHERE firstname = 'Leo' OR male = 'true'",
TEST_INDEX_BANK, TEST_INDEX_ONLINE));
} catch (ResponseException e) {
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
final String entity = TestUtils.getResponseBody(e.getResponse());
assertThat(entity, containsString("When using multiple indices, the mappings must be identical"));
assertThat(entity, containsString("\"type\": \"VerificationException\""));
}
}

@Test
public void testAllowNonIdenticalMappings() throws IOException {
String result = explainQuery(String.format(Locale.ROOT, "SELECT firstname, birthdate FROM %s, %s " +
Expand Down

0 comments on commit 0042559

Please sign in to comment.