Skip to content
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

[Cosmos] split proof queries async client #22261

Merged
merged 83 commits into from
Feb 7, 2022
Merged
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
61ba8d1
initial commit
simorenoh Aug 13, 2021
15dcceb
Client Constructor (#20310)
annatisch Aug 20, 2021
bda95c3
read database
simorenoh Aug 27, 2021
c9648ab
Update simon_testfile.py
simorenoh Aug 27, 2021
80540dc
with coroutine
simorenoh Aug 30, 2021
1285438
Update simon_testfile.py
simorenoh Aug 30, 2021
992b0cd
small changes
simorenoh Aug 31, 2021
47cb688
async with returns no exceptions
simorenoh Aug 31, 2021
f3fa79f
Merge pull request #1 from Azure/simonmoreno/async
simorenoh Aug 31, 2021
0c49739
async read container
simorenoh Sep 1, 2021
47f4af5
async item read
simorenoh Sep 2, 2021
c97c946
cleaning up
simorenoh Sep 3, 2021
fcd95db
create item/ database methods
simorenoh Sep 13, 2021
36c5b90
item delete working
simorenoh Sep 13, 2021
44db2a2
docs replace functionality
simorenoh Sep 16, 2021
ec5b6ed
upsert functionality
simorenoh Sep 17, 2021
d63d052
Merge pull request #2 from simorenoh/item-read
simorenoh Oct 8, 2021
5d74c8f
missing query methods
simorenoh Oct 11, 2021
89fc2f7
CRUD for udf, sproc, triggers
simorenoh Oct 12, 2021
fdaa880
Merge branch 'Azure:main' into async-client
simorenoh Oct 12, 2021
3f9baf2
Merge branch 'Azure:main' into async-client
simorenoh Oct 12, 2021
d6650bc
Merge branch 'Azure:main' into query-functionality
simorenoh Oct 12, 2021
043dfe0
initial query logic + container methods
simorenoh Oct 13, 2021
befdb41
Merge branch 'async-client' into query-functionality
simorenoh Oct 13, 2021
8cffbe2
Merge pull request #3 from simorenoh/query-functionality
simorenoh Oct 13, 2021
72de7c8
missing some execution logic and tests
simorenoh Oct 21, 2021
5b805b8
oops
simorenoh Oct 21, 2021
8d8d0c4
fully working queries
simorenoh Oct 22, 2021
b597ca8
small fix to query_items()
simorenoh Oct 22, 2021
18319df
Update _cosmos_client_connection_async.py
simorenoh Oct 22, 2021
162c44d
Update _cosmos_client_connection.py
simorenoh Oct 22, 2021
ebbac51
documentation update
simorenoh Oct 22, 2021
43f78e6
Merge branch 'Azure:main' into main
simorenoh Oct 22, 2021
470aa5b
updated MIT dates and get_user_client() description
simorenoh Oct 22, 2021
74da690
Update CHANGELOG.md
simorenoh Oct 22, 2021
7104d63
Merge branch 'Azure:main' into main
simorenoh Oct 25, 2021
20718c7
Delete simon_testfile.py
simorenoh Oct 25, 2021
d825eaa
Merge pull request #4 from simorenoh/async-client
simorenoh Oct 25, 2021
e3c27a5
leftover retry utility
simorenoh Oct 25, 2021
3b778ad
Update README.md
simorenoh Oct 25, 2021
c6e352e
docs and removed six package
simorenoh Oct 28, 2021
8971a25
Merge remote-tracking branch 'upstream/main'
simorenoh Oct 28, 2021
52736ac
changes based on comments
simorenoh Nov 4, 2021
ad98039
small change in type hints
simorenoh Nov 4, 2021
f76c595
updated readme
simorenoh Nov 9, 2021
3f02a65
fixes based on conversations
simorenoh Nov 10, 2021
e719869
added missing type comments
simorenoh Nov 11, 2021
d03ee05
Merge branch 'Azure:main' into main
simorenoh Nov 11, 2021
02c52ee
update changelog for ci pipeline
simorenoh Nov 23, 2021
2cb4551
added typehints, moved params into keywords, added decorators, made _…
simorenoh Nov 29, 2021
cf20d35
changes based on sync with central sdk
simorenoh Dec 2, 2021
f456817
remove is_system_key from scripts (only used in execute_sproc)
simorenoh Dec 3, 2021
ea9bd16
Revert "remove is_system_key from scripts (only used in execute_sproc)"
simorenoh Dec 3, 2021
709d2eb
async script proxy using composition
simorenoh Dec 3, 2021
3277dd8
pylint
simorenoh Dec 3, 2021
a57cb4d
capitalized constants
simorenoh Dec 6, 2021
014578b
Apply suggestions from code review
simorenoh Dec 6, 2021
0d79695
closing python code snippet
simorenoh Dec 6, 2021
fdabea1
last doc updates
simorenoh Dec 7, 2021
016d0dd
Update sdk/cosmos/azure-cosmos/CHANGELOG.md
tjprescott Dec 7, 2021
8228aa9
version update
simorenoh Dec 7, 2021
7ae1cd0
Merge branch 'Azure:main' into main
simorenoh Dec 13, 2021
7e8e953
cosmos updates for release
simorenoh Dec 13, 2021
9a2acc7
working split proof for async client, need to remove prints() and mak…
simorenoh Dec 24, 2021
a88cdfa
remove print statements and improve comments
simorenoh Jan 11, 2022
99997e9
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
simorenoh Jan 12, 2022
f446308
Merge branch 'Azure-main'
simorenoh Jan 12, 2022
bc466d8
Merge branch 'Azure-main'
simorenoh Jan 12, 2022
bca2da7
Merge branch 'Azure:main' into main
simorenoh Jan 13, 2022
7d41d02
Update CHANGELOG.md
simorenoh Jan 13, 2022
8d49e0e
Merge branch 'main' into split-proof-async
simorenoh Jan 13, 2022
27dce87
pylint
simorenoh Jan 13, 2022
d70269c
address Annie's comments on sync split proof
simorenoh Jan 18, 2022
a86b733
parity with sync client
simorenoh Jan 21, 2022
a075a78
async comparing of document producers
simorenoh Jan 24, 2022
64b9cfa
Merge branch 'main' into split-proof-async
simorenoh Jan 24, 2022
e85b6de
removed unneeded logic/imports, made compares async for pylint attempt
simorenoh Jan 25, 2022
c220ade
spelling mistake and making private
simorenoh Jan 25, 2022
9d6a72f
Merge branch 'main' into split-proof-async
simorenoh Jan 25, 2022
c6d585e
making sync client private too
simorenoh Jan 25, 2022
c5e710a
Update CHANGELOG.md
simorenoh Feb 2, 2022
47a0acb
Delete test_axq.py
simorenoh Feb 2, 2022
6071694
Merge branch 'main' into split-proof-async
simorenoh Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CRUD for udf, sproc, triggers
simorenoh committed Oct 12, 2021

Verified

This commit was signed with the committer’s verified signature.
GuySartorelli Guy Sartorelli
commit 89fc2f731c39ab18cf07b085d6544bfbc7f55230
Original file line number Diff line number Diff line change
@@ -216,6 +216,41 @@ def _GetDatabaseIdWithPathForUser(self, database_link, user): # pylint: disable
database_id = base.GetResourceIdOrFullNameFromLink(database_link)
return database_id, path

def _GetContainerIdWithPathForSproc(self, collection_link, sproc): # pylint: disable=no-self-use
CosmosClientConnection.__ValidateResource(sproc)
sproc = sproc.copy()
if sproc.get("serverScript"):
sproc["body"] = str(sproc.pop("serverScript", ""))
elif sproc.get("body"):
sproc["body"] = str(sproc["body"])
path = base.GetPathFromLink(collection_link, "sprocs")
collection_id = base.GetResourceIdOrFullNameFromLink(collection_link)
return collection_id, path, sproc

def _GetContainerIdWithPathForTrigger(self, collection_link, trigger): # pylint: disable=no-self-use
CosmosClientConnection.__ValidateResource(trigger)
trigger = trigger.copy()
if trigger.get("serverScript"):
trigger["body"] = str(trigger.pop("serverScript", ""))
elif trigger.get("body"):
trigger["body"] = str(trigger["body"])

path = base.GetPathFromLink(collection_link, "triggers")
collection_id = base.GetResourceIdOrFullNameFromLink(collection_link)
return collection_id, path, trigger

def _GetContainerIdWithPathForUDF(self, collection_link, udf): # pylint: disable=no-self-use
CosmosClientConnection.__ValidateResource(udf)
udf = udf.copy()
if udf.get("serverScript"):
udf["body"] = str(udf.pop("serverScript", ""))
elif udf.get("body"):
udf["body"] = str(udf["body"])

path = base.GetPathFromLink(collection_link, "udfs")
collection_id = base.GetResourceIdOrFullNameFromLink(collection_link)
return collection_id, path, udf

async def GetDatabaseAccount(self, url_connection=None, **kwargs):
"""Gets database account info.

@@ -365,6 +400,103 @@ async def CreateItem(self, database_or_container_link, document, options=None, *

return await self.Create(document, path, "docs", collection_id, None, options, **kwargs)

async def CreateUserDefinedFunction(self, collection_link, udf, options=None, **kwargs):
"""Creates a user-defined function in a collection.

:param str collection_link:
The link to the collection.
:param str udf:
:param dict options:
The request options for the request.

:return:
The created UDF.
:rtype:
dict

"""
if options is None:
options = {}

collection_id, path, udf = self._GetContainerIdWithPathForUDF(collection_link, udf)
return await self.Create(udf, path, "udfs", collection_id, None, options, **kwargs)

async def CreateTrigger(self, collection_link, trigger, options=None, **kwargs):
"""Creates a trigger in a collection.

:param str collection_link:
The link to the document collection.
:param dict trigger:
:param dict options:
The request options for the request.

:return:
The created Trigger.
:rtype:
dict

"""
if options is None:
options = {}

collection_id, path, trigger = self._GetContainerIdWithPathForTrigger(collection_link, trigger)
return await self.Create(trigger, path, "triggers", collection_id, None, options, **kwargs)

async def CreateStoredProcedure(self, collection_link, sproc, options=None, **kwargs):
"""Creates a stored procedure in a collection.

:param str collection_link:
The link to the document collection.
:param str sproc:
:param dict options:
The request options for the request.

:return:
The created Stored Procedure.
:rtype:
dict

"""
if options is None:
options = {}

collection_id, path, sproc = self._GetContainerIdWithPathForSproc(collection_link, sproc)
return await self.Create(sproc, path, "sprocs", collection_id, None, options, **kwargs)

async def ExecuteStoredProcedure(self, sproc_link, params, options=None, **kwargs):
"""Executes a store procedure.

:param str sproc_link:
The link to the stored procedure.
:param dict params:
List or None
:param dict options:
The request options for the request.

:return:
The Stored Procedure response.
:rtype:
dict

"""
if options is None:
options = {}

initial_headers = dict(self.default_headers)
initial_headers.update({http_constants.HttpHeaders.Accept: (runtime_constants.MediaTypes.Json)})

if params and not isinstance(params, list):
params = [params]

path = base.GetPathFromLink(sproc_link)
sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link)
headers = base.GetHeaders(self, initial_headers, "post", path, sproc_id, "sprocs", options)

# ExecuteStoredProcedure will use WriteEndpoint since it uses POST operation
request_params = _request_object.RequestObject("sprocs", documents._OperationType.ExecuteJavaScript)
result, self.last_response_headers = await self.__Post(path, request_params, params, headers, **kwargs)
return result

async def Create(self, body, path, typ, id, initial_headers, options=None, **kwargs): # pylint: disable=redefined-builtin
"""Creates a Azure Cosmos resource and returns it.

@@ -574,6 +706,69 @@ async def ReadItem(self, document_link, options=None, **kwargs):
document_id = base.GetResourceIdOrFullNameFromLink(document_link)
return await self.Read(path, "docs", document_id, None, options, **kwargs)

async def ReadUserDefinedFunction(self, udf_link, options=None, **kwargs):
"""Reads a user-defined function.

:param str udf_link:
The link to the user-defined function.
:param dict options:
The request options for the request.

:return:
The read UDF.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(udf_link)
udf_id = base.GetResourceIdOrFullNameFromLink(udf_link)
return await self.Read(path, "udfs", udf_id, None, options, **kwargs)

async def ReadStoredProcedure(self, sproc_link, options=None, **kwargs):
"""Reads a stored procedure.

:param str sproc_link:
The link to the stored procedure.
:param dict options:
The request options for the request.

:return:
The read Stored Procedure.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(sproc_link)
sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link)
return await self.Read(path, "sprocs", sproc_id, None, options, **kwargs)

