diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/matchtoterm/TermFieldRewriter.java b/src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/matchtoterm/TermFieldRewriter.java index 68af948bfc..ce9fbee134 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/matchtoterm/TermFieldRewriter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/matchtoterm/TermFieldRewriter.java @@ -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; @@ -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 indexToType) { diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/TermQueryExplainIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/TermQueryExplainIT.java index a31952a96b..93e6a047fd 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/TermQueryExplainIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/TermQueryExplainIT.java @@ -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 " +