Earn recognition and rewards for your Microsoft Fabric Community contributions and become the hero our community deserves.
Learn moreBecome a Certified Power BI Data Analyst! Prepare for Exam PL-300 with expert-led live sessions. Get registered!
Hi,
I have a table in a lakehouse and this table is loaded to a python notebook within Fabric.
The data is manipulated in python and then I am writing back updated data as a file in my lakehouse.
What I want to do next, but I am failing, is to delete the old table in my lakehouse and create a new one from the updated file.
Please see below the steps that the notebook is executing:
1. Loads data (table) from a Lakehouse.
Solved! Go to Solution.
Hi, I found a solution, but in pyspark.
I was unable to find a way to do what I wanted via python.
Once I've updated the user defined function, I was able to drop the existing table and save a new version.
Some of code I used matches with the code posted by @andrewsommer .
spark.sql("DROP TABLE IF EXISTS LakehouseName.MyTableName")
df.write.mode("overwrite").format("delta").saveAsTable("MyTableName")
Hi, I found a solution, but in pyspark.
I was unable to find a way to do what I wanted via python.
Once I've updated the user defined function, I was able to drop the existing table and save a new version.
Some of code I used matches with the code posted by @andrewsommer .
spark.sql("DROP TABLE IF EXISTS LakehouseName.MyTableName")
df.write.mode("overwrite").format("delta").saveAsTable("MyTableName")
Hi, thanks for the detailed information.
However, the notebook is in python and I am using python libraries and functions that don't run in Spark.
I am trying to perform the steps you have described above using python.
Unfortunutely, I can't execute what I am after in spark.. I have tried to re-write the code, but I have lack of knowledge to do so.
Thanks,
Maria
Hi @mtomova,
Thanks @andrewsommer for Addressing the issue.
we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.
Regards,
Vinay Pabbu
Hi,
I am using python and the steps @andrewsommer has provided, although super detailed and clear, are not working in my case.
When I try to run my function it is failing, because I have used Python syntax and I am unable to re-write it in pyspark.
Is there a way to perform the automation I need using Python or Fabric does not support that and I need to use pyspark?
Thanks,
Maria
You’re on the right track
CopyEdit
df = spark.read.table("LakehouseName.TableName")
CopyEdit
df_updated = your_transformation_function(df)
CopyEdit
output_path = "Files/your_path/new_table_data"
df_updated.write.format("delta").mode("overwrite").save(f"lakehouse:///path/{output_path}")
CopyEdit
spark.sql("DROP TABLE IF EXISTS LakehouseName.TableName")
Create a New Table from the Delta File
CopyEdit
spark.sql(f"""
CREATE TABLE LakehouseName.TableName
USING DELTA
LOCATION 'lakehouse:///path/{output_path}'
""")
Please mark this post as solution if it helps you. Appreciate Kudos.
User | Count |
---|---|
67 | |
42 | |
12 | |
10 | |
3 |
User | Count |
---|---|
86 | |
60 | |
15 | |
8 | |
8 |