UDF函数为数组<Struct>类型格式化日期字段并返回格式化数据

问题描述 投票:0回答:0

我想编写一个通用的 udf 函数,它将输入作为数组列并检查所有时间戳字段。将时间戳字段格式化为 UTC,然后返回带有格式化时间戳的数组。

例如 我有这样的数据

“accountsLinked”:[{ “信息”:“account1”, “用户”:{ “编号”:“1234”, “名字”:“测试1”, “姓氏”:“测试2” }, "时间戳":"18486854578", “upstreamApp”:“JOKO” }]

udf 函数的输出应该是包含以下详细信息的数组

“accountsLinked”:[{ “信息”:“account1”, “用户”:{ “编号”:“1234”, “名字”:“测试1”, “姓氏”:“测试2” }, “时间戳”:“2023-08-23 12:12:45:456”, “upstreamApp”:“JOKO” }]

我试图创建一个 udf 函数,它以 json 形式提供输出,但我无法将该 json 转换为结构数组

apache apache-spark apache-spark-sql apache-spark-dataset
© www.soinside.com 2019 - 2024. All rights reserved.