Load files in appending in databricks

Shambhu Rai 1,406 Reputation points
2023-11-29T05:48:38.4166667+00:00

Hi Expert,

I have 2 files in blob storage .

file1.csv, file2.csv

how will i load it in a view using appending order using *.csv extension using temp view

file_list = dbutils.fs.ls("/mnt/mount/test/file")
Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
480 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
1,926 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,570 questions
Azure Data Lake Analytics
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Suba Balaji 11,186 Reputation points
    2023-11-29T09:53:05.2066667+00:00

    Hi,

    You can try the below code - (I am assuming, the files are under test/file folder)

    final_files_list=[]
    file_list = dbutils.fs.ls("/mnt/mount/test/file")
    for file in file_list:
      final_files_list.append(file.name)
    df = spark.read.load(path=final_files_list,format="csv", sep=",", inferSchema="true", header="true")
    df.createOrReplaceTempView("TestFiles") 
    

    We are creating a pyspark data frame from the given csv files, and convert that to a temp view called TestFiles.

    Please try and let us know for questions.

    Thanks