You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何向AWS Glue Map.Apply调用的函数中传入参数

Map.apply 传入的目标函数默认第一个入参为待处理frame的单行数据,你可以按以下两种方式绑定自定义参数:

方案1:用lambda匿名函数包装(适合参数少的场景)

先调整自定义函数,将行数据作为第一个入参,之后追加你需要的自定义参数,再用lambda提前绑定固定参数即可:

def awsome_function(row, needed_input_var):
    # 你的业务逻辑示例:从行中取字段和自定义参数运算
    return row.sale_count * needed_input_var

# 调用时用lambda包裹,提前传入自定义参数的固定值
Map.apply(
    frame=products_combination, 
    f=lambda row: awsome_function(row, needed_input_var=你要传入的参数值)
)

方案2:用functools.partial绑定参数(适合多参数场景,代码更简洁)

from functools import partial

# 支持传入多个自定义参数
def awsome_function(row, needed_input_var, discount_rate):
    return row.origin_price * needed_input_var * discount_rate

# 提前绑定所有自定义固定参数,剩余第一个row参数留给Map.apply自动传入
bound_func = partial(awsome_function, needed_input_var=12, discount_rate=0.8)
Map.apply(frame=products_combination, f=bound_func)

如果你的参数需要随每行数据动态变化,可将对应参数值提前写入products_combination的字段中,直接在函数内从row读取对应字段即可,无需额外传参。

内容的提问来源于stack exchange,提问作者Brian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 05:54:01