Load files in appending in databricks

Shambhu Rai 1,411 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.
537 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,285 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,048 questions
Azure Data Lake Analytics
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Subashri Vasudevan 11,206 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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.