Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何使用columns value生成另一列';s Spark Scala中withColumn的名称_Json_Scala_Dataframe_Dynamic_Apache Spark Sql - Fatal编程技术网

Json 如何使用columns value生成另一列';s Spark Scala中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

我试图在读取json资源文件后生成dataframe。我的json文件包含依赖属性,在使用withColumn时,我需要获取列值以创建另一个列名

你可以在下面找到我目前正在做的事情:

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的例子吗?