-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PACHA-21] support uniqueness constraints in SQL layer (#1037)
<!-- The PR description should answer 2 important questions: --> ### What Exposes SQL constraints to datafusion's planner via the `TableProvider::constraints()` trait method. ### How We pull these constraints from the GraphQL configuration for the model. This is not ideal - the data should really live at the model layer now. But we can hopefully solve that later. <!-- How is it trying to accomplish it (what are the implementation steps)? --> V3_GIT_ORIGIN_REV_ID: c723d895fd707e24defae971f474b5938478a82b
- Loading branch information
1 parent
9dd4622
commit 7a31d2d
Showing
8 changed files
with
217 additions
and
11 deletions.
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
### Added | ||
|
||
- SQL endpoint can utilize uniqueness constraints | ||
|
||
### Fixed | ||
|
||
### Changed | ||
|
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
122 changes: 122 additions & 0 deletions
122
v3/crates/engine/tests/sql/aggregate/group_by_unique_key/expected.json
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
[ | ||
{ | ||
"billingAddress": "Theodor-Heuss-Straße 34", | ||
"billingCity": "Stuttgart", | ||
"billingCountry": "Germany", | ||
"billingPostalCode": "70174", | ||
"billingState": null, | ||
"customerId": 2, | ||
"invoiceDate": "2009-01-01T00:00:00", | ||
"invoiceId": 1, | ||
"total": 1, | ||
"invoice_line_count": 2 | ||
}, | ||
{ | ||
"billingAddress": "Ullevålsveien 14", | ||
"billingCity": "Oslo", | ||
"billingCountry": "Norway", | ||
"billingPostalCode": "0171", | ||
"billingState": null, | ||
"customerId": 4, | ||
"invoiceDate": "2009-01-02T00:00:00", | ||
"invoiceId": 2, | ||
"total": 3, | ||
"invoice_line_count": 4 | ||
}, | ||
{ | ||
"billingAddress": "Grétrystraat 63", | ||
"billingCity": "Brussels", | ||
"billingCountry": "Belgium", | ||
"billingPostalCode": "1000", | ||
"billingState": null, | ||
"customerId": 8, | ||
"invoiceDate": "2009-01-03T00:00:00", | ||
"invoiceId": 3, | ||
"total": 5, | ||
"invoice_line_count": 6 | ||
}, | ||
{ | ||
"billingAddress": "8210 111 ST NW", | ||
"billingCity": "Edmonton", | ||
"billingCountry": "Canada", | ||
"billingPostalCode": "T6G 2C7", | ||
"billingState": "AB", | ||
"customerId": 14, | ||
"invoiceDate": "2009-01-06T00:00:00", | ||
"invoiceId": 4, | ||
"total": 8, | ||
"invoice_line_count": 9 | ||
}, | ||
{ | ||
"billingAddress": "69 Salem Street", | ||
"billingCity": "Boston", | ||
"billingCountry": "USA", | ||
"billingPostalCode": "2113", | ||
"billingState": "MA", | ||
"customerId": 23, | ||
"invoiceDate": "2009-01-11T00:00:00", | ||
"invoiceId": 5, | ||
"total": 13, | ||
"invoice_line_count": 14 | ||
}, | ||
{ | ||
"billingAddress": "Berger Straße 10", | ||
"billingCity": "Frankfurt", | ||
"billingCountry": "Germany", | ||
"billingPostalCode": "60316", | ||
"billingState": null, | ||
"customerId": 37, | ||
"invoiceDate": "2009-01-19T00:00:00", | ||
"invoiceId": 6, | ||
"total": 0, | ||
"invoice_line_count": 1 | ||
}, | ||
{ | ||
"billingAddress": "Barbarossastraße 19", | ||
"billingCity": "Berlin", | ||
"billingCountry": "Germany", | ||
"billingPostalCode": "10779", | ||
"billingState": null, | ||
"customerId": 38, | ||
"invoiceDate": "2009-02-01T00:00:00", | ||
"invoiceId": 7, | ||
"total": 1, | ||
"invoice_line_count": 2 | ||
}, | ||
{ | ||
"billingAddress": "8, Rue Hanovre", | ||
"billingCity": "Paris", | ||
"billingCountry": "France", | ||
"billingPostalCode": "75002", | ||
"billingState": null, | ||
"customerId": 40, | ||
"invoiceDate": "2009-02-01T00:00:00", | ||
"invoiceId": 8, | ||
"total": 1, | ||
"invoice_line_count": 2 | ||
}, | ||
{ | ||
"billingAddress": "9, Place Louis Barthou", | ||
"billingCity": "Bordeaux", | ||
"billingCountry": "France", | ||
"billingPostalCode": "33000", | ||
"billingState": null, | ||
"customerId": 42, | ||
"invoiceDate": "2009-02-02T00:00:00", | ||
"invoiceId": 9, | ||
"total": 3, | ||
"invoice_line_count": 4 | ||
}, | ||
{ | ||
"billingAddress": "3 Chatham Street", | ||
"billingCity": "Dublin", | ||
"billingCountry": "Ireland", | ||
"billingPostalCode": null, | ||
"billingState": "Dublin", | ||
"customerId": 46, | ||
"invoiceDate": "2009-02-03T00:00:00", | ||
"invoiceId": 10, | ||
"total": 5, | ||
"invoice_line_count": 6 | ||
} | ||
] |
10 changes: 10 additions & 0 deletions
10
v3/crates/engine/tests/sql/aggregate/group_by_unique_key/plan.json
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"plan_type": "logical_plan", | ||
"plan": "Projection: Invoice.billingAddress, Invoice.billingCity, Invoice.billingCountry, Invoice.billingPostalCode, Invoice.billingState, Invoice.customerId, Invoice.invoiceDate, Invoice.invoiceId, Invoice.total, count(Int64(1)) AS invoice_line_count\n Limit: skip=0, fetch=10\n Aggregate: groupBy=[[Invoice.invoiceId, Invoice.billingAddress, Invoice.billingCity, Invoice.billingCountry, Invoice.billingPostalCode, Invoice.billingState, Invoice.customerId, Invoice.invoiceDate, Invoice.total]], aggr=[[count(Int64(1))]]\n Projection: Invoice.billingAddress, Invoice.billingCity, Invoice.billingCountry, Invoice.billingPostalCode, Invoice.billingState, Invoice.customerId, Invoice.invoiceDate, Invoice.invoiceId, Invoice.total\n Inner Join: Invoice.invoiceId = InvoiceLine.invoiceId\n ModelQuery: model=default:Invoice, projection=[billingAddress,billingCity,billingCountry,billingPostalCode,billingState,customerId,invoiceDate,invoiceId,total]\n ModelQuery: model=default:InvoiceLine, projection=[invoiceId]" | ||
}, | ||
{ | ||
"plan_type": "physical_plan", | ||
"plan": "ProjectionExec: expr=[billingAddress@1 as billingAddress, billingCity@2 as billingCity, billingCountry@3 as billingCountry, billingPostalCode@4 as billingPostalCode, billingState@5 as billingState, customerId@6 as customerId, invoiceDate@7 as invoiceDate, invoiceId@0 as invoiceId, total@8 as total, count(Int64(1))@9 as invoice_line_count]\n GlobalLimitExec: skip=0, fetch=10\n AggregateExec: mode=Single, gby=[invoiceId@7 as invoiceId, billingAddress@0 as billingAddress, billingCity@1 as billingCity, billingCountry@2 as billingCountry, billingPostalCode@3 as billingPostalCode, billingState@4 as billingState, customerId@5 as customerId, invoiceDate@6 as invoiceDate, total@8 as total], aggr=[count(Int64(1))]\n CoalesceBatchesExec: target_batch_size=8192\n HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(invoiceId@7, invoiceId@0)], projection=[billingAddress@0, billingCity@1, billingCountry@2, billingPostalCode@3, billingState@4, customerId@5, invoiceDate@6, invoiceId@7, total@8]\n NDCQueryPushDown\n NDCQueryPushDown\n" | ||
} | ||
] |
10 changes: 10 additions & 0 deletions
10
v3/crates/engine/tests/sql/aggregate/group_by_unique_key/query.sql
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT | ||
Invoice.*, | ||
COUNT(1) AS invoice_line_count | ||
FROM | ||
Invoice | ||
JOIN InvoiceLine USING (invoiceId) | ||
GROUP BY | ||
Invoice.invoiceId | ||
LIMIT | ||
10; |
3 changes: 3 additions & 0 deletions
3
v3/crates/engine/tests/sql/aggregate/group_by_unique_key/session_variables.json
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"x-hasura-role": "admin" | ||
} |
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
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