с левым соединением:
// data
val details = Seq(
(1, "1-1-19", "blr", 30),
(2, "1-2-18", "up", 33),
(3, "1-2-18", "dlh", 25)
).toDF("code", "date", "location", "temperature")
val refrenceDetails = Seq(
(1, "1-1-19", "blr"),
(2, "1-2-18", "up")).
toDF("code", "date", "location")
// action
val joined = details.alias("d").join(refrenceDetails.alias("r"), Seq("code"), "left")
val validDetails = joined.where($"r.code".isNotNull)
val invalidDetails = joined.where($"r.code".isNull)
// display
validDetails.show(false)
invalidDetails.show(false)
Вывод:
+----+------+--------+-----------+------+--------+
|code|date |location|temperature|date |location|
+----+------+--------+-----------+------+--------+
|1 |1-1-19|blr |30 |1-1-19|blr |
|2 |1-2-18|up |33 |1-2-18|up |
+----+------+--------+-----------+------+--------+
+----+------+--------+-----------+----+--------+
|code|date |location|temperature|date|location|
+----+------+--------+-----------+----+--------+
|3 |1-2-18|dlh |25 |null|null |
+----+------+--------+-----------+----+--------+