i have two data frames i want to check if df1 contains any row in df2 where key is a and b, if equal then change exists to true in df2 and add the new rows from df1 with exists False
df1
a | b | c | d
1 | 1 | 3 | 4
2 | 2 | 4 | 1
3 | 3 | 5 | 3
df2
a | b | c | d
1 | 1 | 4 | 5
4 | 4 | 3 | 2
this should look like
df3
a | b | c | d | exists
1 | 1 | 4 | 5 | True
4 | 4 | 3 | 2 | False
1 | 1 | 3 | 4 | False
2 | 2 | 4 | 1 | False
3 | 3 | 5 | 3 | False
so far i have this
val newdf = df1.join(df2, df1("a")===df2("a") && df1("b") === df2("b"), "left")
.select(df2("a"), df2("b"),df2("c"),df2("d"),when(df2("a").isNull, false).otherwise(true).alias("exists"))
which returns
a | b | c | d | exists
1 | 1 | 4 | 5 | True
rest of the rows are null
1 | 1 | 3 | 4 | Falsedid this row going to be in df3 too? because there is matching row in df1..