-
Notifications
You must be signed in to change notification settings - Fork 186
Fix #46 #71
Fix #46 #71
Changes from 4 commits
ecb779c
7041361
d3b390d
e10f125
0042559
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,8 +73,8 @@ 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) | ||
&& !hasIdenticalMappings(curScope(), indexToType)) { | ||
throw new VerificationException("When using multiple indices, the mappings must be identical."); | ||
&& !hasUnknownIndex(curScope())) { | ||
throw new VerificationException("Unknown index " + indexToType.keySet()); | ||
} | ||
return true; | ||
} | ||
|
@@ -210,12 +210,8 @@ public boolean isValidIdentifierForTerm(SQLIdentifierExpr expr) { | |
); | ||
} | ||
|
||
public boolean hasIdenticalMappings(TermFieldScope scope, Map<String, String> indexToType) { | ||
public boolean hasUnknownIndex(TermFieldScope scope) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the definition of "unknown index"? Based on the code in this method, as well as on lines 76-77, I think the logic should be inverted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. "unknown index" refers to index that is not existed, or can not be matched by wildcard. I modified the logic to make more sense. |
||
if (scope.getMapper().isEmpty()) { | ||
throw new VerificationException("Unknown index " + indexToType.keySet()); | ||
} | ||
|
||
if (isMappingOfAllIndicesDifferent()) { | ||
return false; | ||
} | ||
|
||
|
@@ -246,12 +242,4 @@ public static String toString(TermRewriterFilter filter) { | |
return filter.name; | ||
} | ||
} | ||
|
||
private boolean isMappingOfAllIndicesDifferent() { | ||
// Collect all FieldMappings into hash set and ignore index/type names. Size > 1 means FieldMappings NOT unique. | ||
return curScope().getMapper().allMappings().stream(). | ||
flatMap(typeMappings -> typeMappings.allMappings().stream()). | ||
collect(Collectors.toSet()). | ||
size() > 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ public void testNonResolvingIndexPatternWithNonExistingIndex() throws IOExceptio | |
} | ||
|
||
@Test | ||
@Ignore("allow non-identical mapping when query multi-index") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer deleting the tests that are not asserting any truth anymore. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleted |
||
public void testNonIdenticalMappings() throws IOException { | ||
try { | ||
explainQuery(String.format(Locale.ROOT, "SELECT firstname, birthdate FROM %s, %s " + | ||
|
@@ -115,6 +116,17 @@ public void testNonIdenticalMappings() throws IOException { | |
} | ||
} | ||
|
||
@Test | ||
public void testAllowNonIdenticalMappings() throws IOException { | ||
String result = explainQuery(String.format(Locale.ROOT, "SELECT firstname, birthdate FROM %s, %s " + | ||
"WHERE firstname = 'Leo' OR male = 'true'", | ||
TEST_INDEX_BANK, TEST_INDEX_ONLINE)); | ||
assertThat(result, containsString("term")); | ||
assertThat(result, containsString("_source")); | ||
assertThat(result, containsString("firstname")); | ||
assertThat(result, containsString("birthdate")); | ||
} | ||
|
||
@Test | ||
public void testIdenticalMappings() throws IOException { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that relaxing the mapping check completely will break the functionality where mappings are used to generate Elasticsearch DSL such as
WHERE =
clause,GROUP BY
,ORDER By
etc. This is because it will make it ambiguous as to mapping from which index to be applied. Lets keep this function, but only check for mappings present as part ofSELECT
clause.