Skip to content

Commit a7d06a3

Browse files
authored
{Cosmos] README file improvements: Analytical store, limitations, workarounds. (#13188)
1 parent 494ce5a commit a7d06a3

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

sdk/cosmos/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Use the Azure Cosmos DB SQL API SDKs for application development and database ma
66

77
## Contents of this folder
88

9-
### azure-cosmos
9+
### [azure-cosmos](./azure-cosmos)
1010

1111
This is the Azure Cosmos DB SQL API SDK for Python to manage databases and the JSON documents they contain in this NoSQL database service. High level capabilities are:
1212

@@ -17,7 +17,7 @@ This is the Azure Cosmos DB SQL API SDK for Python to manage databases and the J
1717

1818
Use this package if you are creating an application or exploring data.
1919

20-
### azure-mgmt-cosmosdb
20+
### [azure-mgmt-cosmosdb](./azure-mgmt-cosmosdb)
2121

2222
This is the Microsoft Azure Cosmos DB Management Client Library. High level capabilities are:
2323

@@ -34,7 +34,7 @@ This is the Microsoft Azure Cosmos DB Management Client Library. High level capa
3434

3535
Use this package if you are creating an account level management application.
3636

37-
### azure-mgmt-documentdb
37+
### [azure-mgmt-documentdb](./azure-mgmt-documentdb)
3838

3939
Legacy DocumentDB SDK.
4040

sdk/cosmos/azure-cosmos/README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ Use the Azure Cosmos DB SQL API SDK for Python to manage databases and the JSON
1111

1212
[SDK source code][source_code] | [Package (PyPI)][cosmos_pypi] | [API reference documentation][ref_cosmos_sdk] | [Product documentation][cosmos_docs] | [Samples][cosmos_samples]
1313

14+
> This SDK is used for the [SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-getting-started). For all other APIs, please check the [Azure Cosmos DB documentation](https://docs.microsoft.com/en-us/azure/cosmos-db/introduction) to evaluate the best SDK for your project.
1415
1516
## Getting started
17+
1618
### Prerequisites
19+
1720
* Azure subscription - [Create a free account][azure_sub]
1821
* Azure [Cosmos DB account][cosmos_account] - SQL API
1922
* [Python 2.7 or 3.5.3+][python]
2023

21-
2224
If you need a Cosmos DB SQL API account, you can create one with this [Azure CLI][azure_cli] command:
2325

2426
```Bash
@@ -39,6 +41,7 @@ Although not required, you can keep your base system and Azure SDK environments
3941
python3 -m venv azure-cosmosdb-sdk-environment
4042
source azure-cosmosdb-sdk-environment/bin/activate
4143
```
44+
4245
### Authenticate the client
4346

4447
Interaction with Cosmos DB starts with an instance of the [CosmosClient][ref_cosmosclient] class. You need an **account**, its **URI**, and one of its **account keys** to instantiate the client object.
@@ -52,6 +55,7 @@ ACCT_NAME=<cosmos-db-account-name>
5255
export ACCOUNT_URI=$(az cosmosdb show --resource-group $RES_GROUP --name $ACCT_NAME --query documentEndpoint --output tsv)
5356
export ACCOUNT_KEY=$(az cosmosdb list-keys --resource-group $RES_GROUP --name $ACCT_NAME --query primaryMasterKey --output tsv)
5457
```
58+
5559
### Create the client
5660

5761
Once you've populated the `ACCOUNT_URI` and `ACCOUNT_KEY` environment variables, you can create the [CosmosClient][ref_cosmosclient].
@@ -77,12 +81,26 @@ Once you've initialized a [CosmosClient][ref_cosmosclient], you can interact wit
7781

7882
For more information about these resources, see [Working with Azure Cosmos databases, containers and items][cosmos_resources].
7983

84+
## Limitations
85+
86+
As of August 2020 the features below are not yet supported.
87+
88+
* Bulk/Batch processing
89+
* Group By queries
90+
* Direct TCP Mode access
91+
* Language Native async i/o
92+
93+
## Limitations Workaround
94+
95+
If you want to use Python SDK to perform bulk inserts to Cosmos DB, the best alternative is to use [stored procedures](https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs) to write multiple items with the same partition key.
96+
8097
## Examples
8198

8299
The following sections provide several code snippets covering some of the most common Cosmos DB tasks, including:
83100

84101
* [Create a database](#create-a-database "Create a database")
85102
* [Create a container](#create-a-container "Create a container")
103+
* [Create an Analytical Store Enabled container](#create-an-analytical-store-enabled-container "Create a container")
86104
* [Get an existing container](#get-an-existing-container "Get an existing container")
87105
* [Insert data](#insert-data "Insert data")
88106
* [Delete data](#delete-data "Delete data")
@@ -131,6 +149,28 @@ except exceptions.CosmosHttpResponseError:
131149
raise
132150
```
133151

152+
### Create an Analytical Store enabled container
153+
154+
This example creates a container with [Analytical Store](https://docs.microsoft.com/en-us/azure/cosmos-db/analytical-store-introduction) enabled, for reporting, BI, AI, and Advanced Analytics with [Azure Synapse Link](https://docs.microsoft.com/en-us/azure/cosmos-db/synapse-link).
155+
156+
Options:
157+
158+
+ 0 or Null = Not enabled.
159+
+ -1 = The data will be stored infinitely.
160+
+ Any other number is the actual ttl, in seconds.
161+
162+
```Python
163+
container_name = 'products'
164+
try:
165+
container = database.create_container(id=container_name, partition_key=PartitionKey(path="/productName"),analytical_storage_ttl=-1)
166+
except exceptions.CosmosResourceExistsError:
167+
container = database.get_container_client(container_name)
168+
except exceptions.CosmosHttpResponseError:
169+
raise
170+
```
171+
172+
The preceding snippet also handles the [CosmosHttpResponseError][ref_httpfailure] exception if the container creation failed. For more information on error handling and troubleshooting, see the [Troubleshooting](#troubleshooting "Troubleshooting") section.
173+
134174
The preceding snippet also handles the [CosmosHttpResponseError][ref_httpfailure] exception if the container creation failed. For more information on error handling and troubleshooting, see the [Troubleshooting](#troubleshooting "Troubleshooting") section.
135175

136176
### Get an existing container

sdk/cosmos/azure-cosmos/samples/container_management.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# 2.4 - Create container with unique key
2525
# 2.5 - Create Container with partition key V2
2626
# 2.6 - Create Container with partition key V1
27+
# 2.7 - Create Container with analytical store enabled
2728
#
2829
# 3. Manage Container Provisioned Throughput
2930
# 3.1 - Get Container provisioned throughput (RU/s)
@@ -67,8 +68,8 @@ def find_container(db, id):
6768

6869

6970
def create_container(db, id):
70-
""" Execute the most basic Create of container.
71-
This will create a container with 400 RUs throughput and default indexing policy """
71+
""" Execute basic container creation.
72+
This will create containers with 400 RUs with different indexing, partitioning, and storage options """
7273

7374
partition_key = PartitionKey(path='/id', kind='Hash')
7475
print("\n2.1 Create Container - Basic")
@@ -84,9 +85,8 @@ def create_container(db, id):
8485

8586
try:
8687
coll = {
87-
"id": "container_custom_index_policy",
88+
"id": id+"_container_custom_index_policy",
8889
"indexingPolicy": {
89-
"indexingMode": "lazy",
9090
"automatic": False
9191
}
9292
}
@@ -107,9 +107,8 @@ def create_container(db, id):
107107
print("\n2.3 Create Container - With custom provisioned throughput")
108108

109109
try:
110-
coll = {"id": "container_custom_throughput"}
111110
container = db.create_container(
112-
id=coll['id'],
111+
id=id+"_container_custom_throughput",
113112
partition_key=partition_key,
114113
offer_throughput=400
115114
)
@@ -122,7 +121,7 @@ def create_container(db, id):
122121

123122
try:
124123
container = db.create_container(
125-
id="container_unique_keys",
124+
id= id+"_container_unique_keys",
126125
partition_key=partition_key,
127126
unique_key_policy={'uniqueKeys': [{'paths': ['/field1/field2', '/field3']}]}
128127
)
@@ -138,7 +137,7 @@ def create_container(db, id):
138137

139138
try:
140139
container = db.create_container(
141-
id="container_partition_key_v2",
140+
id=id+"_container_partition_key_v2",
142141
partition_key=PartitionKey(path='/id', kind='Hash')
143142
)
144143
properties = container.read()
@@ -152,7 +151,7 @@ def create_container(db, id):
152151

153152
try:
154153
container = db.create_container(
155-
id="container_partition_key_v1",
154+
id=id+"_container_partition_key_v1",
156155
partition_key=PartitionKey(path='/id', kind='Hash', version=1)
157156
)
158157
properties = container.read()
@@ -162,6 +161,21 @@ def create_container(db, id):
162161
except exceptions.CosmosResourceExistsError:
163162
print('A container with id \'container_partition_key_v1\' already exists')
164163

164+
print("\n2.7 Create Container - With analytical store enabled")
165+
166+
try:
167+
container = db.create_container(
168+
id=id+"_container_analytical_store",
169+
partition_key=PartitionKey(path='/id', kind='Hash',analytical_storage_ttl=-1)
170+
)
171+
properties = container.read()
172+
print('Container with id \'{0}\' created'.format(container.id))
173+
print('Partition Key - \'{0}\''.format(properties['partitionKey']))
174+
175+
except exceptions.CosmosResourceExistsError:
176+
print('A container with id \'_container_analytical_store\' already exists')
177+
178+
165179

166180
def manage_provisioned_throughput(db, id):
167181
print("\n3.1 Get Container provisioned throughput (RU/s)")

sdk/cosmos/azure-cosmos/samples/index_management.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
# excludedPaths
2323
#
2424
# We can toggle 'automatic' to eiher be True or False depending upon whether we want to have indexing over all columns by default or not.
25-
# indexingMode can be either of consistent, lazy or none
2625
#
2726
# We can provide options while creating documents. indexingDirective is one such,
2827
# by which we can tell whether it should be included or excluded in the index of the parent container.

0 commit comments

Comments
 (0)