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

Commit

Permalink
fixed bug for maxItemCount in order by queries (#177)
Browse files Browse the repository at this point in the history
* fixed bug for maxItemCount in order by queries

* bumped version for release
  • Loading branch information
Srinath Narayanan authored and christopheranderson committed Aug 5, 2019
1 parent e6118a9 commit 2856a30
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
7 changes: 3 additions & 4 deletions azure/cosmos/execution_context/document_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ class _DocumentProducer(object):
When handling an orderby query, MultiExecutionContextAggregator instantiates one instance of this class
per target partition key range and aggregates the result of each.
'''
def __init__(self, partition_key_target_range, client, collection_link, query, document_producer_comp):
def __init__(self, partition_key_target_range, client, collection_link, query, document_producer_comp, options):
'''
Constructor
'''
# TODO: is that fine we build the options dict and we don't inherit it?
self._options = {}
self._options = options
self._partition_key_target_range = partition_key_target_range
self._doc_producer_comp = document_producer_comp
self._client = client
Expand All @@ -59,7 +58,7 @@ def fetch_fn(options):
query,
options,
partition_key_target_range['id'])

self._ex_context = _DefaultQueryExecutionContext(client, self._options, fetch_fn)

def get_target_range(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
else:
query = self._query

return document_producer._DocumentProducer(partition_key_target_range, self._client, self._resource_link, query, self._document_producer_comparator)
return document_producer._DocumentProducer(partition_key_target_range, self._client, self._resource_link, query, self._document_producer_comparator, self._options)

def _get_target_parition_key_range(self):

Expand Down
2 changes: 1 addition & 1 deletion azure/cosmos/http_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Versions:
"""
CurrentVersion = '2018-09-17'
SDKName = 'azure-cosmos'
SDKVersion = '3.1.0'
SDKVersion = '3.1.1'


class Delimiters:
Expand Down
12 changes: 10 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Changes in 3.1.1 : ##

- Bug fix in orderby queries to honor maxItemCount

## Changes in 3.1.0 : ##

- Added support for picking up endpoint and key from environment variables

## Changes in 3.0.2 : ##

- Added Support for MultiPolygon Datatype
Expand All @@ -17,8 +25,8 @@
- DocumentClient to CosmosClient
- Collection to Container
- Document to Item
- Package name updated to azure-cosmos
- Namespace updated to azure.cosmos
- Package name updated to "azure-cosmos"
- Namespace updated to "azure.cosmos"

## Changes in 2.3.3 : ##

Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
# built documents.
#
# The short X.Y version.
version = '3.1.0'
version = '3.1.1'
# The full version, including alpha/beta/rc tags.
release = '3.1.0'
release = '3.1.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import setuptools

setup(name='azure-cosmos',
version='3.1.0',
version='3.1.1',
description='Azure Cosmos Python SDK',
author="Microsoft",
author_email="askdocdb@microsoft.com",
Expand Down
37 changes: 36 additions & 1 deletion test/query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uuid
import pytest
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.documents as documents
import azure.cosmos.retry_utility as retry_utility
import test.test_config as test_config

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

def test_max_item_count_honored_in_order_by_query(self):
created_collection = self.config.create_multi_partition_collection_with_custom_pk_if_not_exist(self.client)
docs = []
for i in range(10):
document_definition = {'pk': 'pk', 'id': 'myId' + str(uuid.uuid4())}
docs.append(self.client.CreateItem(created_collection['_self'], document_definition))

query = 'SELECT * from c ORDER BY c._ts'
query_options = {'enableCrossPartitionQuery': True,
'maxItemCount': 1}
query_iterable = self.client.QueryItems(created_collection['_self'], query, query_options)
#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
self.validate_query_requests_count(query_iterable, 16 * 2)

query_options['maxItemCount'] = 100
query_iterable = self.client.QueryItems(created_collection['_self'], query, query_options)
# 1 call to get query plan 1 calls to one partition with the documents, 1 call each to other 4 partitions
self.validate_query_requests_count(query_iterable, 6 * 2)

def validate_query_requests_count(self, query_iterable, expected_count):
self.count = 0
self.OriginalExecuteFunction = retry_utility._ExecuteFunction
retry_utility._ExecuteFunction = self._MockExecuteFunction
block = query_iterable.fetch_next_block()
while block:
block = query_iterable.fetch_next_block()
retry_utility._ExecuteFunction = self.OriginalExecuteFunction
self.assertEquals(self.count, expected_count)
self.count = 0

def _MockExecuteFunction(self, function, *args, **kwargs):
self.count += 1
return self.OriginalExecuteFunction(function, *args, **kwargs)


if __name__ == "__main__":
unittest.main()

0 comments on commit 2856a30

Please sign in to comment.