Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fabric notebook scripts #229

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions fabric/CopyBusinessCentral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"spark.conf.set(\"spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version\", \"2\")\n",
"spark.conf.set(\"spark.sql.delta.commitProtocol.enabled\", \"true\")\n",
"spark.conf.set(\"spark.sql.analyzer.maxIterations\", \"999\")\n",
"spark.conf.set(\"spark.sql.caseSensitive\", \"true\")\n",
"\n",
"# file paths\n",
"folder_path_spark = 'Files/deltas/' # this is mostly the default\n",
Expand All @@ -67,12 +68,12 @@
"\n",
"# parameters\n",
"workspace = 'businessCentral' #can also be a GUID\n",
"Lakehouse = 'businessCentral'; #can also be a GUID\n",
"Lakehouse = 'businessCentral'; #can also be a GUID - if you do please add back-quotes around the GUID for example: '`GUID`'\n",
"Remove_delta = True; #will remove the delta files if everything is processed\n",
"Drop_table_if_mismatch = False; #option to drop the table if json file has different columns then in the table\n",
"no_Partition = 258 #how many partition is used in the dataframe, a good starting point might be 2-4 partitions per CPU core in your Spark cluster\n",
"DecimalFormat = 'float' #how to format the decimal numbers, can be 'float' or 'decimal(10,3)'. If you change this it will be a breaking change for the table\n",
"DateTimeFormat = 'date' #how to format the datetime, can be 'timestamp' or 'date'. If you change this it will be a breaking change for the table\n",
"DateTimeFormat = 'timestamp' #how to format the datetime, can be 'timestamp' or 'date'. If you change this it will be a breaking change for the table\n",
"schema_name = \"\" #for if you are using a lakehouse based on a schema"
]
},
Expand Down Expand Up @@ -105,7 +106,7 @@
"\n",
" if table_name in [t.name for t in spark.catalog.listTables()]:\n",
" #count number of columns in excisting table\n",
" SQL_Query = \"SELECT TOP 1 * FROM \" + Lakehouse +\".\"+table_name; \n",
" SQL_Query = \"SELECT * FROM \" + Lakehouse +\".\"+table_name + \" LIMIT 1\"; \n",
" df = spark.sql(SQL_Query)\n",
" num_cols_table = len(df.columns) \n",
"\n",
Expand Down Expand Up @@ -237,9 +238,9 @@
" df_new = df_new.withColumn(col_name, df_new[col_name].cast(col_type))\n",
"\n",
" #check if the table exists\n",
" if table_name.lower() in [t.name.lower() for t in spark.catalog.listTables()]:\n",
" if table_name in [t.name for t in spark.catalog.listTables()]:\n",
" #read the old data into a new dataframe and union with the new dataframe\n",
" SQL_Query = \"SELECT * FROM \" + Lakehouse +\".\"+table_name.lower(); \n",
" SQL_Query = \"SELECT * FROM \" + Lakehouse +\".\"+table_name; \n",
" #print(SQL_Query)\n",
" df_old = spark.sql(SQL_Query)\n",
" df_new = df_new.union(df_old).repartition(no_Partition)\n",
Expand Down
Loading