-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stored procedures execution (Incremental PR - II) (#141)
<!-- The PR description should answer 2 (maybe 3) important questions: --> ### What <!-- What is this PR trying to accomplish (and why, if it's not obvious)? --> This PR is the second incremental PR towards adding stored procedures support and this PR adds the execution logic of the same. The actual PR logic is not very large but due to the tests, the lines diff is around 18k. ### How <!-- How is it trying to accomplish it (what are the implementation steps)? --> Steps: 1. Identify whether the procedure name in the mutation request is a stored procedure. 2. Fetch the metadata of the stored procedure. 3. Arguments and field validation, throw error if any required argument is not provided in the request. 4. Create a temporary table, the schema of the temporary table is determined by the `returns` field of the stored procedure. The temporary table is used to write the results of the stored procedure into. 5. The SQL query is generated in the following format: ```sql INSERT INTO #TempTable (col1, col2) EXEC <stored_procedure_name> @arg1_name = arg_value ``` 6. Make another SQL query to query from the temporary table with the fields requested and return the response.
- Loading branch information
1 parent
5602bb4
commit 5d2f334
Showing
25 changed files
with
17,851 additions
and
130 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
52 changes: 52 additions & 0 deletions
52
...ver/tests/goldenfiles/mutations/stored_procedures/get_customer_details_with_invoices.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,52 @@ | ||
{ | ||
"operations": [ | ||
{ | ||
"type": "procedure", | ||
"name": "GetCustomerDetailsWithTotalPurchases", | ||
"arguments": { | ||
"CustomerId": 1, | ||
"Phone": "123" | ||
}, | ||
"fields": { | ||
"type": "array", | ||
"fields": { | ||
"type": "object", | ||
"fields": { | ||
"CustomerId": { | ||
"type": "column", | ||
"column": "CustomerId" | ||
}, | ||
"Invoices": { | ||
"type": "relationship", | ||
"arguments": {}, | ||
"column": "CustomerId", | ||
"relationship": "GetInvoice", | ||
"query": { | ||
"fields": { | ||
"InvoiceId": { | ||
"type": "column", | ||
"column": "InvoiceId" | ||
}, | ||
"Total": { | ||
"type": "column", | ||
"column": "Total" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"collection_relationships": { | ||
"GetInvoice": { | ||
"column_mapping": { | ||
"CustomerId": "CustomerId" | ||
}, | ||
"relationship_type": "array", | ||
"target_collection": "Invoice", | ||
"arguments": {} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...tests/goldenfiles/mutations/stored_procedures/get_customer_details_without_arguments.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,22 @@ | ||
{ | ||
"operations": [ | ||
{ | ||
"type": "procedure", | ||
"name": "GetCustomerDetailsWithTotalPurchases", | ||
"arguments": {}, | ||
"fields": { | ||
"type": "array", | ||
"fields": { | ||
"type": "object", | ||
"fields": { | ||
"CustomerId": { | ||
"type": "column", | ||
"column": "CustomerId" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"collection_relationships": {} | ||
} |
22 changes: 22 additions & 0 deletions
22
crates/ndc-sqlserver/tests/goldenfiles/mutations/stored_procedures/return_one.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,22 @@ | ||
{ | ||
"operations": [ | ||
{ | ||
"type": "procedure", | ||
"name": "ReturnOne", | ||
"arguments": {}, | ||
"fields": { | ||
"type": "array", | ||
"fields": { | ||
"type": "object", | ||
"fields": { | ||
"ReturnOneResult": { | ||
"type": "column", | ||
"column": "result" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"collection_relationships": {} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
..._tests__native_mutations__negative_native_mutations_test__atomicity_native_mutations.snap
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,11 @@ | ||
--- | ||
source: crates/ndc-sqlserver/tests/mutation_tests.rs | ||
expression: result | ||
--- | ||
[ | ||
{ | ||
"aggregates": { | ||
"artist_count": 275 | ||
} | ||
} | ||
] |
16 changes: 16 additions & 0 deletions
16
.../tests/snapshots/mutation_tests__stored_procedures__basic_stored_procedure_execution.snap
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,16 @@ | ||
--- | ||
source: crates/ndc-sqlserver/tests/mutation_tests.rs | ||
expression: result | ||
--- | ||
{ | ||
"operation_results": [ | ||
{ | ||
"type": "procedure", | ||
"result": [ | ||
{ | ||
"ReturnOneResult": 1 | ||
} | ||
] | ||
} | ||
] | ||
} |
48 changes: 48 additions & 0 deletions
48
...shots/mutation_tests__stored_procedures__execute_stored_procedure_with_relationships.snap
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,48 @@ | ||
--- | ||
source: crates/ndc-sqlserver/tests/mutation_tests.rs | ||
expression: result | ||
--- | ||
{ | ||
"operation_results": [ | ||
{ | ||
"type": "procedure", | ||
"result": [ | ||
{ | ||
"CustomerId": 1, | ||
"Invoices": { | ||
"rows": [ | ||
{ | ||
"InvoiceId": 98, | ||
"Total": 3.98 | ||
}, | ||
{ | ||
"InvoiceId": 121, | ||
"Total": 3.96 | ||
}, | ||
{ | ||
"InvoiceId": 143, | ||
"Total": 5.94 | ||
}, | ||
{ | ||
"InvoiceId": 195, | ||
"Total": 0.99 | ||
}, | ||
{ | ||
"InvoiceId": 316, | ||
"Total": 1.98 | ||
}, | ||
{ | ||
"InvoiceId": 327, | ||
"Total": 13.86 | ||
}, | ||
{ | ||
"InvoiceId": 382, | ||
"Total": 8.91 | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.