我有一个Dataframe,我试图展平。作为该过程的一部分,我想将其分解,所以如果我有一列数组,则将使用数组的每个值创建一个单独的行。我知道我可以使用爆炸函数。但是,我有一个问题,该列包含空值,我使用火花1.6。下面是数据类型和我想要什么的例子:
我的数据:Spark 1.6以空值爆炸
id | ListOfRficAction| RficActionAttachment
_______________________________
1 | Luke | [baseball, soccer]
2 | Lucy | null
,我想
id | ListOfRficAction| RficActionAttachment
_______________________________
1 | Luke | baseball
1 | Luke | soccer
2 | Lucy | null
我使用的Spark 1.6(所以我不能使用explode_outer功能),我尝试使用爆炸,但我有以下错误:
scala.MatchError: [null] (of class org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema)
我也尝试:
df.withColumn("likes", explode(
when(col("likes").isNotNull, col("likes"))
// If null explode an array<string> with a single null
.otherwise(array(lit(null).cast("string")))))
但我的DataFrame架构是一个很复杂(我有字符串和长),所以强制转换功能不起作用。这里是我的架构的一部分,我有错误:
|-- RficActionAttachment: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- ActivityFileAutoUpdFlg: string (nullable = true)
| | |-- ActivityFileDate: string (nullable = true)
| | |-- ActivityFileDeferFlg: string (nullable = true)
| | |-- ActivityFileDockReqFlg: string (nullable = true)
| | |-- ActivityFileDockStatFlg: string (nullable = true)
| | |-- ActivityFileExt: string (nullable = true)
| | |-- ActivityFileName: string (nullable = true)
| | |-- ActivityFileRev: string (nullable = true)
| | |-- ActivityFileSize: long (nullable = true)
| | |-- ActivityFileSrcPath: string (nullable = true)
| | |-- ActivityFileSrcType: string (nullable = true)
| | |-- ActivityId: string (nullable = true)
| | |-- AttachmentId: string (nullable = true)
| | |-- Comment: string (nullable = true)
用户类抛出的异常:
org.apache.spark.sql.AnalysisException: cannot resolve 'CASE WHEN isnotnull(ListOfRficAction.RficAction.ListOfRficActionAttachment.RficActionAttachment) THEN ListOfRficAction.RficAction.ListOfRficActionAttachment.RficActionAttachment ELSE array(ListOfRficAction.RficAction.ListOfRficActionAttachment.RficActionAttachment)'
由于数据类型不匹配:THEN和ELSE表情都应该是相同类型或强制转换到一种常见的类型;
想知道我能做些什么吗?
我的问题是不同的,因为当我的模式 –
问题是情况下,当我不能使用的情况下不适用于我 –