I want to explode Array[(Int, Int)]
INPUT:
colA newCol
1 [[11, 12],[13, 15]]
2 [[17, 91], [51, 72]]
OUTPUT:
colA newCol
1 11
1 13
2 17
2 51
My Schema looks like this:
|-- colA: integer (nullable = true)
|-- newCol: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- value: integer (nullable = true)
| | |-- count: integer (nullable = true)
I've tried something below like this:
val res = df.withColumn("tup", explode($"newCol")).select("colA", "tup")
res.select(col("colA"), col("tup")("value").as("uId"))
java.lang.RuntimeException: Error while encoding: java.lang.RuntimeException: scala.Tuple2$mcII$sp is not a valid external type for schema of struct<value:int,count:int>