This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Fix #46 #71
Closed
Closed
Fix #46 #71
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecb779c
[fix #46] get rid of identical mapping check
zhongnansu 7041361
Merge remote-tracking branch 'origin/master' into sql-46
zhongnansu d3b390d
[fix #46] ignore corresponding useless IT test, add a new one
zhongnansu e10f125
[fix #46] update new test method signature
zhongnansu 0042559
[#46] fix semantic logic of unknown index check; delete useless test …
zhongnansu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,19 +210,15 @@ 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; | ||
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) { | ||
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.