github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/select/select.py (about)

     1  #!/usr/bin/env/env python3
     2  import boto3
     3  
     4  s3 = boto3.client('s3',
     5                    endpoint_url='http://localhost:9000',
     6                    aws_access_key_id='minio',
     7                    aws_secret_access_key='minio123',
     8                    region_name='us-east-1')
     9  
    10  r = s3.select_object_content(
    11      Bucket='mycsvbucket',
    12      Key='sampledata/TotalPopulation.csv.gz',
    13      ExpressionType='SQL',
    14      Expression="select * from s3object s where s.Location like '%United States%'",
    15      InputSerialization={
    16          'CSV': {
    17              "FileHeaderInfo": "USE",
    18          },
    19          'CompressionType': 'GZIP',
    20      },
    21      OutputSerialization={'CSV': {}},
    22  )
    23  
    24  for event in r['Payload']:
    25      if 'Records' in event:
    26          records = event['Records']['Payload'].decode('utf-8')
    27          print(records)
    28      elif 'Stats' in event:
    29          statsDetails = event['Stats']['Details']
    30          print("Stats details bytesScanned: ")
    31          print(statsDetails['BytesScanned'])
    32          print("Stats details bytesProcessed: ")
    33          print(statsDetails['BytesProcessed'])