我有一个看起来像这样的小 csv 文件:
is_employee,candidate_id,gender,hesa_type,university
FALSE,b9bb80,Male,Mathematical sciences,Birmingham
FALSE,8e552d,Female,Computer science,Swansea
TRUE,2bc475,Male,Engineering & technology,Aston
TRUE,c3ac8d,Female,Mathematical sciences,Heriot-Watt
FALSE,ceb2fa,Female,Mathematical sciences,Imperial College London
以下 lambda 函数用于从 s3bucket 进行查询。
import boto3
import os
import json
def lambda_handler(event, context):
BUCKET_NAME = 'foo'
KEY = 'bar/data.csv'
s3 = boto3.client('s3','eu-west-1')
response = s3.select_object_content(
Bucket = BUCKET_NAME,
Key = KEY,
ExpressionType = 'SQL',
Expression = 'Select count(*) from s3object s where s.gender like \'%Female%\'',
InputSerialization = {'CSV': {"FileHeaderInfo": "Use"}},
OutputSerialization = {'JSON': {}},
)
for i in response['Payload']:
if 'Records' in i:
query_result = i['Records']['Payload'].decode('utf-8')
print(list(json.loads(query_result).values())[0])
现在,这很好用,因为我得到了3
. like
但是由于某种原因,将运算符更改为 时,相同的代码不起作用=
,结果下拉为0
,因此找不到匹配项。这里发生了什么事 ?