如你所知, transform
api已经集成到spark3.0.0中,但是我已经厌倦了,不知道如何使用它,也不能用google搜索任何用法。有人能给我一个用法吗?比你还厉害!
我累了什么:
val source = spark.read.format("json").option("multiLine", "true").load("/home/user/Desktop/test.json")
source.select(transform($"array0",x =>struct($"x.a".as("A")) ))
org.apache.spark.sql.AnalysisException: cannot resolve '`x.a`' given input columns: [array0];;
'Project [transform(array0#0, lambdafunction(named_struct(NamePlaceholder, 'x.a), lambda x#4, false)) AS transform(array0, lambdafunction(named_struct(NamePlaceholder(), x.a AS `A`), x))#3]
+- RelationV2[array0#0] json file:/home/usr/Desktop/test.json
我的源json:
{
"array0":[
{
"a":"0",
"b":"1"
}
]
}
1条答案
按热度按时间whlutmcx1#
如果你是指高阶函数
transform
与数组一起使用,下面是一个简单的工作示例:在您的示例中,由于数组中有结构,因此可以按如下方式访问结构的元素: