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

[Blob][QQ]Default output_format to input_format #12283

Merged
merged 1 commit into from
Jul 1, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def _quick_query_options(self, query_expression,
delimiter = output_format.lineterminator
except AttributeError:
delimiter = output_format.delimiter
else:
output_format = input_format
query_request = QueryRequest(
expression=query_expression,
input_serialization=serialize_query_format(input_format),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.3.3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Wed, 01 Jul 2020 01:25:22 GMT
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/utqqcontainercb261fef?restype=container
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Wed, 01 Jul 2020 01:25:22 GMT
etag:
- '"0x8D81D5D9FFCC701"'
last-modified:
- Wed, 01 Jul 2020 01:25:22 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-version:
- '2019-12-12'
status:
code: 201
message: Created
- request:
body: '{"name": "owner", "id": 1}{"name2": "owner2"}{"name": "owner", "id": 1}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '71'
Content-Type:
- application/octet-stream
User-Agent:
- azsdk-python-storage-blob/12.3.3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Wed, 01 Jul 2020 01:25:22 GMT
x-ms-tags:
- ''
x-ms-version:
- '2019-12-12'
method: PUT
uri: https://storagename.blob.core.windows.net/utqqcontainercb261fef/csvfilecb261fef
response:
body:
string: ''
headers:
content-length:
- '0'
content-md5:
- 5tYmuyKFS9mJzdfHlAFncQ==
date:
- Wed, 01 Jul 2020 01:25:22 GMT
etag:
- '"0x8D81D5DA010ECF2"'
last-modified:
- Wed, 01 Jul 2020 01:25:22 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-content-crc64:
- EFBi2aad5IE=
x-ms-request-server-encrypted:
- 'true'
x-ms-version:
- '2019-12-12'
status:
code: 201
message: Created
- request:
body: '<?xml version=''1.0'' encoding=''utf-8''?>

<QueryRequest><QueryType>SQL</QueryType><Expression>SELECT name from BlobStorage</Expression><InputSerialization><Format><Type>json</Type><JsonTextConfiguration><RecordSeparator>

</RecordSeparator></JsonTextConfiguration></Format></InputSerialization><OutputSerialization><Format><Type>json</Type><JsonTextConfiguration><RecordSeparator>

</RecordSeparator></JsonTextConfiguration></Format></OutputSerialization></QueryRequest>'
headers:
Accept:
- application/xml
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '465'
Content-Type:
- application/xml; charset=utf-8
User-Agent:
- azsdk-python-storage-blob/12.3.3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Wed, 01 Jul 2020 01:25:22 GMT
x-ms-version:
- '2019-12-12'
method: POST
uri: https://storagename.blob.core.windows.net/utqqcontainercb261fef/csvfilecb261fef?comp=query
response:
body:
string: !!binary |
T2JqAQIWYXZyby5zY2hlbWG+HlsKICB7CiAgICAidHlwZSI6ICJyZWNvcmQiLAogICAgIm5hbWUi
OiAiY29tLm1pY3Jvc29mdC5henVyZS5zdG9yYWdlLnF1ZXJ5QmxvYkNvbnRlbnRzLnJlc3VsdERh
dGEiLAogICAgImRvYyI6ICJIb2xkcyByZXN1bH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lbiBzZW50LiIsCiAgICAiZmllbGRzIjogWwogICAgICB7
CiAgICAgICAgIm5hbWUiOiAidG90YWxCeXRlcyIsCiAgICAgICAgInR5cGUiOiAibG9uZyIsCiAg
ICAgICAgImRvYyI6ICJUaGUgdG90YWwgbnVtYmVyIG9mIGJ5dGVzIHRvIGJlIHNjYW5uZWQgaW4g
dGhpcyBxdWVyeSIKICAgICAgfQogICAgXQogIH0KXQoAMXp9EeYLOEaqWbd+uR5gOAJOAEp7Im5h
bWUiOiJvd25lciJ9Cnt9CnsibmFtZSI6Im93bmVyIn0KMXp9EeYLOEaqWbd+uR5gOAIKBI4BjgEx
en0R5gs4RqpZt365HmA4AgYGjgExen0R5gs4RqpZt365HmA4
headers:
accept-ranges:
- bytes
content-type:
- avro/binary
date:
- Wed, 01 Jul 2020 01:25:38 GMT
etag:
- '"0x8D81D5DA010ECF2"'
last-modified:
- Wed, 01 Jul 2020 01:25:22 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
- chunked
x-ms-blob-type:
- BlockBlob
x-ms-creation-time:
- Wed, 01 Jul 2020 01:25:22 GMT
x-ms-lease-state:
- available
x-ms-lease-status:
- unlocked
x-ms-version:
- '2019-12-12'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '0'
User-Agent:
- azsdk-python-storage-blob/12.3.3 Python/3.7.3 (Windows-10-10.0.18362-SP0)
x-ms-date:
- Wed, 01 Jul 2020 01:25:39 GMT
x-ms-version:
- '2019-12-12'
method: DELETE
uri: https://storagename.blob.core.windows.net/utqqcontainercb261fef?restype=container
response:
body:
string: ''
headers:
content-length:
- '0'
date:
- Wed, 01 Jul 2020 01:25:39 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-version:
- '2019-12-12'
status:
code: 202
message: Accepted
version: 1
37 changes: 37 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_quick_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,41 @@ def on_error(error):
self.assertEqual(listdata, [b'{"name":"owner"}',b'{}',b'{"name":"owner"}', b''])
self._teardown(bsc)

@GlobalStorageAccountPreparer()
def test_quick_query_with_only_input_json_serialization_setting(self, resource_group, location, storage_account,
storage_account_key):
# Arrange
bsc = BlobServiceClient(
self.account_url(storage_account, "blob"),
credential=storage_account_key)
self._setup(bsc)

data1 = b'{\"name\": \"owner\", \"id\": 1}'
data2 = b'{\"name2\": \"owner2\"}'
data = data1 + data2 + data1

# upload the json file
blob_name = self._get_blob_reference()
blob_client = bsc.get_blob_client(self.container_name, blob_name)
blob_client.upload_blob(data, overwrite=True)

errors = []
def on_error(error):
errors.append(error)

input_format = DelimitedJSON(delimiter='\n')
output_format = None

resp = blob_client.query_blob(
"SELECT name from BlobStorage",
on_error=on_error,
blob_format=input_format,
output_format=output_format)
query_result = resp.readall()

self.assertEqual(len(errors), 0)
self.assertEqual(resp._size, len(data))
self.assertEqual(query_result, b'{"name":"owner"}\n{}\n{"name":"owner"}\n')
self._teardown(bsc)

# ------------------------------------------------------------------------------