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

Commit 2856a30

Browse files
Srinath Narayananchristopheranderson
Srinath Narayanan
authored andcommitted
fixed bug for maxItemCount in order by queries (#177)
* fixed bug for maxItemCount in order by queries * bumped version for release
1 parent e6118a9 commit 2856a30

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

azure/cosmos/execution_context/document_producer.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ class _DocumentProducer(object):
3535
When handling an orderby query, MultiExecutionContextAggregator instantiates one instance of this class
3636
per target partition key range and aggregates the result of each.
3737
'''
38-
def __init__(self, partition_key_target_range, client, collection_link, query, document_producer_comp):
38+
def __init__(self, partition_key_target_range, client, collection_link, query, document_producer_comp, options):
3939
'''
4040
Constructor
4141
'''
42-
# TODO: is that fine we build the options dict and we don't inherit it?
43-
self._options = {}
42+
self._options = options
4443
self._partition_key_target_range = partition_key_target_range
4544
self._doc_producer_comp = document_producer_comp
4645
self._client = client
@@ -59,7 +58,7 @@ def fetch_fn(options):
5958
query,
6059
options,
6160
partition_key_target_range['id'])
62-
61+
6362
self._ex_context = _DefaultQueryExecutionContext(client, self._options, fetch_fn)
6463

6564
def get_target_range(self):

azure/cosmos/execution_context/multi_execution_aggregator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
142142
else:
143143
query = self._query
144144

145-
return document_producer._DocumentProducer(partition_key_target_range, self._client, self._resource_link, query, self._document_producer_comparator)
145+
return document_producer._DocumentProducer(partition_key_target_range, self._client, self._resource_link, query, self._document_producer_comparator, self._options)
146146

147147
def _get_target_parition_key_range(self):
148148

azure/cosmos/http_constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class Versions:
257257
"""
258258
CurrentVersion = '2018-09-17'
259259
SDKName = 'azure-cosmos'
260-
SDKVersion = '3.1.0'
260+
SDKVersion = '3.1.1'
261261

262262

263263
class Delimiters:

changelog.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## Changes in 3.1.1 : ##
2+
3+
- Bug fix in orderby queries to honor maxItemCount
4+
5+
## Changes in 3.1.0 : ##
6+
7+
- Added support for picking up endpoint and key from environment variables
8+
19
## Changes in 3.0.2 : ##
210

311
- Added Support for MultiPolygon Datatype
@@ -17,8 +25,8 @@
1725
- DocumentClient to CosmosClient
1826
- Collection to Container
1927
- Document to Item
20-
- Package name updated to azure-cosmos
21-
- Namespace updated to azure.cosmos
28+
- Package name updated to "azure-cosmos"
29+
- Namespace updated to "azure.cosmos"
2230

2331
## Changes in 2.3.3 : ##
2432

doc/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
# built documents.
5353
#
5454
# The short X.Y version.
55-
version = '3.1.0'
55+
version = '3.1.1'
5656
# The full version, including alpha/beta/rc tags.
57-
release = '3.1.0'
57+
release = '3.1.1'
5858

5959
# The language for content autogenerated by Sphinx. Refer to documentation
6060
# for a list of supported languages.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import setuptools
55

66
setup(name='azure-cosmos',
7-
version='3.1.0',
7+
version='3.1.1',
88
description='Azure Cosmos Python SDK',
99
author="Microsoft",
1010
author_email="[email protected]",

test/query_tests.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
import pytest
44
import azure.cosmos.cosmos_client as cosmos_client
5-
import azure.cosmos.documents as documents
5+
import azure.cosmos.retry_utility as retry_utility
66
import test.test_config as test_config
77

88
@pytest.mark.usefixtures("teardown")
@@ -155,5 +155,40 @@ def test_populate_query_metrics (self):
155155
self.assertTrue(len(metrics) > 1)
156156
self.assertTrue(all(['=' in x for x in metrics]))
157157

158+
def test_max_item_count_honored_in_order_by_query(self):
159+
created_collection = self.config.create_multi_partition_collection_with_custom_pk_if_not_exist(self.client)
160+
docs = []
161+
for i in range(10):
162+
document_definition = {'pk': 'pk', 'id': 'myId' + str(uuid.uuid4())}
163+
docs.append(self.client.CreateItem(created_collection['_self'], document_definition))
164+
165+
query = 'SELECT * from c ORDER BY c._ts'
166+
query_options = {'enableCrossPartitionQuery': True,
167+
'maxItemCount': 1}
168+
query_iterable = self.client.QueryItems(created_collection['_self'], query, query_options)
169+
#1 call to get query plans, 1 call to get pkr, 10 calls to one partion with the documents, 1 call each to other 4 partitions
170+
self.validate_query_requests_count(query_iterable, 16 * 2)
171+
172+
query_options['maxItemCount'] = 100
173+
query_iterable = self.client.QueryItems(created_collection['_self'], query, query_options)
174+
# 1 call to get query plan 1 calls to one partition with the documents, 1 call each to other 4 partitions
175+
self.validate_query_requests_count(query_iterable, 6 * 2)
176+
177+
def validate_query_requests_count(self, query_iterable, expected_count):
178+
self.count = 0
179+
self.OriginalExecuteFunction = retry_utility._ExecuteFunction
180+
retry_utility._ExecuteFunction = self._MockExecuteFunction
181+
block = query_iterable.fetch_next_block()
182+
while block:
183+
block = query_iterable.fetch_next_block()
184+
retry_utility._ExecuteFunction = self.OriginalExecuteFunction
185+
self.assertEquals(self.count, expected_count)
186+
self.count = 0
187+
188+
def _MockExecuteFunction(self, function, *args, **kwargs):
189+
self.count += 1
190+
return self.OriginalExecuteFunction(function, *args, **kwargs)
191+
192+
158193
if __name__ == "__main__":
159194
unittest.main()

0 commit comments

Comments
 (0)