cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

SCD Type-2

sudhanshu1
New Contributor III

Hi All,

I have 22 postgress tables and i need to implement SCD type 2 and create azure Databricks pipeline . However my project team doesn't want to use delta tables concept . Have anyone implemented this ? below is how i planned to do

try:

 df_src = spark.read.jdbc(url=jdbcUrl_source, table="data_table_1", properties=connectionProperties)

except Exception as e:

 print("not able to connect")

 print(f"Error is :{e}")

 raise Exception

try:

 data_table_1_target_df = spark.read.jdbc(url=jdbcUrl_target, table="data_table_1", properties=connectionProperties)

except Exception as e:

 print("Target path not found")

 print(f"Error is :{e}")

 raise Exception

merged_data_df = spark.sql("""

  MERGE INTO target_table AS t

  USING scd_data AS s

  ON t.id = s.id

  WHEN MATCHED AND t.status = TRUE THEN

   UPDATE SET

    t.effective_to_date = s.start_date,

    t.status = FALSE

  WHEN NOT MATCHED THEN

   INSERT (id, cus_name, age, effective_from_date, effective_to_date, status)

   VALUES (s.id, s.cus_name, s.age, s.start_date, s.end_date, s.is_active)

""")

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group