[英]AWS Glue SelectFields and Filter not taking dynamic values
我编写了一个 AWS Glue 脚本,它使用SelectFields()和Filter()方法进行字段选择和过滤。 我已经用静态值测试了这些并且工作正常,但是,当以相同格式传递动态值时,它们不起作用。 知道为什么不采用动态值吗? 我通过传递一个动态值进行了测试,对于这种情况,两种方法都有效。
还请注意,传递的键(过滤键)在其静态或动态时有效
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 ])
如我所见,路径参数希望您提供一个列表,但您提供一个 str 对象:
>>> type(['cust_id', 'cust_name', 'state', 'country'])
<class 'list'>
>>> type(select_string)
<class 'str'>
你有没有试过直接给清单?
>>> type(columnstoSelect)
<class 'list'>
columnstoSelect = ['cust_id', 'custname', 'state']
selected_dyf = SelectFields.apply(frame = custData, paths = columnstoSelect )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.