小编A k*_*ram的帖子

仅过滤非空数组数据帧火花

我如何只过滤非空数组

import  org.apache.spark.sql.types.ArrayType

  val arrayFields = secondDF.schema.filter(st => st.dataType.isInstanceOf[ArrayType])
  val names = arrayFields.map(_.name)
Run Code Online (Sandbox Code Playgroud)

或者是这个代码

val DF1=DF.select(col("key"),explode(col("objectiveAttachment")).as("collection")).select(col("collection.*"),col("key"))

|-- objectiveAttachment: array (nullable = true) 
 | |-- element: string (containsNull = true) 
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

 org.apache.spark.sql.AnalysisException: Can only star expand struct data types. Attribute: ArrayBuffer(collection);
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

scala apache-spark apache-spark-sql

5
推荐指数
1
解决办法
8434
查看次数

在 Spark 中的 Dataframe 中展平数组

如何将数组展平为包含列 [a,b,c,d,e] 的数据帧

root
 |-- arry: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- a string (nullable = true)
 |    |    |-- b: long (nullable = true)
 |    |    |-- c: string (nullable = true)
 |    |    |-- d: string (nullable = true)
 |    |    |-- e: long (nullable = true)
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

scala apache-spark apache-spark-sql

2
推荐指数
1
解决办法
6228
查看次数

标签 统计

apache-spark ×2

apache-spark-sql ×2

scala ×2