async def ReadTrigger(self, trigger_link, options=None, **kwargs):
"""Reads a trigger.

:param str trigger_link:
The link to the trigger.
:param dict options:
The request options for the request.

:return:
The read Trigger.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(trigger_link)
trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link)
return await self.Read(path, "triggers", trigger_id, None, options, **kwargs)

async def ReadConflict(self, conflict_link, options=None, **kwargs):
"""Reads a conflict.

@@ -692,6 +887,64 @@ async def ReplaceContainer(self, collection_link, collection, options=None, **kw
collection_id = base.GetResourceIdOrFullNameFromLink(collection_link)
return await self.Replace(collection, path, "colls", collection_id, None, options, **kwargs)

async def ReplaceUserDefinedFunction(self, udf_link, udf, options=None, **kwargs):
"""Replaces a user-defined function and returns it.

:param str udf_link:
The link to the user-defined function.
:param dict udf:
:param dict options:
The request options for the request.

:return:
The new UDF.
:rtype:
dict

"""
if options is None:
options = {}

CosmosClientConnection.__ValidateResource(udf)
udf = udf.copy()
if udf.get("serverScript"):
udf["body"] = str(udf["serverScript"])
elif udf.get("body"):
udf["body"] = str(udf["body"])

path = base.GetPathFromLink(udf_link)
udf_id = base.GetResourceIdOrFullNameFromLink(udf_link)
return await self.Replace(udf, path, "udfs", udf_id, None, options, **kwargs)

async def ReplaceTrigger(self, trigger_link, trigger, options=None, **kwargs):
"""Replaces a trigger and returns it.

:param str trigger_link:
The link to the trigger.
:param dict trigger:
:param dict options:
The request options for the request.

:return:
The replaced Trigger.
:rtype:
dict

"""
if options is None:
options = {}

CosmosClientConnection.__ValidateResource(trigger)
trigger = trigger.copy()
if trigger.get("serverScript"):
trigger["body"] = str(trigger["serverScript"])
elif trigger.get("body"):
trigger["body"] = str(trigger["body"])

path = base.GetPathFromLink(trigger_link)
trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link)
return await self.Replace(trigger, path, "triggers", trigger_id, None, options, **kwargs)

