Your notebook currently returns a dictionary. You need to modify it to loop through the dictionary and execute SQL commands to create external tables :
from notebookutils import mssparkutils
def main():
file_dict = {}
for sub_folder in SUB_FOLDERS:
file_name = get_most_recent_parquet_file(sub_folder)
recent_file_path = file_name
file_dict[sub_folder] = recent_file_path
for table_name, file_location in file_dict.items():
create_external_table(table_name, file_location)
mssparkutils.notebook.exit(file_dict)
def create_external_table(table_name, file_location):
sql_script = f"""
CREATE EXTERNAL TABLE {table_name} (
-- Define your schema here
column1 STRING,
column2 INT,
...
)
WITH (
LOCATION = '{file_location}',
DATA_SOURCE = your_data_source, -- here you refer your external data source
FILE_FORMAT = your_file_format -- and here to your file format
);
"""
# Execute the SQL script
mssparkutils.sql.execute(sql_script)
SUB_FOLDERS = [...]
main()
Just before running the notebook, make you have created an external data source and file format in your Azure Synapse SQL pool.