Skip to content

Commit cb3227a

Browse files
authored
Add merge support (#42924)
* Add merge support * Updated CHANGELOG.md * Move header tests to `test_headers.py` * Add Partition Merge header's async test
1 parent 1e53ab7 commit cb3227a

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This version and all future versions will require Python 3.9+.
2828
#### Features Added
2929
* Added read_items API to provide an efficient method for retrieving multiple items in a single request. See [PR 42167](https://github.com/Azure/azure-sdk-for-python/pull/42167).
3030
* Added ability to replace a container's indexing policy if a vector embedding policy was present. See [PR 42810](https://github.com/Azure/azure-sdk-for-python/pull/42810).
31+
* Added merge support. See [PR 42924](https://github.com/Azure/azure-sdk-for-python/pull/42924).
3132

3233
#### Bugs Fixed
3334
* Improved the resilience of Database Account Read metadata operation against short-lived network issues by increasing number of retries. See [PR 42525](https://github.com/Azure/azure-sdk-for-python/pull/42525).

sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
147147
headers = dict(default_headers)
148148
options = options or {}
149149

150+
# SDK supported capabilities header for partition merge support
151+
headers[http_constants.HttpHeaders.SDKSupportedCapabilities] = \
152+
http_constants.SDKSupportedCapabilities.PARTITION_MERGE
153+
150154
# Generate a new activity ID for each request client side.
151155
headers[http_constants.HttpHeaders.ActivityId] = GenerateGuidId()
152156
if cosmos_client_connection.UseMultipleWriteLocations:

sdk/cosmos/azure-cosmos/azure/cosmos/http_constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ class _ErrorCodes:
373373
# Linux Error Codes
374374
LinuxConnectionReset = 131
375375

376+
class SDKSupportedCapabilities:
377+
"""Constants of SDK supported capabilities.
378+
"""
379+
NONE = '0'
380+
PARTITION_MERGE = '1'
376381

377382
class StatusCodes:
378383
"""HTTP status codes returned by the REST operations

sdk/cosmos/azure-cosmos/tests/test_headers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def request_raw_response_hook(response):
2323
assert (response.http_request.headers[http_constants.HttpHeaders.ThroughputBucket]
2424
== str(request_throughput_bucket_number))
2525

26+
def partition_merge_support_response_hook(raw_response):
27+
header = raw_response.http_request.headers
28+
assert http_constants.HttpHeaders.SDKSupportedCapabilities in header
29+
assert header[http_constants.HttpHeaders.SDKSupportedCapabilities] == \
30+
http_constants.SDKSupportedCapabilities.PARTITION_MERGE
31+
2632
@pytest.mark.cosmosEmulator
2733
class TestHeaders(unittest.TestCase):
2834
database: DatabaseProxy = None
@@ -279,5 +285,10 @@ def test_container_read_item_negative_throughput_bucket(self):
279285
280286
"""
281287

288+
def test_partition_merge_support_header(self):
289+
# This test only runs read API to verify if the header was set correctly, because all APIs are using the same
290+
# base method to set the header(GetHeaders).
291+
self.container.read(raw_response_hook=partition_merge_support_response_hook)
292+
282293
if __name__ == "__main__":
283294
unittest.main()

sdk/cosmos/azure-cosmos/tests/test_headers_async.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from azure.cosmos import http_constants
1313
from azure.cosmos.aio import CosmosClient, _retry_utility_async, DatabaseProxy
1414
from azure.cosmos.partition_key import PartitionKey
15+
from test_headers import partition_merge_support_response_hook
1516

1617
client_throughput_bucket_number = 2
1718
request_throughput_bucket_number = 3
@@ -230,6 +231,10 @@ async def test_client_id(self):
230231
finally:
231232
cosmos_client_connection._CosmosClientConnection__Get = original_connection_get
232233

234+
async def test_partition_merge_support_header(self):
235+
# This test only runs read API to verify if the header was set correctly, because all APIs are using the same
236+
# base method to set the header(GetHeaders).
237+
await self.container.read(raw_response_hook=partition_merge_support_response_hook)
233238

234239
if __name__ == "__main__":
235240
unittest.main()

0 commit comments

Comments
 (0)