【问题标题】:define the return type for udf in pyspark在 pyspark 中定义 udf 的返回类型
【发布时间】:2022-11-24 04:24:14
【问题描述】:

我正在创建一个基于以下功能的 UDF:

def return_output(column):
    return {'features':{'site':'a.com', 'test':column, 'test_vocab':['a','b','c']}

但我不确定如何定义返回类型

列的一个例子是 {"sentence":[0,1,2],"another_one":[0,1,2]}

所以最终的输出看起来像下面这样:

{'features':{'home_page':'a.com', 'test':{"sentence":[0,1,2],"another_one":[0,1,2]}
, 'test_vocab':['a','b','c']}

我应该如何定义此输出的返回类型?

【问题讨论】:

    标签: pyspark user-defined-functions return-type


    【解决方案1】:

    这看起来很JSON像这样正确的类型应该是StructType - 你可以在这里阅读更多关于它的信息 - https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.types.StructType.html#structtype

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2021-04-13
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-11-01
      相关资源
      最近更新 更多