Skip to content

Instantly share code, notes, and snippets.

@blackrez
Created July 18, 2021 09:51
Show Gist options
  • Save blackrez/228470193f43b658522e9911a03a153d to your computer and use it in GitHub Desktop.
Save blackrez/228470193f43b658522e9911a03a153d to your computer and use it in GitHub Desktop.
import boto3
s3 = boto3.client('s3')
resp = s3.select_object_content(
Bucket='carto-1000x',
Key='data/yellow_tripdata_2016–01.csv',
ExpressionType='SQL',
Expression="SELECT avg(cast(tip_amount as float)) , count(1) FROM s3object s",
InputSerialization = {'CSV': {"FileHeaderInfo": "Use", 'FieldDelimiter': ',','RecordDelimiter': '\n'}, 'CompressionType': 'NONE'},
OutputSerialization = {'CSV': {}},
)
for event in resp['Payload']:
if 'Records' in event:
records = event['Records']['Payload'].decode('utf-8')
print(records)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment