Created
December 29, 2021 15:40
-
-
Save pietheinstrengholt/bee6a0091365ef634a71ee19d7957467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%pyspark | |
| from datetime import date | |
| current_date = datetime.today().date() | |
| try: | |
| # Read original data - this is your scd type 2 table holding all data | |
| dataOriginal = spark.read.load(dfDataOriginalPath + "/" + cw_database + "/" + cw_table, format='delta') | |
| except: | |
| # Use first load when no data exists yet | |
| newOriginalData = dataChanged.withColumn('current', lit(True)).withColumn('effectiveDate', lit(current_date)).withColumn('endDate', lit(date(9999, 12, 31))) | |
| newOriginalData.write.format("delta").mode("overwrite").save(dfDataOriginalPath + "/" + cw_database + "/" + cw_table) | |
| newOriginalData.show() | |
| newOriginalData.printSchema() | |
| exit("Done loading data! Newly loaded data will be used to generate original data.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment