I have a dataframe in spark as shown below

```
  a    b
( 21 , 23 )
( 23 , 21 )
( 22 , 21 )
( 21 , 22 )

```

I want a dataframe which should look like this:-

```
( 21 , 22 )
( 21 , 23 )
( 22 , 21 )
( 22 , 23 )
( 23 , 21 )
( 23 , 22 )

```

So it should consider all possible combinations for both columns. How this can be achieved?

I tried Cartesian join but it is taking too much time for very small dataset.Any other alternatives? 

Thanks.