import boto3
s3 = boto3.client('s3')
resp = s3.select_object_content(
Bucket='s3-nb-demo',
Key='sample_data.parquet',
ExpressionType='SQL',
Expression="SELECT * FROM s3object s where s.\"Name\" = 'NB'",
InputSerialization = {'Parquet': {}},
OutputSerialization = {'CSV': {}},
)
for event in resp['Payload']:
if 'Records' in event:
records = event['Records']['Payload'].decode('utf-8')
print(records)
elif 'Stats' in event:
statsDetails = event['Stats']['Details']
print("Stats details bytesScanned: ")
print(statsDetails['BytesScanned'])
print("Stats details bytesProcessed: ")
print(statsDetails['BytesProcessed'])
print("Stats details bytesReturned: ")
print(statsDetails['BytesReturned'])
该代码不返回任何行。我已经使用 Athena 验证了数据文件和查询,它返回了多行。该resp['Payload']
对象没有名为 的属性Records
。我见过很多使用 CSV 文件的示例,但没有关于 Parquet 文件的帖子。