【发布时间】:2022-01-22 16:58:49
【问题描述】:
我创建了一个在控制台中工作的 Lambda 函数(调用 SciPy 包)。但不会在 Redshift.i 中返回预期结果
这是 Lambda 函数代码:
import json
from scipy import stats
def binomial_test(event, context):
t1 = event['arguments']
# 'len(t1)' represents the number of rows in the request payload.
# The number of results in the response payload should be the same as the number of rows received.
resp = [None]*len(t1)
# By default success is set to 'True'.
success = True
# Iterating over all rows in the request payload.
i = 0
for x in t1:
p_value = stats.binomtest(x[0], x[1], x[2], x[3]).pvalue
resp[i] = p_value
i = i+1
ret = dict()
ret['success'] = success
if not success:
ret['error_msg'] = "Invalid values"
else:
ret['results'] = resp
ret_json = json.dumps(ret)
return ret_json
这是 AWS 控制台中的结果,因此您可以看到 Lambda 可以正常工作:
"{\"success\": true, \"results\": [0.5381831001889082]}"
但在 Redshift 中,该函数只返回值 0。
这里是 UDF 定义:
CREATE EXTERNAL FUNCTION stats_binom_test (BIGINT, BIGINT, NUMERIC, VARCHAR)
RETURNS DOUBLE PRECISION
IMMUTABLE
LAMBDA 'stats_binom_test'
IAM_ROLE 'arn:aws:iam::xxxxxxxxxxxx'
您能告诉我如何正确地返回结果吗? 我尝试了各种数据类型,但没有任何效果。
【问题讨论】:
标签: amazon-web-services function aws-lambda amazon-redshift external