Skip to content

Commit

Permalink
resolve comments (#38295)
Browse files Browse the repository at this point in the history
Co-authored-by: annie-mac <xinlian@microsoft.com>
  • Loading branch information
xinlian12 and annie-mac authored Nov 5, 2024
1 parent 6293903 commit 8b3b1d2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def to_dict(self) -> Dict[str, Any]:
return {
self.version_property_name: ChangeFeedStateVersion.V2.value,
self.container_rid_property_name: self._container_rid,
self.change_feed_mode_property_name: "Incremental",
self.change_feed_mode_property_name: "LatestVersion",
self.change_feed_start_from_property_name: self._change_feed_start_from.to_dict(),
self.continuation_property_name: self._continuation.to_dict() if self._continuation is not None else None
}
Expand Down
21 changes: 11 additions & 10 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
"""
import warnings
from datetime import datetime
from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload, Iterable
from typing import Any, Dict, Mapping, Optional, Sequence, Type, Union, List, Tuple, cast, overload, AsyncIterable
from typing_extensions import Literal

from azure.core import MatchConditions
from azure.core.async_paging import AsyncItemPaged
from azure.core.async_paging import AsyncItemPaged, AsyncList
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async # type: ignore

from ._cosmos_client_connection_async import CosmosClientConnection
from .._change_feed.feed_range_internal import FeedRangeInternalEpk
from .._cosmos_responses import CosmosDict, CosmosList
from ._scripts import ScriptsProxy
from .._base import (
build_options as _build_options,
Expand All @@ -43,6 +41,8 @@
GenerateGuidId,
_set_properties_cache
)
from .._change_feed.feed_range_internal import FeedRangeInternalEpk
from .._cosmos_responses import CosmosDict, CosmosList
from .._routing.routing_range import Range
from .._session_token_helpers import get_latest_session_token
from ..offer import ThroughputProperties
Expand Down Expand Up @@ -637,8 +637,8 @@ def query_items_change_feed( # pylint: disable=unused-argument
before high priority requests start getting throttled. Feature must first be enabled at the account level.
:keyword Callable response_hook: A callable invoked with the response metadata.
:param Any args: args
:returns: An Iterable of items (dicts).
:rtype: Iterable[Dict[str, Any]]
:returns: An AsyncItemPaged of items (dicts).
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
# pylint: disable=too-many-statements
if kwargs.get("priority") is not None:
Expand Down Expand Up @@ -1297,13 +1297,13 @@ async def read_feed_ranges(
*,
force_refresh: Optional[bool] = False,
**kwargs: Any
) -> Iterable[Dict[str, Any]]:
) -> AsyncIterable[Dict[str, Any]]:
""" Obtains a list of feed ranges that can be used to parallelize feed operations.
:keyword bool force_refresh:
Flag to indicate whether obtain the list of feed ranges directly from cache or refresh the cache.
:returns: A list representing the feed ranges in base64 encoded string
:rtype: Iterable[Dict[str, Any]]
:returns: AsyncIterable representing the feed ranges in base64 encoded string
:rtype: AsyncIterable[Dict[str, Any]]
.. warning::
The structure of the dict representation of a feed range may vary, including which keys
Expand All @@ -1322,7 +1322,8 @@ async def read_feed_ranges(

feed_ranges = [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).to_dict()
for partitionKeyRange in partition_key_ranges]
return (feed_range for feed_range in feed_ranges)

return AsyncList(feed_ranges)

async def get_latest_session_token(
self,
Expand Down
3 changes: 1 addition & 2 deletions sdk/cosmos/azure-cosmos/azure/cosmos/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,8 @@ def read_feed_ranges(
[Range("", "FF", True, False)], # default to full range
**kwargs)

feed_ranges = [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).to_dict()
return [FeedRangeInternalEpk(Range.PartitionKeyRangeToRange(partitionKeyRange)).to_dict()
for partitionKeyRange in partition_key_ranges]
return (feed_range for feed_range in feed_ranges)

def get_latest_session_token(
self,
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure-cosmos/samples/examples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async def examples_async():

# Get the feed ranges list from container.
# [START read_feed_ranges]
feed_ranges = list(await container.read_feed_ranges())
feed_ranges = [feed_range async for feed_range in await container.read_feed_ranges()]
# [END read_feed_ranges]

# Get a feed range from a partition key.
Expand Down Expand Up @@ -296,7 +296,7 @@ async def examples_async():
# The asynchronous client returns asynchronous iterators for its query methods;
# as such, we iterate over it by using an async for loop
# [START query_items_change_feed_from_beginning]
feed_ranges = await container.read_feed_ranges()
feed_ranges = [feed_range async for feed_range in await container.read_feed_ranges()]
async for item in container.query_items_change_feed(feed_range=feed_ranges[0], start_time="Beginning"):
print(json.dumps(item, indent=True))
# [END query_items_change_feed_from_beginning]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def storing_session_tokens_container_feed_ranges(container):
# to store session tokens in a cache by feed range from the partition key.
feed_ranges_and_session_tokens = []
previous_session_token = ""
feed_ranges = list(await container.read_feed_ranges())
feed_ranges = [feed_range async for feed_range in await container.read_feed_ranges()]

# populating cache with session tokens
for i in range(5):
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure-cosmos/test/test_change_feed_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestChangeFeedAsync:
async def test_get_feed_ranges(self, setup):
created_collection = await setup["created_db"].create_container("get_feed_ranges_" + str(uuid.uuid4()),
PartitionKey(path="/pk"))
result = list(await created_collection.read_feed_ranges())
result = [feed_range async for feed_range in await created_collection.read_feed_ranges()]
assert len(result) == 1

@pytest.mark.parametrize("change_feed_filter_param", ["partitionKey", "partitionKeyRangeId", "feedRange"])
Expand All @@ -57,7 +57,7 @@ async def test_query_change_feed_with_different_filter_async(self, change_feed_f
elif change_feed_filter_param == "partitionKeyRangeId":
filter_param = {"partition_key_range_id": "0"}
elif change_feed_filter_param == "feedRange":
feed_ranges = list(await created_collection.read_feed_ranges())
feed_ranges = [feed_range async for feed_range in await created_collection.read_feed_ranges()]
assert len(feed_ranges) == 1
filter_param = {"feed_range": feed_ranges[0]}
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def create_items_logical_pk(container, target_pk_range, previous_session_t
@staticmethod
async def create_items_physical_pk(container, pk_feed_range, previous_session_token, feed_ranges_and_session_tokens, hpk=False):
target_session_token = ""
container_feed_ranges = list(await container.read_feed_ranges())
container_feed_ranges = [feed_range async for feed_range in await container.read_feed_ranges()]
target_feed_range = None
for feed_range in container_feed_ranges:
if await container.is_feed_range_subset(feed_range, pk_feed_range):
Expand Down

0 comments on commit 8b3b1d2

Please sign in to comment.