Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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
将scala中的数组类型转换为_Scala_Apache Spark_Dataframe_Rdd - Fatal编程技术网

将scala中的数组类型转换为

将scala中的数组类型转换为,scala,apache-spark,dataframe,rdd,Scala,Apache Spark,Dataframe,Rdd,我在将数据帧中的列转换为字符串格式时遇到了问题。数据帧的示例如下所示: -- example_code_b: string (nullable = true) -- example_code: array (nullable = true) [info] | |-- element: map (containsNull = true) [info] | | |-- key: string [info] | | |-- value: string (valueC

我在将数据帧中的列转换为字符串格式时遇到了问题。数据帧的示例如下所示:

-- example_code_b: string (nullable = true)
-- example_code: array (nullable = true)
[info]  |    |-- element: map (containsNull = true)
[info]  |    |    |-- key: string
[info]  |    |    |-- value: string (valueContainsNull = true)
我想将示例代码从当前的arraymapstring,string转换为string,string格式

输入格式为[Mapentity->PER,Mapentity->PER]和 我希望输出的形式是PER,PER


您可以在DataFrame API中执行UDF,也可以使用Dataset API执行UDF:

import spark.implicits._

df
  .as[Seq[Map[String,String]]]
  .map(s => s.reduce(_ ++ _))
  .toDF("example_code")
  .show()

注意,这不考虑多个密钥的情况,它们没有合并,只是覆盖了

。您可以简单地在任何数组列上使用爆炸函数,这将为数组的每个值创建单独的行。

val newDF = df.withColumn("mymap" explode(col("example_code")))

嘿,我告诉他这个错误:找不到数据集中存储的类型的编码器。导入spark.implicits可支持基本类型Int、String等和产品类型case类。将来的版本中将添加对序列化其他类型的支持。[错误].maps=>s.reduce++\I已导入隐式:import spark.implicits.\udf.as[Seq[Map[String,String]].maps=>s.reduce++.toDFex\u代码。显示此操作无效。输入的格式是[Mapentity->PER,Mapentity->PER],我希望它的格式是PER,PERHey Raphael,这段代码不起作用。你有其他选择吗?嘿,分解打印出连续行中的每个输入,我希望它们在同一行中,用a分隔,意思是,你想在单个映射中合并所有值?是的。这不管用。输入的形式是[Mapentity->PER,Mapentity->PER],我希望它的形式是PER,PERis示例代码。。大小为1?的数组。不,它有多个参数