简体   繁体   English

AWS Glue SelectFields 和 Filter 不采用动态值

[英]AWS Glue SelectFields and Filter not taking dynamic values

I have an AWS Glue script written which does field selection and Filtering using SelectFields() and Filter() methods.我编写了一个 AWS Glue 脚本,它使用SelectFields()Filter()方法进行字段选择和过滤。 I have tested these with static values and works fine, however, they do not work when dynamic values are passed in the same format.我已经用静态值测试了这些并且工作正常,但是,当以相同格式传递动态值时,它们不起作用。 Any idea why the dynamic values are not taken?知道为什么不采用动态值吗? I tested out by passing one of the dynamic values and for this case, both methods work.我通过传递一个动态值进行了测试,对于这种情况,两种方法都有效。

Pls also note that the passed key (filterkey) works if its static or dynamic还请注意,传递的键(过滤键)在其静态或动态时有效

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 ])

As I see, the paths argument expects you to give a list but you give a str object:如我所见,路径参数希望您提供一个列表,但您提供一个 str 对象:

>>> type(['cust_id', 'cust_name', 'state', 'country'])
<class 'list'>
>>> type(select_string)
<class 'str'>

Have you tried to give the list directly?你有没有试过直接给清单?

>>> 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM