I have JSON file with 6 records and one of the column(p_ccodes) contains below values
rec-1: "p_ccodes" : [ ],
rec-2: "p_ccodes" : [ [ "FLASHSALE" ] ],
rec-3: "p_ccodes" : [ [ "GRATISONGKIR" ] ],
rec-4: "p_ccodes" : [ [ "SAYALI13" ] ],
rec-5: "p_ccodes" : [ [ "testCappingIndo" ] ],
rec-6: "p_ccodes" : [ ],
I tried with below code:
df.withColumn("p_ccodes", explode(col("p_ccodes"))).withColumn("p_ccodes", explode(col("p_ccodes")))
output for that column as below which is expected but need to have all 6 records. I am getting only 4 instead of 6.
Output:
+--------------------+
|p_appliedcouponcodes|
+-----+---------------
| FLASHSALE|
| GRATISONGKIR|
| SAYALI13|
| testCappingIndo|
+-----+---------------`
Please suggest how can I get all 6 records with null value for other two records.