1

Assuming I set up my blob_client correctly (with the right storage account key, url, container name, and blob name) why is my python query code failing? The file in blob is a JSON.

query_expression = "SELECT COUNT(*) from blobdata"
input_format = DelimitedJsonDialect(delimiter=',')
reader = blob_client.query_blob(query_expression, on_error=on_error, blob_format=input_format)
content = reader.readall()
print(content)

Error: azure.core.exceptions.HttpResponseError: Invalid path for JSON-formatted input.

additionally what should the table in the query string be?

1 Answer 1

2

I was able to dig this up from the Azure documentation

https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blobclient?view=azure-python#azure-storage-blob-blobclient-query-blob

query_expression = "SELECT _2 from BlobStorage"
input_format = DelimitedTextDialect(delimiter=',', quotechar='"', lineterminator='\n', escapechar="", has_header=False)
reader = blob_client.query_blob(query_expression, on_error=on_error, blob_format=input_format, output_format=output_format)

I think you need to at least add that "DelimitedTextDialect" input, and the example was querying from BlobStorage.

I find the azure python docs pretty hard to parse, but I think you can import the "DelimitedTextDialect" from azure.storage.blob.delimitedtextdialect

see https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.delimitedtextdialect?view=azure-python

Sign up to request clarification or add additional context in comments.

3 Comments

I was following that same documentation, however (and apologies if you had answered after I made an edit), I am using the DelimitedJsonDialect as input format for my json file in blob. So, I'm specifying the blob format but still getting an error. My json file in blob has one value that's a nested json if that helps.
are you querying "from BlobStorage" too like the docs? I do think I might have written this up right before you edited it
Oh wow. I didn't realize you had to put that exact from clause in the query. I assumed it needed to be the name of the blob container. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.