Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated release notes, added more examples to the sample #16027

Merged
merged 2 commits into from
Jan 8, 2021
Merged
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
3 changes: 2 additions & 1 deletion sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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__':
Expand Down
76 changes: 68 additions & 8 deletions sdk/tables/azure-data-tables/samples/sample_query_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
try:
stq.insert_random_entities()
stq.sample_query_entities()
stq.sample_query_entities_multiple_params()
stq.sample_query_entities_values()
except:
stq.clean_up()