我编写了一个AWS Glue脚本,它使用SelectFields()和Filter()方法进行字段选择和过滤。我已经用静态值测试了它们,效果很好,但是当动态值以相同的格式传递时,它们就不起作用了。知道为什么不取动态值吗? 我通过传递一个动态值进行了测试,对于本例,两种方法都有效。你知道吗
请注意,如果传递的密钥(filterkey)是静态的或动态的,那么它也可以工作
wordstoFilter = ['USA', 'France']
columnstoSelect = ['cust_id', 'custname', 'state']
#join and return all list values in single quote along with comma
fltr_string =', '.join(["'{}'".format(value) for value in wordstoFilter])
select_string =', '.join(["'{}'".format(value) for value in columnstoSelect ])
filterkey = "country"
#below statement works with static value
#country_filter_dyf = Filter.apply(frame=custData, f=(lambda x: x["country"] in ["USA"]))
country_filter_dyf = Filter.apply(frame=custData, f=(lambda x: x[filterkey] in [fltr_string]))
##Select case
#below statement works with static value
#selected_fields_dyf = SelectFields.apply(frame = custData, paths = ['cust_id', 'cust_name', 'state', 'country'])
#Below one doesn't work
selected_dyf = SelectFields.apply(frame = custData, paths = [select_string ])
如我所见,paths参数要求您提供一个列表,但您提供一个str对象:
你有没有试着直接列出名单?你知道吗
相关问题 更多 >
编程相关推荐