async def ReplaceItem(self, document_link, new_document, options=None, **kwargs):
"""Replaces a document and returns it.

@@ -727,6 +980,36 @@ async def ReplaceItem(self, document_link, new_document, options=None, **kwargs)

return await self.Replace(new_document, path, "docs", document_id, None, options, **kwargs)


async def ReplaceStoredProcedure(self, sproc_link, sproc, options=None, **kwargs):
"""Replaces a stored procedure and returns it.

:param str sproc_link:
The link to the stored procedure.
:param dict sproc:
:param dict options:
The request options for the request.

:return:
The replaced Stored Procedure.
:rtype:
dict

"""
if options is None:
options = {}

CosmosClientConnection.__ValidateResource(sproc)
sproc = sproc.copy()
if sproc.get("serverScript"):
sproc["body"] = str(sproc["serverScript"])
elif sproc.get("body"):
sproc["body"] = str(sproc["body"])

path = base.GetPathFromLink(sproc_link)
sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link)
return await self.Replace(sproc, path, "sprocs", sproc_id, None, options, **kwargs)

async def Replace(self, resource, path, typ, id, initial_headers, options=None, **kwargs): # pylint: disable=redefined-builtin
"""Replaces a Azure Cosmos resource and returns it.

@@ -868,6 +1151,69 @@ async def DeleteItem(self, document_link, options=None, **kwargs):
document_id = base.GetResourceIdOrFullNameFromLink(document_link)
return await self.DeleteResource(path, "docs", document_id, None, options, **kwargs)

