Skip to content

Commit 173a676

Browse files
author
Andrew Mathew
committed
merging
2 parents 7656cf2 + 419e374 commit 173a676

12 files changed

+690
-0
lines changed

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
'priority': 'priorityLevel',
6464
'no_response': 'responsePayloadOnWriteDisabled',
6565
'max_item_count': 'maxItemCount',
66+
'throughput_bucket': 'throughputBucket'
6667
}
6768

6869
# Cosmos resource ID validation regex breakdown:
@@ -316,6 +317,9 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
316317
if options.get("correlatedActivityId"):
317318
headers[http_constants.HttpHeaders.CorrelatedActivityId] = options["correlatedActivityId"]
318319

320+
if options.get("throughputBucket"):
321+
headers[http_constants.HttpHeaders.ThroughputBucket] = options["throughputBucket"]
322+
319323
if resource_type == "docs" and verb != "get":
320324
if "responsePayloadOnWriteDisabled" in options:
321325
responsePayloadOnWriteDisabled = options["responsePayloadOnWriteDisabled"]

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def __init__( # pylint: disable=too-many-statements
160160
http_constants.HttpHeaders.IsContinuationExpected: False,
161161
}
162162

163+
throughput_bucket = kwargs.pop('throughput_bucket', None)
164+
if throughput_bucket:
165+
self.default_headers[http_constants.HttpHeaders.ThroughputBucket] = throughput_bucket
166+
163167
# Keeps the latest response headers from the server.
164168
self.last_response_headers: CaseInsensitiveDict = CaseInsensitiveDict()
165169

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py

+44
Large diffs are not rendered by default.

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client.py

