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

Refactor file handling and table saving logic in CopyBusinessCentral.… #223

Merged
merged 1 commit into from
Jan 14, 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
10 changes: 4 additions & 6 deletions fabric/CopyBusinessCentral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@
" files_in_dir = glob.glob(folder_path + entry.name + '/*')\n",
" if not files_in_dir:\n",
" continue\n",
"\n",
" \n",
" table_name = entry.name.replace(\"-\",\"\")\n",
" ContainsCompany = False\n",
" df_new = spark.read.option(\"minPartitions\", no_Partition).format(\"csv\").option(\"header\",\"true\").load(folder_path_spark + entry.name +\"/*\") \n",
" file_list.extend(glob.glob(folder_path_spark + entry.name + '/*')) #collect the imported filed in a list for deletion later on\n",
"\n",
" f = open(folder_path_json + entry.name +\".cdm.json\")\n",
" schema = json.load(f)\n",
Expand Down Expand Up @@ -270,17 +269,16 @@
" if is_string_empty(schema_name):\n",
" df_new.write.mode(\"overwrite\").format(\"delta\").saveAsTable(f\"{table_name}\")\n",
" else:\n",
" df_new.write.mode(\"overwrite\").format(\"delta\").saveAsTable(f\"{schema_name}.{table_name}\")\n",
" \n",
" df_new.write.mode(\"overwrite\").format(\"delta\").saveAsTable(f\"{schema_name}.{table_name}\") \n",
"\n",
" #delete the files\n",
" if Remove_delta:\n",
" for filename in file_list: \n",
" for filename in files_in_dir:\n",
" try: \n",
" os.remove(filename) \n",
" except OSError as e: # this would catch any error when trying to delete the file \n",
" print(f\"Error: {filename} : {e.strerror}\")\n",
" file_list = [] # clear the list"
" files_in_dir = [] # clear the list"
]
}
],
Expand Down
Loading