Json 如何使用columns value生成另一列';s Spark Scala中withColumn的名称
我试图在读取json资源文件后生成dataframe。我的json文件包含依赖属性,在使用withColumn时,我需要获取列值以创建另一个列名 你可以在下面找到我目前正在做的事情:Json 如何使用columns value生成另一列';s Spark Scala中withColumn的名称,json,scala,dataframe,dynamic,apache-spark-sql,Json,Scala,Dataframe,Dynamic,Apache Spark Sql,我试图在读取json资源文件后生成dataframe。我的json文件包含依赖属性,在使用withColumn时,我需要获取列值以创建另一个列名 你可以在下面找到我目前正在做的事情: val getInfo= df .withColumn("transactions", explode($"transactions"))//this is array .withColumn("id", $"transactions.data.profile.id") .wit
val getInfo= df
.withColumn("transactions", explode($"transactions"))//this is array
.withColumn("id", $"transactions.data.profile.id")
.withColumn("totalAmounts", explode($"transactions.data.activity.total"))
.withColumn("amount", $"totalAmounts.amount")
.withColumn("code", $"totalAmounts.code")
.withColumn("category", $"totalAmounts.category")
.withColumn("createdAt", $"transactions.data.meta.created.at")
.withColumn("relatedDetails", explode($"transactions.data.related"))
.withColumn("resourceId", $"relatedDetails.id")
.withColumn("mainType", $"relatedDetails.type")
.withColumn("subType", $"transactions.data.subType")
.drop("transactions")
.drop("totalAmounts")
.drop("relatedDetails")
.as[TransactionData]
.toDF()
上面的代码对我来说没问题,但json文件中有一个动态生成的属性。
当我想添加另一列“transactionType”时,它依赖于“resourceId”列的值
我需要做的是:
.withColumn("transactionType",$"transactions.included.transactionDetail.<<resourceId value>>.transactionType") .
.withColumn(“transactionType”,“$”transactions.included.transactionDetail..transactionType”)。
你能举个JSON的例子吗?