Github user kaspersorensen commented on a diff in the pull request:
https://github.com/apache/metamodel/pull/20#discussion_r29603364
--- Diff:
core/src/main/java/org/apache/metamodel/query/parser/FromItemParser.java ---
@@ -95,10 +104,32 @@ private FromItem parseTableItem(String itemToken) {
result.setQuery(_query);
return result;
}
+
+ private FromItem parseAllJoinItems(final String itemToken) {
+ String[] joinSplit = itemToken.split("(?i) JOIN ");
+ List<String> joinsList = new ArrayList<String>();
+ for(int i = 0 ; i < joinSplit.length -1 ; i++) {
+ joinSplit[i] = joinSplit[i].trim();
+ joinSplit[i+1] = joinSplit[i+1].trim();
+ String leftPart = joinSplit[i].substring(0,
joinSplit[i].lastIndexOf(" "));
+ String joinType =
joinSplit[i].substring(joinSplit[i].lastIndexOf(" "));
+ String rightPart = (i+1 == joinSplit.length-1) ?
joinSplit[i+1] : joinSplit[i+1].substring(0, joinSplit[i+1].lastIndexOf(" "));
+ joinsList.add((leftPart + " " + joinType + " JOIN " +
rightPart).replaceAll(" +", " "));
+ String rightTable = rightPart.substring(0,
rightPart.lastIndexOf(" ON "));
+ String nextJoinType =
joinSplit[i+1].substring(joinSplit[i+1].lastIndexOf(" "));
+ joinSplit[i+1] = rightTable + " " + nextJoinType;
+ }
+ Set<FromItem> fromItems = new HashSet<FromItem>();
+ FromItem leftFromItem = null;
+ for(String token : joinsList) {
+ leftFromItem = parseJoinItem(leftFromItem, token, fromItems);
+ }
+ return leftFromItem;
+ }
// this method will be documented based on this example itemToken: FOO
f
// INNER JOIN BAR b ON f.id = b.id
- private FromItem parseJoinItem(final String itemToken) {
+ private FromItem parseJoinItem(final FromItem leftFromItem,final
String itemToken,Set<FromItem> fromItems) {
--- End diff --
Very minor, but I am missing some spaces after the commas :-)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---