![]() |
Image from https://www.pexels.com/@mikebirdy/ |
Azure Blob Storage Table provides a very economical way to store schema-free records. However, it has some limitations. In the blog, we look at limitations in search queries.
We need these dependencies
python-dotenv==0.21.1 azure-data-tables==12.4.2
And here is a tiny code snippet.
import os from dotenv import load_dotenv from azure.core.exceptions import ResourceExistsError from azure.data.tables import TableClient # create .env file and have values for these # BLOB_CONN_STR= # TBL_NAME= load_dotenv() tbl_name = os.getenv("TBL_NAME") tbl_client = TableClient.from_connection_string( os.getenv("BLOB_CONN_STR"), tbl_name) try: tbl_client.create_table() except ResourceExistsError: print(f"Table, {tbl_name} already exists") tbl_client.create_entity(entity={ "PartitionKey": "pk", # set your partition key accordingly. "RowKey": "row-1", "Name": "Alice", "Color": "Red", "FavoriteNumber": 1 }); tbl_client.create_entity(entity={ "PartitionKey": "pk", # set your partition key accordingly. "RowKey": "row-2", "Name": "Brenda", "Color": "Pink", "FavoriteNumber": 2 }); tbl_client.create_entity(entity={ "PartitionKey": "pk", # set your partition key accordingly. "RowKey": "row-3", "Name": "Cindy", "Color": "Pink", "FavoriteNumber": 1, "Extra": "Friend of Alice" }); tbl_client.create_entity(entity={ "PartitionKey": "pk", # set your partition key accordingly. "RowKey": "row-4", "Name": "Daphne", "Color": "Pink", "FavoriteNumber": 1, "Extra": "Friend of Brenda" }); parameters = {"color": "Pink"} queried_entities = tbl_client.query_entities( query_filter="Color eq @color", select=["Name", "Color", "FavoriteNumber", "Timestamp"], parameters=parameters ) for entity_chosen in queried_entities: print(entity_chosen)
We get the Python storage table client, create a table, and insert 4 rows. In the last row, we have an extra column, and it is ok :-). The result is
{'Color': 'Pink', 'FavoriteNumber': 2, 'Name': 'Brenda'} {'Color': 'Pink', 'FavoriteNumber': 1, 'Name': 'Cindy'} {'Color': 'Pink', 'FavoriteNumber': 1, 'Name': 'Daphne'}
Note that the Timestamp is not printed out. Timestamps can be printed out like this.
print(entity_chosen.metadata['timestamp'])
and in the Azure portal, we have
Limitations
There are no options to do order by that is sorting of rows is not supported.
And. there are no ways to limit the number of results. The results_per_page property is not supported yet.
Comments
Post a Comment