Support JOIN without table alias #274
Support JOIN without table alias #274
Conversation
src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/join/JoinRewriteRule.java
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/query/ESActionFactory.java
Show resolved
Hide resolved
public void rewrite(SQLQueryExpr root) { | ||
|
||
final Multimap<String, Table> tableByFieldName = ArrayListMultimap.create(); | ||
final Set<String> tableNameAndAlias = new HashSet<>(); |
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.
How is tableNameAndAlias used? I don't see what it's used for other than just storing the table name and alias which doesn't seem like it's necessary to create the Set for
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.
Right, good catch. I used it previously for a special case, and removed that after refactoring, Will remove it.
src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/join/JoinRewriteRule.java
Show resolved
Hide resolved
String tableName = tableExpr.getExpr().toString().replaceAll(" ", "").split("/")[0]; | ||
|
||
if (tableExpr.getAlias() == null) { | ||
// Could we not directly use table name as alias? |
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.
If the table join with itself, the alias will be duplicate. not sure wheter the syntax or semantic check this before reach here.
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.
For self join, the alias will not be duplicate as we generate different alias for each table without alias. I have added more checks to handle joins with same tables on either side. Added more integration tests as well.
src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/join/JoinRewriteRule.java
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/rewriter/join/JoinRewriteRule.java
Show resolved
Hide resolved
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.
LGTM
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.
LGTM
*Issue #232 *
Description of changes:
This pull request adds the ability to have JOIN queries without table alias given all the fields belong to either table but not common to both.
Testing:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.