Search code examples
scalaapache-sparkazure-databricks

How to execute SQL scripts using azure databricks


I have one SQL scripts file In that file there is some sql query I want to upload it on dbfs and read it from azure databricks and execute querys from the script on azure databricks


Solution

  • Databricks does not directly support the execution of .sql files. However you could just read them into a string and execute them.

    with open("/dbfs/path/to/query.sql") as queryFile:
       queryText = queryFile.read()
    results = spark.sql(queryText)