簡體   English   中英

AWS Glue SelectFields 和 Filter 不采用動態值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM