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

Adding the ability to create a container with analytical storage turned on. #12408

Merged
merged 13 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added deprecation warning for "lazy" indexing mode. The backend no longer allows creating containers with this mode and will set them to consistent instead.
- Fix for bug where options headers were not added to upsert_item function. Issue #11791 - thank you @aalapatirvbd.
- 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.
- Added the ability to set the analytical storage TTL we creating a new container.
toswedlu-zz marked this conversation as resolved.
Show resolved Hide resolved

** Bug fixes **
- Fixed support for dicts as inputs for get_client APIs.
Expand Down
11 changes: 10 additions & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def create_container(
offer_throughput=None, # type: Optional[int]
unique_key_policy=None, # type: Optional[Dict[str, Any]]
conflict_resolution_policy=None, # type: Optional[Dict[str, Any]]
analytical_storage_ttl=None, # type: Optional[int]
**kwargs # type: Any
):
# type: (...) -> ContainerProxy
Expand All @@ -171,6 +172,8 @@ def create_container(
:param offer_throughput: The provisioned throughput for this offer.
:param unique_key_policy: The unique key policy to apply to the container.
:param conflict_resolution_policy: The conflict resolution policy to apply to the container.
:param analytical_storage_ttl: Analytical store time to live (TTL) for items in the container. A value of
None leaves analytical storage off and a value of -1 turns analytical storage on with no TTL.
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
Expand Down Expand Up @@ -215,6 +218,8 @@ def create_container(
definition["uniqueKeyPolicy"] = unique_key_policy
if conflict_resolution_policy is not None:
definition["conflictResolutionPolicy"] = conflict_resolution_policy
if analytical_storage_ttl is not None:
definition["analyticalStorageTtl"] = analytical_storage_ttl

request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand Down Expand Up @@ -243,6 +248,7 @@ def create_container_if_not_exists(
offer_throughput=None, # type: Optional[int]
unique_key_policy=None, # type: Optional[Dict[str, Any]]
conflict_resolution_policy=None, # type: Optional[Dict[str, Any]]
analytical_storage_ttl=None, # type: Optional[int]
**kwargs # type: Any
):
# type: (...) -> ContainerProxy
Expand All @@ -260,6 +266,8 @@ def create_container_if_not_exists(
:param offer_throughput: The provisioned throughput for this offer.
:param unique_key_policy: The unique key policy to apply to the container.
:param conflict_resolution_policy: The conflict resolution policy to apply to the container.
:param analytical_storage_ttl: Analytical store time to live (TTL) for items in the container. A value of
None leaves analytical storage off and a value of -1 turns analytical storage on with no TTL.
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str,str] initial_headers: Initial headers to be sent as part of the request.
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
Expand Down Expand Up @@ -287,7 +295,8 @@ def create_container_if_not_exists(
populate_query_metrics=populate_query_metrics,
offer_throughput=offer_throughput,
unique_key_policy=unique_key_policy,
conflict_resolution_policy=conflict_resolution_policy
conflict_resolution_policy=conflict_resolution_policy,
analytical_storage_ttl=analytical_storage_ttl,
)

@distributed_trace
Expand Down
35 changes: 35 additions & 0 deletions sdk/cosmos/azure-cosmos/test/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,41 @@ def test_get_resource_with_dictionary_and_object(self):
read_permission = created_user.get_permission(created_permission.properties)
self.assertEqual(read_permission.id, created_permission.id)

def test_create_container_with_analytical_store_off(self):
# don't run test, for the time being, if running against the emulator
if 'localhost' in self.host or '127.0.0.1' in self.host:
return

created_db = self.databaseForTest
collection_id = 'test_create_container_with_analytical_store_off_' + str(uuid.uuid4())
collection_indexing_policy = {'indexingMode': 'consistent'}
created_recorder = RecordDiagnostics()
created_collection = created_db.create_container(id=collection_id,
indexing_policy=collection_indexing_policy,
partition_key=PartitionKey(path="/pk", kind="Hash"),
response_hook=created_recorder)
properties = created_collection.read()
ttl_key = "analyticalStorageTtl"
self.assertTrue(ttl_key not in properties or properties[ttl_key] == None)

def test_create_container_with_analytical_store_on(self):
# don't run test, for the time being, if running against the emulator
if 'localhost' in self.host or '127.0.0.1' in self.host:
return

created_db = self.databaseForTest
collection_id = 'test_create_container_with_analytical_store_on_' + str(uuid.uuid4())
collection_indexing_policy = {'indexingMode': 'consistent'}
created_recorder = RecordDiagnostics()
created_collection = created_db.create_container(id=collection_id,
analytical_storage_ttl=-1,
indexing_policy=collection_indexing_policy,
partition_key=PartitionKey(path="/pk", kind="Hash"),
response_hook=created_recorder)
properties = created_collection.read()
ttl_key = "analyticalStorageTtl"
self.assertTrue(ttl_key in properties and properties[ttl_key] == -1)

def _MockExecuteFunction(self, function, *args, **kwargs):
self.last_headers.append(args[4].headers[HttpHeaders.PartitionKey]
if HttpHeaders.PartitionKey in args[4].headers else '')
Expand Down