-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add support for self-joins with sub-query #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c029bdb
feat: add support for self-joins
GurtejSohi 26932df
chore: address review comments
GurtejSohi 0378c9c
refactor: api changes for join expression
GurtejSohi fb4d86d
style: spotless formatting
GurtejSohi 72cbcff
feat: implementation for sub query joins within the same collection
GurtejSohi ca4d5f8
chore: complete the impl for sub query self join
GurtejSohi 986c619
test: add integration test for self join with sub-query
GurtejSohi a774807
chore: cleaned up code and added docs
GurtejSohi a72ddf6
chore: address review comments
GurtejSohi 9ee78fb
chore: address review comments p2
GurtejSohi 11f5d28
test: add integration test to verify self join with sub-query works f…
GurtejSohi ab72570
chore: update collection data for integration test
GurtejSohi b572d5f
refactor: move inner class in MongoLetClauseBuilder below the outer c…
GurtejSohi f7a0118
Merge branch 'main' into add-support-for-self-joins
GurtejSohi 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
document-store/src/integrationTest/resources/query/items_data_with_nested_fields.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| [ | ||
| { | ||
| "_id": 1, | ||
| "itemDetails": { | ||
| "item": "Comb", | ||
| "date": "2012-01-01", | ||
| "quantity": 10 | ||
| } | ||
| }, | ||
| { | ||
| "_id": 2, | ||
| "itemDetails": { | ||
| "item": "Shampoo", | ||
| "date": "2012-01-01", | ||
| "quantity": 10 | ||
| } | ||
| }, | ||
| { | ||
| "_id": 3, | ||
| "itemDetails": { | ||
| "item": "Shampoo", | ||
| "date": "2012-02-02", | ||
| "quantity": 20 | ||
| } | ||
| }, | ||
| { | ||
| "_id": 4, | ||
| "itemDetails": { | ||
| "item": "Shampoo", | ||
| "date": "2012-03-03", | ||
| "quantity": 30 | ||
| } | ||
| }, | ||
| { | ||
| "_id": 5, | ||
| "itemDetails": { | ||
| "item": "Soap", | ||
| "date": "2012-02-02", | ||
| "quantity": 20 | ||
| } | ||
| }, | ||
| { | ||
| "_id": 6, | ||
| "itemDetails": { | ||
| "item": "Soap", | ||
| "date": "2012-01-01", | ||
| "quantity": 10 | ||
| } | ||
| } | ||
| ] |
22 changes: 22 additions & 0 deletions
22
document-store/src/integrationTest/resources/query/self_join_with_sub_query_response.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [ | ||
| { | ||
| "date": "2015-09-10T08:43:00Z", | ||
| "item": "Comb", | ||
| "quantity": 10 | ||
| }, | ||
| { | ||
| "date": "2014-03-01T09:00:00Z", | ||
| "item": "Mirror", | ||
| "quantity": 1 | ||
| }, | ||
| { | ||
| "date": "2014-04-04T11:21:39.736Z", | ||
| "item": "Shampoo", | ||
| "quantity": 20 | ||
| }, | ||
| { | ||
| "date": "2016-02-06T20:20:13Z", | ||
| "item": "Soap", | ||
| "quantity": 5 | ||
| } | ||
| ] |
23 changes: 23 additions & 0 deletions
23
...store/src/integrationTest/resources/query/sub_query_join_response_with_nested_fields.json
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "itemDetails": { | ||
| "item": "Comb", | ||
| "date": "2012-01-01", | ||
| "quantity": 10 | ||
| } | ||
| }, | ||
| { | ||
| "itemDetails": { | ||
| "item": "Shampoo", | ||
| "date": "2012-03-03", | ||
| "quantity": 30 | ||
| } | ||
| }, | ||
| { | ||
| "itemDetails": { | ||
| "item": "Soap", | ||
| "date": "2012-02-02", | ||
| "quantity": 20 | ||
| } | ||
| } | ||
| ] |
69 changes: 69 additions & 0 deletions
69
...n/java/org/hypertrace/core/documentstore/expression/impl/AliasedIdentifierExpression.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package org.hypertrace.core.documentstore.expression.impl; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import lombok.Value; | ||
| import org.hypertrace.core.documentstore.parser.SelectTypeExpressionVisitor; | ||
|
|
||
| /** | ||
| * Expression for referencing an identifier/column name within a context having an alias. | ||
| * | ||
| * <p>Example: In this query: <code> | ||
| * SELECT item, quantity, date | ||
| * FROM <implicit_collection> | ||
| * JOIN ( | ||
| * SELECT item, MAX(date) AS latest_date | ||
| * FROM <implicit_collection> | ||
| * GROUP BY item | ||
| * ) AS latest | ||
| * ON item = latest.item | ||
| * ORDER BY `item` ASC; | ||
| * </code> the rhs of the join condition "latest.item" can be expressed as: <code> | ||
| * AliasedIdentifierExpression.builder().name("item").alias("alias1").build() </code> | ||
| */ | ||
| @Value | ||
| public class AliasedIdentifierExpression extends IdentifierExpression { | ||
| String contextAlias; | ||
|
|
||
| private AliasedIdentifierExpression(final String name, final String contextAlias) { | ||
| super(name); | ||
| this.contextAlias = contextAlias; | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T accept(final SelectTypeExpressionVisitor visitor) { | ||
| return visitor.visit(this); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "`" + getContextAlias() + "." + getName() + "`"; | ||
|
Check warning on line 39 in document-store/src/main/java/org/hypertrace/core/documentstore/expression/impl/AliasedIdentifierExpression.java
|
||
| } | ||
|
|
||
| public static AliasedIdentifierExpressionBuilder builder() { | ||
| return new AliasedIdentifierExpressionBuilder(); | ||
| } | ||
|
|
||
| public static class AliasedIdentifierExpressionBuilder { | ||
| private String name; | ||
| private String contextAlias; | ||
|
|
||
| public AliasedIdentifierExpressionBuilder name(final String name) { | ||
| this.name = name; | ||
| return this; | ||
| } | ||
|
|
||
| public AliasedIdentifierExpressionBuilder contextAlias(final String contextAlias) { | ||
| this.contextAlias = contextAlias; | ||
| return this; | ||
| } | ||
|
|
||
| public AliasedIdentifierExpression build() { | ||
| Preconditions.checkArgument( | ||
| this.name != null && !this.name.isBlank(), "name is null or blank"); | ||
| Preconditions.checkArgument( | ||
| this.contextAlias != null && !this.contextAlias.isBlank(), | ||
| "contextAlias is null or blank"); | ||
| return new AliasedIdentifierExpression(this.name, this.contextAlias); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Why not just
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.
Alias sounds like we are giving the field name as alias (like in SelectionSpec. If you look at the example above, this is not the alias for the field, but the alias for the context in which we are referring the field.
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.
Makes sense.