+21
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class CosmosClient: # pylint: disable=client-accepts-api-version-keyword
167167
level (to log all requests) or at a single request level. Requests will be logged at INFO level.
168168
:keyword bool no_response_on_write: Indicates whether service should be instructed to skip sending
169169
response payloads for write operations on items by default unless specified differently per operation.
170+
:keyword int throughput_bucket: The desired throughput bucket for the client
170171
171172
.. admonition:: Example:
172173
@@ -254,6 +255,7 @@ async def create_database(
254255
initial_headers: Optional[Dict[str, str]] = None,
255256
etag: Optional[str] = None,
256257
match_condition: Optional[MatchConditions] = None,
258+
throughput_bucket: Optional[int] = None,
257259
**kwargs: Any
258260
) -> DatabaseProxy:
259261
"""
@@ -269,6 +271,7 @@ async def create_database(
269271
:keyword match_condition: The match condition to use upon the etag.
270272
:paramtype match_condition: ~azure.core.MatchConditions
271273
:keyword response_hook: A callable invoked with the response metadata.
274+
:keyword int throughput_bucket: The desired throughput bucket for the client
272275
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], None]
273276
:raises ~azure.cosmos.exceptions.CosmosResourceExistsError: Database with the given ID already exists.
274277
:returns: A DatabaseProxy instance representing the new database.
@@ -292,6 +295,8 @@ async def create_database(
292295
kwargs["etag"] = etag
293296
if match_condition is not None:
294297
kwargs["match_condition"] = match_condition
298+
if throughput_bucket is not None:
299+
kwargs["throughput_bucket"] = throughput_bucket
295300
request_options = _build_options(kwargs)
296301
_set_throughput_options(offer=offer_throughput, request_options=request_options)
297302

@@ -308,6 +313,7 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
308313
initial_headers: Optional[Dict[str, str]] = None,
309314
etag: Optional[str] = None,
310315
match_condition: Optional[MatchConditions] = None,
316+
throughput_bucket: Optional[int] = None,
311317
**kwargs: Any
312318
) -> DatabaseProxy:
313319
"""
@@ -329,6 +335,7 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
329335
:keyword match_condition: The match condition to use upon the etag.
330336
:paramtype match_condition: ~azure.core.MatchConditions
331337
:keyword response_hook: A callable invoked with the response metadata.
338+
:keyword int throughput_bucket: The desired throughput bucket for the client
332339
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], None]
333340
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The database read or creation failed.
334341
:returns: A DatabaseProxy instance representing the database.
@@ -342,6 +349,8 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
342349
kwargs["etag"] = etag
343350
if match_condition is not None:
344351
kwargs["match_condition"] = match_condition
352+
if throughput_bucket is not None:
353+
kwargs["throughput_bucket"] = throughput_bucket
345354
try:
346355
database_proxy = self.get_database_client(id)
347356
await database_proxy.read(**kwargs)
@@ -378,6 +387,7 @@ def list_databases(
378387
session_token: Optional[str] = None,
379388
initial_headers: Optional[Dict[str, str]] = None,
380389
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
390+
throughput_bucket: Optional[int] = None,
381391
**kwargs: Any
382392
) -> AsyncItemPaged[Dict[str, Any]]:
383393
"""List the databases in a Cosmos DB SQL database account.
@@ -386,6 +396,7 @@ def list_databases(
386396
:keyword str session_token: Token for use with Session consistency.
387397
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
388398
:keyword response_hook: A callable invoked with the response metadata.
399+
:keyword int throughput_bucket: The desired throughput bucket for the client
389400
:paramtype response_hook: Callable[[Mapping[str, Any]], None]
390401
:returns: An AsyncItemPaged of database properties (dicts).
391402
:rtype: AsyncItemPaged[Dict[str, str]]
@@ -394,6 +405,8 @@ def list_databases(
394405
kwargs["session_token"] = session_token
395406
if initial_headers is not None:
396407
kwargs["initial_headers"] = initial_headers
408+
if throughput_bucket is not None:
409+
kwargs["throughput_bucket"] = throughput_bucket
397410
feed_options = _build_options(kwargs)
398411
if max_item_count is not None:
399412
feed_options["maxItemCount"] = max_item_count
@@ -413,6 +426,7 @@ def query_databases(
413426
session_token: Optional[str] = None,
414427
initial_headers: Optional[Dict[str, str]] = None,
415428
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
429+
throughput_bucket: Optional[int] = None,
416430
**kwargs: Any
417431
) -> AsyncItemPaged[Dict[str, Any]]:
418432
"""Query the databases in a Cosmos DB SQL database account.
@@ -425,6 +439,7 @@ def query_databases(
425439
:keyword str session_token: Token for use with Session consistency.
426440
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
427441
:keyword response_hook: A callable invoked with the response metadata.
442+
:keyword int throughput_bucket: The desired throughput bucket for the client
428443
:paramtype response_hook: Callable[[Mapping[str, Any]], None]
429444
:returns: An AsyncItemPaged of database properties (dicts).
430445
:rtype: AsyncItemPaged[Dict[str, str]]
@@ -433,6 +448,8 @@ def query_databases(
433448
kwargs["session_token"] = session_token
434449
if initial_headers is not None:
435450
kwargs["initial_headers"] = initial_headers
451+
if throughput_bucket is not None:
452+
kwargs['throughput_bucket'] = throughput_bucket
436453
feed_options = _build_options(kwargs)
437454
if max_item_count is not None:
438455
feed_options["maxItemCount"] = max_item_count
@@ -455,6 +472,7 @@ async def delete_database(
455472
etag: Optional[str] = None,
456473
match_condition: Optional[MatchConditions] = None,
457474
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
475+
throughput_bucket: Optional[int] = None,
458476
**kwargs: Any
459477
) -> None:
460478
"""Delete the database with the given ID (name).
@@ -469,6 +487,7 @@ async def delete_database(
469487
:keyword match_condition: The match condition to use upon the etag.
470488
:paramtype match_condition: ~azure.core.MatchConditions
471489
:keyword response_hook: A callable invoked with the response metadata.
490+
:keyword int throughput_bucket: The desired throughput bucket for the client
472491
:paramtype response_hook: Callable[[Mapping[str, Any]], None]
473492
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the database couldn't be deleted.
474493
:rtype: None
@@ -481,6 +500,8 @@ async def delete_database(
481500
kwargs["etag"] = etag
482501
if match_condition is not None:
483502
kwargs["match_condition"] = match_condition
503+
if throughput_bucket is not None:
504+
kwargs['throughput_bucket'] = throughput_bucket
484505
request_options = _build_options(kwargs)
485506

486507
database_link = _get_database_link(database)

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def __init__( # pylint: disable=too-many-statements
163163
http_constants.HttpHeaders.IsContinuationExpected: False,
164164
}
165165

166+
throughput_bucket = kwargs.pop('throughput_bucket', None)
167+
if throughput_bucket:
168+
self.default_headers[http_constants.HttpHeaders.ThroughputBucket] = throughput_bucket
169+
166170
if consistency_level is not None:
167171
self.default_headers[http_constants.HttpHeaders.ConsistencyLevel] = consistency_level
168172

Diff for: sdk/cosmos/azure-cosmos/azure/cosmos/aio/_database.py

+27
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ async def read(
133133
*,
134134
session_token: Optional[str] = None,
135135
initial_headers: Optional[Dict[str, str]] = None,
136+
throughput_bucket: Optional[int] = None,
136137
**kwargs: Any
137138
) -> Dict[str, Any]:
138139
"""Read the database properties.
139140
140141
:keyword str session_token: Token for use with Session consistency.
141142
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
142143
:keyword response_hook: A callable invoked with the response metadata.
144+
:keyword int throughput_bucket: The desired throughput bucket for the client
143145
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], None]
144146
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given database couldn't be retrieved.
145147
:returns: A dict representing the database properties
@@ -150,6 +152,8 @@ async def read(
150152
kwargs['session_token'] = session_token
151153
if initial_headers is not None:
152154
kwargs['initial_headers'] = initial_headers
155+
if throughput_bucket is not None:
156+
kwargs["throughput_bucket"] = throughput_bucket
153157
request_options = _build_options(kwargs)
154158

155159
self._properties = await self.client_connection.ReadDatabase(
@@ -178,6 +182,7 @@ async def create_container(
178182
vector_embedding_policy: Optional[Dict[str, Any]] = None,
179183
change_feed_policy: Optional[Dict[str, Any]] = None,
180184
full_text_policy: Optional[Dict[str, Any]] = None,
185+
throughput_bucket: Optional[int] = None,
181186
**kwargs: Any
182187
) -> ContainerProxy:
183188
"""Create a new container with the given ID (name).
@@ -216,6 +221,7 @@ async def create_container(
216221
:keyword Dict[str, Any] full_text_policy: **provisional** The full text policy for the container.
217222
Used to denote the default language to be used for all full text indexes, or to individually
218223
assign a language to each full text index path.
224+
:keyword int throughput_bucket: The desired throughput bucket for the client
219225
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed.
220226
:returns: A `ContainerProxy` instance representing the new container.
221227
:rtype: ~azure.cosmos.aio.ContainerProxy
@@ -273,6 +279,8 @@ async def create_container(
273279
kwargs['etag'] = etag
274280
if match_condition is not None:
275281
kwargs['match_condition'] = match_condition
282+
if throughput_bucket is not None:
283+
kwargs['throughput_bucket'] = throughput_bucket
276284
request_options = _build_options(kwargs)
277285
_set_throughput_options(offer=offer_throughput, request_options=request_options)
278286

@@ -301,6 +309,7 @@ async def create_container_if_not_exists(
301309
vector_embedding_policy: Optional[Dict[str, Any]] = None,
302310
change_feed_policy: Optional[Dict[str, Any]] = None,
303311
full_text_policy: Optional[Dict[str, Any]] = None,
312+
throughput_bucket: Optional[int] = None,
304313
**kwargs: Any
305314
) -> ContainerProxy:
306315
"""Create a container if it does not exist already.
@@ -341,6 +350,7 @@ async def create_container_if_not_exists(
341350
:keyword Dict[str, Any] full_text_policy: **provisional** The full text policy for the container.
342351
Used to denote the default language to be used for all full text indexes, or to individually
343352
assign a language to each full text index path.
353+
:keyword int throughput_bucket: The desired throughput bucket for the client
344354
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed.
345355
:returns: A `ContainerProxy` instance representing the new container.
346356
:rtype: ~azure.cosmos.aio.ContainerProxy
@@ -371,6 +381,7 @@ async def create_container_if_not_exists(
371381
vector_embedding_policy=vector_embedding_policy,
372382
change_feed_policy=change_feed_policy,
373383
full_text_policy=full_text_policy,
384+
throughput_bucket=throughput_bucket,
374385
**kwargs
375386
)
376387

@@ -409,6 +420,7 @@ def list_containers(
409420
max_item_count: Optional[int] = None,
410421
initial_headers: Optional[Dict[str, str]] = None,
411422
response_hook: Optional[Callable[[Mapping[str, Any], AsyncItemPaged[Dict[str, Any]]], None]] = None,
423+
throughput_bucket: Optional[int] = None,
412424
**kwargs
413425
) -> AsyncItemPaged[Dict[str, Any]]:
414426
"""List the containers in the database.
@@ -417,6 +429,7 @@ def list_containers(
417429
:keyword str session_token: Token for use with Session consistency.
418430
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
419431
:keyword response_hook: A callable invoked with the response metadata.
432+
:keyword int throughput_bucket: The desired throughput bucket for the client
420433
:paramtype response_hook: Callable[[Mapping[str, Any], AsyncItemPaged[Dict[str, Any]]], None]
421434
:returns: An AsyncItemPaged of container properties (dicts).
422435
:rtype: AsyncItemPaged[Dict[str, Any]]
@@ -435,6 +448,8 @@ def list_containers(
435448
kwargs['session_token'] = session_token
436449
if initial_headers is not None:
437450
kwargs['initial_headers'] = initial_headers
451+
if throughput_bucket is not None:
452+
kwargs["throughput_bucket"] = throughput_bucket
438453
feed_options = _build_options(kwargs)
439454
if max_item_count is not None:
440455
feed_options["maxItemCount"] = max_item_count
@@ -456,6 +471,7 @@ def query_containers(
456471
max_item_count: Optional[int] = None,
457472
initial_headers: Optional[Dict[str, str]] = None,
458473
response_hook: Optional[Callable[[Mapping[str, Any], AsyncItemPaged[Dict[str, Any]]], None]] = None,
474+
throughput_bucket: Optional[int] = None,
459475
**kwargs: Any
460476
) -> AsyncItemPaged[Dict[str, Any]]:
461477
"""List the properties for containers in the current database.
@@ -468,6 +484,7 @@ def query_containers(
468484
:keyword str session_token: Token for use with Session consistency.
469485
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
470486
:keyword response_hook: A callable invoked with the response metadata.
487+
:keyword int throughput_bucket: The desired throughput bucket for the client
471488
:paramtype response_hook: Callable[[Mapping[str, Any], AsyncItemPaged[Dict[str, Any]]], None]
472489
:returns: An AsyncItemPaged of container properties (dicts).
473490
:rtype: AsyncItemPaged[Dict[str, Any]]
@@ -476,6 +493,8 @@ def query_containers(
476493
kwargs['session_token'] = session_token
477494
if initial_headers is not None:
478495
kwargs['initial_headers'] = initial_headers
496+
if throughput_bucket is not None:
497+
kwargs["throughput_bucket"] = throughput_bucket
479498
feed_options = _build_options(kwargs)
480499
if max_item_count is not None:
481500
feed_options["maxItemCount"] = max_item_count
@@ -506,6 +525,7 @@ async def replace_container(
506525
analytical_storage_ttl: Optional[int] = None,
507526
computed_properties: Optional[List[Dict[str, str]]] = None,
508527
full_text_policy: Optional[Dict[str, Any]] = None,
528+
throughput_bucket: Optional[int] = None,
509529
**kwargs: Any
510530
) -> ContainerProxy:
511531
"""Reset the properties of the container.
@@ -539,6 +559,7 @@ async def replace_container(
539559
:keyword Dict[str, Any] full_text_policy: **provisional** The full text policy for the container.
540560
Used to denote the default language to be used for all full text indexes, or to individually
541561
assign a language to each full text index path.
562+
:keyword int throughput_bucket: The desired throughput bucket for the client
542563
:returns: A `ContainerProxy` instance representing the container after replace completed.
543564
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: Raised if the container couldn't be replaced.
544565
This includes if the container with given id does not exist.
@@ -562,6 +583,8 @@ async def replace_container(
562583
kwargs['etag'] = etag
563584
if match_condition is not None:
564585
kwargs['match_condition'] = match_condition
586+
if throughput_bucket is not None:
587+
kwargs['throughput_bucket'] = throughput_bucket
565588
request_options = _build_options(kwargs)
566589

567590
container_id = self._get_container_id(container)
@@ -597,6 +620,7 @@ async def delete_container(
597620
initial_headers: Optional[Dict[str, str]] = None,
598621
etag: Optional[str] = None,
599622
match_condition: Optional[MatchConditions] = None,
623+
throughput_bucket: Optional[int] = None,
600624
**kwargs: Any
601625
) -> None:
602626
"""Delete a container.
@@ -612,6 +636,7 @@ async def delete_container(
612636
:keyword match_condition: The match condition to use upon the etag.
613637
:paramtype match_condition: ~azure.core.MatchConditions
614638
:keyword response_hook: A callable invoked with the response metadata.
639+
:keyword int throughput_bucket: The desired throughput bucket for the client
615640
:paramtype response_hook: Callable[[Dict[str, str], None], None]
616641
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the container couldn't be deleted.
617642
:rtype: None
@@ -624,6 +649,8 @@ async def delete_container(
624649
kwargs['etag'] = etag
625650
if match_condition is not None:
626651
kwargs['match_condition'] = match_condition
652+
if throughput_bucket is not None:
653+
kwargs['throughput_bucket'] = throughput_bucket
627654
request_options = _build_options(kwargs)
628655

629656
collection_link = self._get_container_link(container)

0 commit comments

Comments
 (0)