【问题标题】:python udf in redshift - support for nested udfredshift 中的 python udf - 支持嵌套的 udf
【发布时间】:2019-03-07 03:14:58
【问题描述】:

我正在尝试在 redshift 中实现嵌套的 udf。

select 
     custom_function(custom_function('', column1), column2) 
from 
     table1 

但它说不支持嵌套的 udf。有人可以帮我吗?

尝试使用答案中提到的python库方法,如下所示!!

class f_string:
   def __init__(self, current_value, key, value):
   self.current_value = current_value
   self.key = key
   self.value = value

def f_make_json(self):
   import json
   current_value = json.loads(self.current_value)
   self.value.replace('"', '\"')
   current_value[self.key] = self.value
   return (json.dumps(current_value))

【问题讨论】:

    标签: python-3.x amazon-redshift user-defined-functions


    【解决方案1】:

    您必须将要嵌套的 UDF 组织为 Python 库并将该库导入您的集群,这里是 instruction

    【讨论】:

    • 不确定我是否理解它们应该如何嵌套以及您在库捆绑方面究竟做了什么
    • 我正在尝试创建一个 json 字符串。像这样 make_json(make_json('{}', 'key1', 'value1'), 'key2', 'value2') 将返回 {'key1':'value1', 'key2':'value2'}
    • 啊,嵌套的是同一个函数……我以为嵌套的是不同的函数。你可以试试子查询中的第一个函数和外部查询中的第二个函数吗?
    • 可能有超过 2 个变量。所以这里有多个子查询不会是理想的解决方案!
    • 毕竟,你为什么不使用连接运算符构建你的 json 呢?我一直在这样做,并且通过正确的代码格式(例如新行上的每个键/值对以及嵌入对象的正确缩进),它非常简单和干净
    猜你喜欢
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多