async def DeleteUserDefinedFunction(self, udf_link, options=None, **kwargs):
"""Deletes a user-defined function.

:param str udf_link:
The link to the user-defined function.
:param dict options:
The request options for the request.

:return:
The deleted UDF.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(udf_link)
udf_id = base.GetResourceIdOrFullNameFromLink(udf_link)
return await self.DeleteResource(path, "udfs", udf_id, None, options, **kwargs)

async def DeleteTrigger(self, trigger_link, options=None, **kwargs):
"""Deletes a trigger.

:param str trigger_link:
The link to the trigger.
:param dict options:
The request options for the request.

:return:
The deleted Trigger.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(trigger_link)
trigger_id = base.GetResourceIdOrFullNameFromLink(trigger_link)
return await self.DeleteResource(path, "triggers", trigger_id, None, options, **kwargs)

async def DeleteStoredProcedure(self, sproc_link, options=None, **kwargs):
"""Deletes a stored procedure.

:param str sproc_link:
The link to the stored procedure.
:param dict options:
The request options for the request.

:return:
The deleted Stored Procedure.
:rtype:
dict

"""
if options is None:
options = {}

path = base.GetPathFromLink(sproc_link)
sproc_id = base.GetResourceIdOrFullNameFromLink(sproc_link)
return await self.DeleteResource(path, "sprocs", sproc_id, None, options, **kwargs)

async def DeleteConflict(self, conflict_link, options=None, **kwargs):
"""Deletes a conflict.

Loading