因此,我使用PyDrill进行SQL查询:
相关代码如下:
yelp_reviews = drill.query('''
SELECT sum(case when t.attributes.Parking.garage='true' then 1 else 0 end) as garage,
sum(case when t.attributes.Parking.street='true' then 1 else 0 end) as street,
sum(case when t.attributes.Parking.validated='true' then 1 else 0 end) as validated,
sum(case when t.attributes.Parking.valet='true' then 1 else 0 end) as valet,
sum(case when t.attributes.Parking.lot='true' then 1 else 0 end) as lot FROM `mongo.274_BI`.`yelp_dataset`t
where t.city=?
''','Las Vegas')执行此命令时,我得到以下错误:
ValueError: Timeout value connect was Las Vegas, but it must be an int or float.我使用以下命令更新了请求
pip install -U requests;不过,错误仍然存在。请帮帮忙。
发布于 2016-10-28 02:46:43
drill.query需要第二个参数的超时值。您传入的字符串"Las Vegas“不是数字(即int或float)。
根据documentation,query接受两个参数sql和timeout。您的SQL应该作为第一个参数传入,超时应该作为可选的第二个参数传入。
在深入研究它之后,您希望将"Las Vegas“安全地插入到sql中。看起来PyDrill不支持这一点。解决方案是只将"Las Vegas“添加到实际查询中,只要sql不来自不受信任的来源,它就可以工作。如果是这样的话,我建议使用PyDrill打开一个问题,因为这应该得到国际海事组织的支持。
https://stackoverflow.com/questions/40291617
复制相似问题