How to identify all columns that have different values in a Spark self-join

Viewed 15

I have a Databricks delta table of financial transactions that is essentially a running log of all changes that ever took place on each record. Each record is uniquely identified by 3 keys. So given that uniqueness, each record can have multiple instances in this table. Each representing a historical entry of a change(across one or more columns of that record) Now if I wanted to find out cases where a specific column value changed I can easily achieve that by doing something like this -->

SELECT t1.Key1, t1.Key2, t1.Key3, t1.Col12 as "Before", t2.Col12 as "After" from table1 t1 inner join table t2 on t1.Key1= t2.Key1 and t1.Key2 = t2.Key2 and t1.Key3 = t2.Key3 where t1.Col12 != t2.Col12

However, these tables have a large amount of columns. What I'm trying to achieve is a way to identify any columns that changed in a self-join like this. Essentially a list of all columns that changed. I don't care about the actual value that changed. Just a list of column names that changed across all records. Doesn't even have to be per row. But the 3 keys will always be excluded, since they uniquely define a record.

Essentially I'm trying to find any columns that are susceptible to change. So that I can focus on them dedicatedly for some other purpose.

Any suggestions would be really appreciated.

0 Answers
Related