0
df2.withColumn("cid", regexp_replace(df2("cid"), "\"", ""))

 trentyid | cid
----------+----------
 a        | 1, 5, 16
 b        | 76, 34

Both trendyid and cid are string columns.

df3.select($"trentyid".as("trentyid"), explode(split($"cid", ",")).as("cid1"))

Output:

 trentyid | cid1
----------+----------
 a        |
 b        |

This last line seems to not work as expected, as the second column is empty.

What could the cause of that be?

stefanobaghino
  • 11,253
  • 4
  • 35
  • 63
Dipanjan Das
  • 33
  • 1
  • 4
  • Your code `val df4=df3.select($"trentyid".as("trentyid"),explode(split( $"cid", ",")).as("cid1"))` is working as expected. It is giving correct result. – himanshuIIITian May 18 '18 at 07:49
  • But why is that cid1 empty........i want cid1 to have all the values i.e 1,5,16 ,76,34 in separate rows . – Dipanjan Das May 18 '18 at 07:50
  • It's not empty. I got following result - `+--------+----+ |trentyid|cid1| +--------+----+ |a |1 | |a |5 | |a |16 | |b |76 | |b |34 | +--------+----+ ` – himanshuIIITian May 18 '18 at 07:51
  • Got the expected result myself. After three confirmations, you may want to check your code as there may be something else wrong with it. – stefanobaghino May 18 '18 at 09:09

0 Answers0