Skip to content

Commit 22bd8ce

Browse files
toswedlu-zzsouthpolesteveannatisch
authored
Adding the ability to create a container with analytical storage turned on. (#12408)
* Adding the ability to createa container with analytical storage turned on * Updating the changelog * disabling analytical storage tests while running against emulator (for the time being) * fixing pylint issues * Update sdk/cosmos/azure-cosmos/CHANGELOG.md Co-authored-by: Steve Faulkner <[email protected]> * changing func param to kwargs param * removing whitespace that pylint doesn't like * commenting out analytical storage unit tests out until we have emulator support * noting in docstring that analytical storage can only be enabled on Synapse Link enabled accounts * just kicking the tires to get the build working Co-authored-by: Steve Faulkner <[email protected]> Co-authored-by: annatisch <[email protected]>
1 parent 3f154bb commit 22bd8ce

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
## 4.0.1 (Unreleased)
22

33
- Added deprecation warning for "lazy" indexing mode. The backend no longer allows creating containers with this mode and will set them to consistent instead.
4-
- Fix for bug where options headers were not added to upsert_item function. Issue #11791 - thank you @aalapatirvbd.
5-
- Fixed error raised when a non string ID is used in an item. It now raises TypeError rather than AttributeError. Issue #11793 - thank you @Rabbit994.
6-
- Fixed #12570 - Thanks @sl-sandy.
74

8-
** Bug fixes **
5+
**New features**
6+
- Added the ability to set the analytical storage TTL when creating a new container.
7+
8+
**Bug fixes**
99
- Fixed support for dicts as inputs for get_client APIs.
1010
- Fixed Python 2/3 compatibility in query iterators.
11+
- Fixed type hint error. Issue #12570 - Thanks @sl-sandy.
12+
- Fixed bug where options headers were not added to upsert_item function. Issue #11791 - thank you @aalapatirvbd.
13+
- Fixed error raised when a non string ID is used in an item. It now raises TypeError rather than AttributeError. Issue #11793 - thank you @Rabbit994.
1114

1215

1316
## 4.0.0 (2020-05-20)
@@ -247,4 +250,3 @@ Version 4.0.0b1 is the first preview of our efforts to create a user-friendly an
247250

248251
- Supports proxy connection
249252

250-

sdk/cosmos/azure-cosmos/azure/cosmos/database.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ def create_container(
177177
has changed, and act according to the condition specified by the `match_condition` parameter.
178178
:keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag.
179179
:keyword Callable response_hook: A callable invoked with the response metadata.
180+
:keyword analytical_storage_ttl: Analytical store time to live (TTL) for items in the container. A value of
181+
None leaves analytical storage off and a value of -1 turns analytical storage on with no TTL. Please
182+
note that analytical storage can only be enabled on Synapse Link enabled accounts.
180183
:returns: A `ContainerProxy` instance representing the new container.
181184
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container creation failed.
182185
:rtype: ~azure.cosmos.ContainerProxy
@@ -216,6 +219,10 @@ def create_container(
216219
if conflict_resolution_policy is not None:
217220
definition["conflictResolutionPolicy"] = conflict_resolution_policy
218221

222+
analytical_storage_ttl = kwargs.pop("analytical_storage_ttl", None)
223+
if analytical_storage_ttl is not None:
224+
definition["analyticalStorageTtl"] = analytical_storage_ttl
225+
219226
request_options = build_options(kwargs)
220227
response_hook = kwargs.pop('response_hook', None)
221228
if populate_query_metrics is not None:
@@ -266,11 +273,15 @@ def create_container_if_not_exists(
266273
has changed, and act according to the condition specified by the `match_condition` parameter.
267274
:keyword ~azure.core.MatchConditions match_condition: The match condition to use upon the etag.
268275
:keyword Callable response_hook: A callable invoked with the response metadata.
276+
:keyword analytical_storage_ttl: Analytical store time to live (TTL) for items in the container. A value of
277+
None leaves analytical storage off and a value of -1 turns analytical storage on with no TTL. Please
278+
note that analytical storage can only be enabled on Synapse Link enabled accounts.
269279
:returns: A `ContainerProxy` instance representing the container.
270280
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The container read or creation failed.
271281
:rtype: ~azure.cosmos.ContainerProxy
272282
"""
273283

284+
analytical_storage_ttl = kwargs.pop("analytical_storage_ttl", None)
274285
try:
275286
container_proxy = self.get_container_client(id)
276287
container_proxy.read(
@@ -287,7 +298,8 @@ def create_container_if_not_exists(
287298
populate_query_metrics=populate_query_metrics,
288299
offer_throughput=offer_throughput,
289300
unique_key_policy=unique_key_policy,
290-
conflict_resolution_policy=conflict_resolution_policy
301+
conflict_resolution_policy=conflict_resolution_policy,
302+
analytical_storage_ttl=analytical_storage_ttl
291303
)
292304

293305
@distributed_trace

sdk/cosmos/azure-cosmos/test/test_crud.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,71 @@ def test_get_resource_with_dictionary_and_object(self):
26052605
read_permission = created_user.get_permission(created_permission.properties)
26062606
self.assertEqual(read_permission.id, created_permission.id)
26072607

2608+
# Temporarily commenting analytical storage tests until emulator support comes.
2609+
# def test_create_container_with_analytical_store_off(self):
2610+
# # don't run test, for the time being, if running against the emulator
2611+
# if 'localhost' in self.host or '127.0.0.1' in self.host:
2612+
# return
2613+
2614+
# created_db = self.databaseForTest
2615+
# collection_id = 'test_create_container_with_analytical_store_off_' + str(uuid.uuid4())
2616+
# collection_indexing_policy = {'indexingMode': 'consistent'}
2617+
# created_recorder = RecordDiagnostics()
2618+
# created_collection = created_db.create_container(id=collection_id,
2619+
# indexing_policy=collection_indexing_policy,
2620+
# partition_key=PartitionKey(path="/pk", kind="Hash"),
2621+
# response_hook=created_recorder)
2622+
# properties = created_collection.read()
2623+
# ttl_key = "analyticalStorageTtl"
2624+
# self.assertTrue(ttl_key not in properties or properties[ttl_key] == None)
2625+
2626+
# def test_create_container_with_analytical_store_on(self):
2627+
# # don't run test, for the time being, if running against the emulator
2628+
# if 'localhost' in self.host or '127.0.0.1' in self.host:
2629+
# return
2630+
2631+
# created_db = self.databaseForTest
2632+
# collection_id = 'test_create_container_with_analytical_store_on_' + str(uuid.uuid4())
2633+
# collection_indexing_policy = {'indexingMode': 'consistent'}
2634+
# created_recorder = RecordDiagnostics()
2635+
# created_collection = created_db.create_container(id=collection_id,
2636+
# analytical_storage_ttl=-1,
2637+
# indexing_policy=collection_indexing_policy,
2638+
# partition_key=PartitionKey(path="/pk", kind="Hash"),
2639+
# response_hook=created_recorder)
2640+
# properties = created_collection.read()
2641+
# ttl_key = "analyticalStorageTtl"
2642+
# self.assertTrue(ttl_key in properties and properties[ttl_key] == -1)
2643+
2644+
# def test_create_container_if_not_exists_with_analytical_store_on(self):
2645+
# # don't run test, for the time being, if running against the emulator
2646+
# if 'localhost' in self.host or '127.0.0.1' in self.host:
2647+
# return
2648+
2649+
# # first, try when we know the container doesn't exist.
2650+
# created_db = self.databaseForTest
2651+
# collection_id = 'test_create_container_if_not_exists_with_analytical_store_on_' + str(uuid.uuid4())
2652+
# collection_indexing_policy = {'indexingMode': 'consistent'}
2653+
# created_recorder = RecordDiagnostics()
2654+
# created_collection = created_db.create_container_if_not_exists(id=collection_id,
2655+
# analytical_storage_ttl=-1,
2656+
# indexing_policy=collection_indexing_policy,
2657+
# partition_key=PartitionKey(path="/pk", kind="Hash"),
2658+
# response_hook=created_recorder)
2659+
# properties = created_collection.read()
2660+
# ttl_key = "analyticalStorageTtl"
2661+
# self.assertTrue(ttl_key in properties and properties[ttl_key] == -1)
2662+
2663+
# # next, try when we know the container DOES exist. This way both code paths are tested.
2664+
# created_collection = created_db.create_container_if_not_exists(id=collection_id,
2665+
# analytical_storage_ttl=-1,
2666+
# indexing_policy=collection_indexing_policy,
2667+
# partition_key=PartitionKey(path="/pk", kind="Hash"),
2668+
# response_hook=created_recorder)
2669+
# properties = created_collection.read()
2670+
# ttl_key = "analyticalStorageTtl"
2671+
# self.assertTrue(ttl_key in properties and properties[ttl_key] == -1)
2672+
26082673
def _MockExecuteFunction(self, function, *args, **kwargs):
26092674
self.last_headers.append(args[4].headers[HttpHeaders.PartitionKey]
26102675
if HttpHeaders.PartitionKey in args[4].headers else '')

0 commit comments

Comments
 (0)