S3 Select: Parse null-values (#6343)

This commit is contained in:
Bert Blommers 2023-05-25 16:37:45 +00:00 committed by GitHub
parent 82a83af80b
commit 0144953273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 12 deletions

View File

@ -1,4 +1,7 @@
from typing import Any, Dict, List from typing import Any, Dict, List, TYPE_CHECKING
if TYPE_CHECKING:
from py_partiql_parser import QueryMetadata
def query( def query(
@ -9,7 +12,7 @@ def query(
return DynamoDBStatementParser(source_data).parse(statement, parameters) return DynamoDBStatementParser(source_data).parse(statement, parameters)
def get_query_metadata(statement: str) -> Any: def get_query_metadata(statement: str) -> "QueryMetadata":
from py_partiql_parser import DynamoDBStatementParser from py_partiql_parser import DynamoDBStatementParser
return DynamoDBStatementParser.get_query_metadata(query=statement) return DynamoDBStatementParser.get_query_metadata(query=statement)

View File

@ -2486,9 +2486,14 @@ class S3Backend(BaseBackend, CloudWatchMetricProvider):
use_headers = input_details["CSV"].get("FileHeaderInfo", "") == "USE" use_headers = input_details["CSV"].get("FileHeaderInfo", "") == "USE"
query_input = csv_to_json(query_input, use_headers) query_input = csv_to_json(query_input, use_headers)
query_result = parse_query(query_input, select_query)
from py_partiql_parser import SelectEncoder
return [ return [
json.dumps(x, indent=None, separators=(",", ":")).encode("utf-8") json.dumps(x, indent=None, separators=(",", ":"), cls=SelectEncoder).encode(
for x in parse_query(query_input, select_query) "utf-8"
)
for x in query_result
] ]

View File

@ -52,7 +52,7 @@ all =
openapi-spec-validator>=0.2.8 openapi-spec-validator>=0.2.8
pyparsing>=3.0.7 pyparsing>=3.0.7
jsondiff>=1.1.2 jsondiff>=1.1.2
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
aws-xray-sdk!=0.96,>=0.93 aws-xray-sdk!=0.96,>=0.93
setuptools setuptools
server = server =
@ -66,7 +66,7 @@ server =
openapi-spec-validator>=0.2.8 openapi-spec-validator>=0.2.8
pyparsing>=3.0.7 pyparsing>=3.0.7
jsondiff>=1.1.2 jsondiff>=1.1.2
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
aws-xray-sdk!=0.96,>=0.93 aws-xray-sdk!=0.96,>=0.93
setuptools setuptools
flask!=2.2.0,!=2.2.1 flask!=2.2.0,!=2.2.1
@ -100,7 +100,7 @@ cloudformation =
openapi-spec-validator>=0.2.8 openapi-spec-validator>=0.2.8
pyparsing>=3.0.7 pyparsing>=3.0.7
jsondiff>=1.1.2 jsondiff>=1.1.2
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
aws-xray-sdk!=0.96,>=0.93 aws-xray-sdk!=0.96,>=0.93
setuptools setuptools
cloudfront = cloudfront =
@ -123,10 +123,10 @@ dms =
ds = sshpubkeys>=3.1.0 ds = sshpubkeys>=3.1.0
dynamodb = dynamodb =
docker>=3.0.0 docker>=3.0.0
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
dynamodbstreams = dynamodbstreams =
docker>=3.0.0 docker>=3.0.0
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
ebs = sshpubkeys>=3.1.0 ebs = sshpubkeys>=3.1.0
ec2 = sshpubkeys>=3.1.0 ec2 = sshpubkeys>=3.1.0
ec2instanceconnect = ec2instanceconnect =
@ -183,7 +183,7 @@ route53 =
route53resolver = sshpubkeys>=3.1.0 route53resolver = sshpubkeys>=3.1.0
s3 = s3 =
PyYAML>=5.1 PyYAML>=5.1
py-partiql-parser==0.3.0 py-partiql-parser==0.3.1
s3control = s3control =
sagemaker = sagemaker =
sdb = sdb =

View File

@ -6,7 +6,7 @@ from unittest import TestCase
from uuid import uuid4 from uuid import uuid4
SIMPLE_JSON = {"a1": "b1", "a2": "b2"} SIMPLE_JSON = {"a1": "b1", "a2": "b2", "a3": None}
SIMPLE_JSON2 = {"a1": "b2", "a3": "b3"} SIMPLE_JSON2 = {"a1": "b2", "a3": "b3"}
SIMPLE_LIST = [SIMPLE_JSON, SIMPLE_JSON2] SIMPLE_LIST = [SIMPLE_JSON, SIMPLE_JSON2]
SIMPLE_CSV = """a,b,c SIMPLE_CSV = """a,b,c
@ -47,7 +47,14 @@ class TestS3Select(TestCase):
OutputSerialization={"JSON": {"RecordDelimiter": ","}}, OutputSerialization={"JSON": {"RecordDelimiter": ","}},
) )
result = list(x["Payload"]) result = list(x["Payload"])
result.should.contain({"Records": {"Payload": b'{"a1":"b1","a2":"b2"},'}}) result.should.contain(
{"Records": {"Payload": b'{"a1":"b1","a2":"b2","a3":null},'}}
)
# Verify result is valid JSON
json.loads(result[0]["Records"]["Payload"][0:-1].decode("utf-8"))
# Verify result contains metadata
result.should.contain( result.should.contain(
{ {
"Stats": { "Stats": {