The schema looks like this
root
|-- orderitemlist: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- internal-material-code: string (nullable = true)
| | |-- lot-number: string (nullable = true)
| | |-- packaging-item-code: string (nullable = true)
| | |-- packaging-item-code-type: string (nullable = true)
how do I access the values for internal-material-code and lot-number
on creating the dataframe I do this
df.withColumn("internalmaterialcode", col("orderitemlist")(0).getItem("internal-material-code"))
also
df.withColumn("internalmaterialcode", col("orderitemlist")(0)("internal-material-code"))
also as follows
df.withColumn("orderitemlistarray", explode(col("orderitemlist")))
.withColumn("internalmaterialcode", col("orderitemlistarray").getItem("internal-material-code"))
also as follows
df.withColumn("orderitemlistarray", explode(col("orderitemlist")))
.withColumn("internalmaterialcode", col("orderitemlistarray.internal-material-code"))
but it gives out null
I have seen similar looking schemas on stackoverflow questions but none of the answers were useful for me. Could someone answer it or direct me to the correct place.
explode. Give that a google, lots of info out there..withColumn("orderitemlistarray", explode(col("orderitemlist"))) .withColumn("internalmaterialcode", col("orderitemlistarray").getItem("internal-material-code"))also as follows.withColumn("orderitemlistarray", explode(col("orderitemlist"))) .withColumn("internalmaterialcode", col("orderitemlistarray.internal-material-code"))