Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.

Commit 4c4c346

Browse files
author
Srinath Narayanan
authored
Added Hashv2 sample - V2 SDK (#163)
* added Hashv2 sample
1 parent 89ace19 commit 4c4c346

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

samples/CollectionManagement/Program.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# 2.2 - Create collection with custom IndexPolicy
2323
# 2.3 - Create collection with offer throughput set
2424
# 2.4 - Create collection with unique key
25+
# 2.5 - Create Collection with partition key
26+
# 2.6 - Create Collection with partition key V2
2527
#
2628
# 3. Manage Collection Offer Throughput
2729
# 3.1 - Get Collection performance tier
@@ -165,12 +167,37 @@ def create_Container(client, id):
165167

166168
collection = client.CreateContainer(database_link, coll)
167169
print('Collection with id \'{0}\' created'.format(collection['id']))
170+
print('Partition Key - \'{0}\''.format(collection['partitionKey']))
168171

169172
except errors.CosmosError as e:
170173
if e.status_code == 409:
171174
print('A collection with id \'{0}\' already exists'.format(collection['id']))
172175
else:
173-
raise errors.HTTPFailure(e.status_code)
176+
raise errors.HTTPFailure(e.status_code)
177+
178+
print("\n2.6 Create Collection - With Partition key V2")
179+
180+
try:
181+
coll = {
182+
"id": "collection_partition_key_v2",
183+
"partitionKey": {
184+
"paths": [
185+
"/field1"
186+
],
187+
"kind": "Hash",
188+
"version": 2
189+
}
190+
}
191+
192+
collection = client.CreateContainer(database_link, coll)
193+
print('Collection with id \'{0}\' created'.format(collection['id']))
194+
print('Partition Key - \'{0}\''.format(collection['partitionKey']))
195+
196+
except errors.CosmosError as e:
197+
if e.status_code == 409:
198+
print('A collection with id \'{0}\' already exists'.format(collection['id']))
199+
else:
200+
raise errors.HTTPFailure(e.status_code)
174201

175202
@staticmethod
176203
def manage_offer_throughput(client, id):

0 commit comments

Comments
 (0)