Hi @rishigc
You can use something like below.
SELECT explode(arrays_zip(split(Product, '+'), split(Price, '+') ) as product_and_price from df
or
df.withColumn("product_and_price", explode(arrays_zip(split(Product, '+'), split(Price, '+'))).select(
$"CustId", $"prodAndPrice.Product", $"prodAndPrice.Price").show()
Here df is the dataframe.
split
function splits the column into array of products & array of prices. These 2 arrays will be merged by
arrays_zip
, so that Nth product will be mapped to Nth price. Then the merged array is exploded using
explode
, so that each element in the array becomes a separate row.
please let us know if it works.
Thanks