cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

write to Delta

SSV_dataeng
New Contributor II
spark.conf.set("spark.databricks.delta.properties.defaults.columnMapping.mode","name")
products_output_path = DA.paths.working_dir + "/delta/products"
products_df.write.format("delta").save(products_output_path)
 
verify_files = dbutils.fs.ls(products_output_path)
verify_delta_format = False
verify_num_data_files = 0
for f in verify_files:
    if f.name == "_delta_log/":
        verify_delta_format = True
    elif f.name.endswith(".parquet"😞
        verify_num_data_files += 1

assert verify_delta_format, "Data not written in Delta format"
assert verify_num_data_files > 0, "No data written"
del verify_files, verify_delta_format, verify_num_data_files
print("All test pass")
 
AssertionError Traceback (most recent call last) <command-1787238488083573> in <cell line: 11>() 9 10 assert verify_delta_format, "Data not written in Delta format" ---> 11 assert verify_num_data_files > 0, "No data written" 12 del verify_files, verify_delta_format, verify_num_data_files 13 print("All test pass") AssertionError: No data written
4 REPLIES 4

daniel_sahal
Esteemed Contributor

@SSV_dataeng 
What is the question here?

1. I was trying to create a file in Delta format. After Delta File creation at the verification step getting Assertion Error: No data written.

could you please let me know how to fix this issue?

 

Lakshay
Esteemed Contributor
Esteemed Contributor

I see the error is part of the assertion part of your code. Do you see any other error when writing the data?

NandiniN
Honored Contributor
Honored Contributor

Hi @SSV_dataeng ,

Please check with this (you would have to indent it correctly for python)

productsOutputPath = DA.workingDir + "/delta/products"
(productsDF
.write
.format("delta")
.mode("overwrite")
.save(productsOutputPath)
)

verify_files = dbutils.fs.ls(productsOutputPath)
verify_delta_format = False
verify_num_data_files = 0
for f in verify_files:
if f.name == '_delta_log/':
verify_delta_format = True
elif f.name.endswith('.parquet'):
verify_num_data_files += 1

assert verify_delta_format, "Data not written in Delta format"
assert verify_num_data_files > 0, "No data written"
del verify_files, verify_delta_format, verify_num_data_files

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!