forked from Azure/azure-sdk-for-python
-
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.
[Cosmos] split proof queries async client (Azure#22261)
* initial commit * Client Constructor (Azure#20310) * Removed some stuff * Looking at constructors * Updated request * Added client close * working client creation Co-authored-by: simorenoh <[email protected]> * read database database read works, but ignored exception is returned: Fatal error on SSL transport NoneType has no attribute 'send' (_loop._proactor.send) RuntimeError: Event loop is closed Unclosed connector/ connection * Update simon_testfile.py * with coroutine Added methods needed to use async with when initializing client, but logs output "Exception ignored... Runtime Error: Event loop is closed" * Update simon_testfile.py * small changes * async with returns no exceptions * async read container * async item read * cleaning up * create item/ database methods * item delete working * docs replace functionality missing upsert and other resources * upsert functionality missing read_all_items and both query methods for container class * missing query methods * CRUD for udf, sproc, triggers * initial query logic + container methods * missing some execution logic and tests * oops * fully working queries * small fix to query_items() also fixed README and added examples_async * Update _cosmos_client_connection_async.py * Update _cosmos_client_connection.py * documentation update * updated MIT dates and get_user_client() description * Update CHANGELOG.md * Delete simon_testfile.py * leftover retry utility * Update README.md * docs and removed six package * changes based on comments still missing discussion resolution on SSL verification and tests for async functionality under test module (apart from samples which are basically end to end tests) * small change in type hints * updated readme * fixes based on conversations * added missing type comments * update changelog for ci pipeline * added typehints, moved params into keywords, added decorators, made _connection_policy private * changes based on sync with central sdk * remove is_system_key from scripts (only used in execute_sproc) is_system_key verifies that an empty partition key is properly dealt with if ['partitionKey']['systemKey'] exists in the container options - however, we do not allow containers to be created with empty partition key values in the python sdk, so the functionality is needless * Revert "remove is_system_key from scripts (only used in execute_sproc)" Reverting last commit, will find way to init is_system_key for now * async script proxy using composition * pylint * capitalized constants * Apply suggestions from code review Clarifying comments for README Co-authored-by: Gahl Levy <[email protected]> * closing python code snippet * last doc updates * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Simon Moreno <[email protected]> * version update * cosmos updates for release * working split proof for async client, need to remove prints() and make better comments * remove print statements and improve comments * Update CHANGELOG.md * pylint * address Annie's comments on sync split proof * parity with sync client * async comparing of document producers * removed unneeded logic/imports, made compares async for pylint attempt * spelling mistake and making private * making sync client private too * Update CHANGELOG.md * Delete test_axq.py Co-authored-by: annatisch <[email protected]> Co-authored-by: Gahl Levy <[email protected]> Co-authored-by: Travis Prescott <[email protected]>
- Loading branch information
1 parent
4851990
commit 9a2b86b
Showing
13 changed files
with
155 additions
and
37 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
74 changes: 74 additions & 0 deletions
74
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/_queue_async_helper.py
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,74 @@ | ||
# The MIT License (MIT) | ||
# Copyright (c) 2022 Microsoft Corporation | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
async def heap_push(heap, item, document_producer_comparator): | ||
"""Push item onto heap, maintaining the heap invariant.""" | ||
heap.append(item) | ||
await _sift_down(heap, document_producer_comparator, 0, len(heap) - 1) | ||
|
||
|
||
async def heap_pop(heap, document_producer_comparator): | ||
"""Pop the smallest item off the heap, maintaining the heap invariant.""" | ||
last_elt = heap.pop() # raises appropriate IndexError if heap is empty | ||
if heap: | ||
return_item = heap[0] | ||
heap[0] = last_elt | ||
await _sift_up(heap, document_producer_comparator, 0) | ||
return return_item | ||
return last_elt | ||
|
||
|
||
async def _sift_down(heap, document_producer_comparator, start_pos, pos): | ||
new_item = heap[pos] | ||
# Follow the path to the root, moving parents down until finding a place | ||
# new_item fits. | ||
while pos > start_pos: | ||
parent_pos = (pos - 1) >> 1 | ||
parent = heap[parent_pos] | ||
if await document_producer_comparator.compare(new_item, parent) < 0: | ||
# if new_item < parent: | ||
heap[pos] = parent | ||
pos = parent_pos | ||
continue | ||
break | ||
heap[pos] = new_item | ||
|
||
|
||
async def _sift_up(heap, document_producer_comparator, pos): | ||
end_pos = len(heap) | ||
start_pos = pos | ||
new_item = heap[pos] | ||
# Bubble up the smaller child until hitting a leaf. | ||
child_pos = 2 * pos + 1 # leftmost child position | ||
while child_pos < end_pos: | ||
# Set child_pos to index of smaller child. | ||
right_pos = child_pos + 1 | ||
# if right_pos < end_pos and not heap[child_pos] < heap[right_pos]: | ||
if right_pos < end_pos and not await document_producer_comparator.compare(heap[child_pos], heap[right_pos]) < 0: | ||
child_pos = right_pos | ||
# Move the smaller child up. | ||
heap[pos] = heap[child_pos] | ||
pos = child_pos | ||
child_pos = 2 * pos + 1 | ||
# The leaf at pos is empty now. Put new_item there, and bubble it up | ||
# to its final resting place (by sifting its parents down). | ||
heap[pos] = new_item | ||
await _sift_down(heap, document_producer_comparator, start_pos, pos) |
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
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
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
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
Oops, something went wrong.