Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/pipelines/templates/stages/cosmos-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extends:
BeforeTestSteps:
- template: /eng/common/pipelines/templates/steps/cosmos-emulator.yml
parameters:
StartParameters: '/noexplorer /noui /enablepreview /EnableSqlComputeEndpoint /SqlComputePort=9999 /disableratelimiting /partitioncount=50 /consistency=Session'
StartParameters: '/noexplorer /noui /enablepreview /EnableSqlComputeEndpoint /SqlComputePort=9999 /disableratelimiting /partitioncount=50 /consistency=Session /overrides=enablePreviousImageForDeleteInFFCF:true'
MatrixConfigs:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- Name: Python_cosmos_emulator
Expand Down
16 changes: 16 additions & 0 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -1058,6 +1062,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -1142,6 +1150,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -1187,6 +1199,10 @@ def query_items_change_feed( # pylint: disable=unused-argument
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down
16 changes: 16 additions & 0 deletions sdk/cosmos/azure-cosmos/azure/cosmos/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -547,6 +551,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -632,6 +640,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down Expand Up @@ -680,6 +692,10 @@ def query_items_change_feed(
LATEST_VERSION: Query latest items from 'start_time' or 'continuation' token.
ALL_VERSIONS_AND_DELETES: Query all versions and deleted items from either `start_time='Now'`
or 'continuation' token.
All versions and deletes responses contain ``current`` and ``metadata`` keys. The **provisional**
``previous`` key can contain the previous item version when previous images are enabled for the container.
To request access to this provisional feature, see `previous image opt-in
<https://aka.ms/cosmosdb-change-feed-deletes>`_.
:paramtype mode: Literal["LatestVersion", "AllVersionsAndDeletes"]
:keyword Sequence[str] excluded_locations: Excluded locations to be skipped from preferred locations. The locations
in this list are specified as the names of the azure Cosmos locations like, 'West US', 'East US' and so on.
Expand Down
25 changes: 19 additions & 6 deletions sdk/cosmos/azure-cosmos/samples/change_feed_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ def clean_up(container):
# Deleting the current item
container.delete_item(item, partition_key=item['address']['state'])


def print_all_versions_and_deletes_change(change):
metadata = change.get('metadata', {})
print('Operation: {}'.format(metadata.get('operationType')))
print('Current item: {}'.format(change.get('current')))

# `previous` is provisional and is returned only when previous images are enabled for the container.
# Request preview access at https://aka.ms/cosmosdb-change-feed-deletes.
previous = change.get('previous')
if previous is not None:
print('Previous item: {}'.format(previous))


def read_change_feed(container):
print('\nReading Change Feed from the beginning\n')

Expand Down Expand Up @@ -126,21 +139,21 @@ def read_change_feed_with_all_versions_and_delete_mode(container):
# This initial call was made to store a point in time in a 'continuation' token
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes")
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

# Read all change feed with 'AllVersionsAndDeletes' mode after create items from a continuation
create_items(container, 10, 'CA')
create_items(container, 10, 'OR')
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", continuation=continuation_token)
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

# Read all change feed with 'AllVersionsAndDeletes' mode after delete items from a continuation
clean_up(container)
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", continuation=continuation_token)
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(container):
print('\nReading Change Feed with AllVersionsAndDeletes mode from the partition key\n')
Expand All @@ -149,7 +162,7 @@ def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(contai
# This initial call was made to store a point in time and 'partition_key' in a 'continuation' token
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", partition_key="CA")
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

create_items(container, 10, 'CA')
Expand All @@ -158,15 +171,15 @@ def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(contai
# Should only print the created items with 'CA' partition key value
response_iterator = container.query_items_change_feed(mode='AllVersionsAndDeletes', continuation=continuation_token)
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

clean_up(container)
# Read change feed 'AllVersionsAndDeletes' mode with 'CA' partition key value from the previous continuation.
# Should only print the deleted items with 'CA' partition key value
response_iterator = container.query_items_change_feed(mode='AllVersionsAndDeletes', continuation=continuation_token)
for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

def run_sample():
client = cosmos_client.CosmosClient(HOST, {'masterKey': MASTER_KEY})
Expand Down
25 changes: 19 additions & 6 deletions sdk/cosmos/azure-cosmos/samples/change_feed_management_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ async def clean_up(container):
# Deleting the current item
await container.delete_item(item, partition_key=item['address']['state'])


def print_all_versions_and_deletes_change(change):
metadata = change.get('metadata', {})
print('Operation: {}'.format(metadata.get('operationType')))
print('Current item: {}'.format(change.get('current')))

# `previous` is provisional and is returned only when previous images are enabled for the container.
# Request preview access at https://aka.ms/cosmosdb-change-feed-deletes.
previous = change.get('previous')
if previous is not None:
print('Previous item: {}'.format(previous))


async def read_change_feed(container):
print('\nReading Change Feed from the beginning\n')

Expand Down Expand Up @@ -134,21 +147,21 @@ async def read_change_feed_with_all_versions_and_delete_mode(container):
# This initial call was made to store a point in time in a 'continuation' token
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes")
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

# Read all change feed with 'AllVersionsAndDeletes' mode after create items from a continuation
await create_items(container, 10, 'CA')
await create_items(container, 10, 'OR')
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", continuation=continuation_token)
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

# Read all change feed with 'AllVersionsAndDeletes' mode after delete items from a continuation
await clean_up(container)
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", continuation=continuation_token)
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

async def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(container):
print('\nReading Change Feed with AllVersionsAndDeletes mode from the partition key\n')
Expand All @@ -157,7 +170,7 @@ async def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(
# This initial call was made to store a point in time and 'partition_key' in a 'continuation' token
response_iterator = container.query_items_change_feed(mode="AllVersionsAndDeletes", partition_key="CA")
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

await create_items(container, 10, 'CA')
Expand All @@ -166,15 +179,15 @@ async def read_change_feed_with_all_versions_and_delete_mode_with_partition_key(
# Should only print the created items with 'CA' partition key value
response_iterator = container.query_items_change_feed(mode='AllVersionsAndDeletes', continuation=continuation_token)
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)
continuation_token = container.client_connection.last_response_headers['etag']

await clean_up(container)
# Read change feed 'AllVersionsAndDeletes' mode with 'CA' partition key value from the previous continuation.
# Should only print the deleted items with 'CA' partition key value
response_iterator = container.query_items_change_feed(mode='AllVersionsAndDeletes', continuation=continuation_token)
async for doc in response_iterator:
print(doc)
print_all_versions_and_deletes_change(doc)

async def run_sample():
async with CosmosClient(HOST, MASTER_KEY) as client:
Expand Down
Loading
Loading