diff --git a/sdk/tables/azure-data-tables/CHANGELOG.md b/sdk/tables/azure-data-tables/CHANGELOG.md index 5b40c0a356f7..0f9110902e25 100644 --- a/sdk/tables/azure-data-tables/CHANGELOG.md +++ b/sdk/tables/azure-data-tables/CHANGELOG.md @@ -1,6 +1,7 @@ # Release History -## 12.0.0b4 (Unreleased) +## 12.0.0b4 (2020-01-12) +* Fixes an [issue](https://github.com/Azure/azure-sdk-for-python/issues/15554) where `query_entities` kwarg `parameters` would not work with multiple parameters or with non-string parameters. This now works with multiple parameters and numeric, string, boolean, UUID, and datetime objects. * Fixes an [issue](https://github.com/Azure/azure-sdk-for-python/issues/15653) where `delete_entity` will return an `ClientAuthenticationError` when the '@' symbol is included in the entity. ## 12.0.0b3 (2020-11-12) diff --git a/sdk/tables/azure-data-tables/samples/async_samples/sample_query_table_async.py b/sdk/tables/azure-data-tables/samples/async_samples/sample_query_table_async.py index b4aa54b9cf6a..db8d0f0a62a4 100644 --- a/sdk/tables/azure-data-tables/samples/async_samples/sample_query_table_async.py +++ b/sdk/tables/azure-data-tables/samples/async_samples/sample_query_table_async.py @@ -42,7 +42,7 @@ def __init__(self): ) self.table_name = "OfficeSupplies" - async def _insert_random_entities(self): + async def insert_random_entities(self): from azure.data.tables.aio import TableClient from azure.core.exceptions import ResourceExistsError brands = ["Crayola", "Sharpie", "Chameleon"] @@ -60,42 +60,102 @@ async def _insert_random_entities(self): except ResourceExistsError: print("Table already exists") - for i in range(10): + for i in range(25): e = copy.deepcopy(entity_template) e["RowKey"] += str(i) e["Name"] = random.choice(names) e["Brand"] = random.choice(brands) e["Color"] = random.choice(colors) + e["Value"] = random.randint(0, 100) await table_client.create_entity(entity=e) async def sample_query_entities(self): - await self._insert_random_entities() from azure.data.tables.aio import TableClient from azure.core.exceptions import HttpResponseError + print("Entities with name: marker") table_client = TableClient.from_connection_string(self.connection_string, self.table_name) # [START query_entities] async with table_client: try: - entity_name = "marker" - name_filter = "Name eq '{}'".format(entity_name) - - async for entity_chosen in table_client.query_entities(filter=name_filter, select=["Brand","Color"]): + parameters = { + u"name": u"marker" + } + name_filter = u"Name eq @name" + async for entity_chosen in table_client.query_entities( + filter=name_filter, select=[u"Brand",u"Color"], parameters=parameters): print(entity_chosen) except HttpResponseError as e: pass # [END query_entities] - finally: - await table_client.delete_table() + + async def sample_query_entities_multiple_params(self): + from azure.data.tables.aio import TableClient + from azure.core.exceptions import HttpResponseError + + print("Entities with name: marker and brand: Crayola") + # [START query_entities] + async with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: + try: + parameters = { + u"name": u"marker", + u"brand": u"Crayola" + } + name_filter = u"Name eq @name and Brand eq @brand" + queried_entities = table_client.query_entities( + filter=name_filter, select=[u"Brand",u"Color"], parameters=parameters) + + async for entity_chosen in queried_entities: + print(entity_chosen) + + except HttpResponseError as e: + print(e.message) + # [END query_entities] + + async def sample_query_entities_values(self): + from azure.data.tables.aio import TableClient + from azure.core.exceptions import HttpResponseError + + print("Entities with 25 < Value < 50") + # [START query_entities] + async with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: + try: + parameters = { + u"lower": 25, + u"upper": 50 + } + name_filter = u"Value gt @lower and Value lt @upper" + queried_entities = table_client.query_entities( + filter=name_filter, select=[u"Value"], parameters=parameters) + + async for entity_chosen in queried_entities: + print(entity_chosen) + + except HttpResponseError as e: + print(e.message) + # [END query_entities] + + async def clean_up(self): + print("cleaning up") + from azure.data.tables.aio import TableClient + async with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: + await table_client.delete_table() async def main(): stq = SampleTablesQuery() - sleep(10) - await stq.sample_query_entities() - sleep(10) + try: + await stq.insert_random_entities() + await stq.sample_query_entities() + await stq.sample_query_entities_multiple_params() + await stq.sample_query_entities_values() + except Exception as e: + print(e) + finally: + await stq.clean_up() + if __name__ == '__main__': diff --git a/sdk/tables/azure-data-tables/samples/sample_query_table.py b/sdk/tables/azure-data-tables/samples/sample_query_table.py index 336a50964bd5..e516dc956410 100644 --- a/sdk/tables/azure-data-tables/samples/sample_query_table.py +++ b/sdk/tables/azure-data-tables/samples/sample_query_table.py @@ -41,7 +41,7 @@ def __init__(self): self.table_name = "SampleQueryTable" - def _insert_random_entities(self): + def insert_random_entities(self): from azure.data.tables import TableClient from azure.core.exceptions import ResourceExistsError brands = [u"Crayola", u"Sharpie", u"Chameleon"] @@ -58,7 +58,7 @@ def _insert_random_entities(self): except ResourceExistsError: print(u"Table already exists") - for i in range(10): + for i in range(25): e = copy.deepcopy(entity_template) try: e[u"RowKey"] += unicode(i) @@ -67,20 +67,24 @@ def _insert_random_entities(self): e[u"Name"] = random.choice(names) e[u"Brand"] = random.choice(brands) e[u"Color"] = random.choice(colors) + e[u"Value"] = random.randint(0, 100) table_client.create_entity(entity=e) def sample_query_entities(self): - self._insert_random_entities() from azure.data.tables import TableClient from azure.core.exceptions import HttpResponseError + print("Entities with name: marker") # [START query_entities] with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: try: - entity_name = u"marker" - name_filter = u"Name eq '{}'".format(entity_name) - queried_entities = table_client.query_entities(filter=name_filter, select=[u"Brand",u"Color"]) + parameters = { + u"name": u"marker" + } + name_filter = u"Name eq @name" + queried_entities = table_client.query_entities( + filter=name_filter, select=[u"Brand",u"Color"], parameters=parameters) for entity_chosen in queried_entities: print(entity_chosen) @@ -89,9 +93,65 @@ def sample_query_entities(self): print(e.message) # [END query_entities] - finally: + def sample_query_entities_multiple_params(self): + from azure.data.tables import TableClient + from azure.core.exceptions import HttpResponseError + + print("Entities with name: marker and brand: Crayola") + # [START query_entities] + with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: + try: + parameters = { + u"name": u"marker", + u"brand": u"Crayola" + } + name_filter = u"Name eq @name and Brand eq @brand" + queried_entities = table_client.query_entities( + filter=name_filter, select=[u"Brand",u"Color"], parameters=parameters) + + for entity_chosen in queried_entities: + print(entity_chosen) + + except HttpResponseError as e: + print(e.message) + # [END query_entities] + + + def sample_query_entities_values(self): + from azure.data.tables import TableClient + from azure.core.exceptions import HttpResponseError + + print("Entities with 25 < Value < 50") + # [START query_entities] + with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: + try: + parameters = { + u"lower": 25, + u"upper": 50 + } + name_filter = u"Value gt @lower and Value lt @upper" + queried_entities = table_client.query_entities( + filter=name_filter, select=[u"Value"], parameters=parameters) + + for entity_chosen in queried_entities: + print(entity_chosen) + + except HttpResponseError as e: + print(e.message) + # [END query_entities] + + def clean_up(self): + from azure.data.tables import TableClient + with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: table_client.delete_table() + if __name__ == '__main__': stq = SampleTablesQuery() - stq.sample_query_entities() \ No newline at end of file + try: + stq.insert_random_entities() + stq.sample_query_entities() + stq.sample_query_entities_multiple_params() + stq.sample_query_entities_values() + except: + stq.clean_up() \ No newline at end of file