Complete the load.. If file not available databricks notebbok

Shambhu Rai 1,406 Reputation points
2023-12-18T04:01:30.12+00:00

Hi If there is no file in blob storage then it should complete the flow in data bricks notebook That means sometimes file is available and not in blob storage mnt/test/ empty folder... In this case flow should complete. . Files like CSV,. Txt

Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,409 questions
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.
501 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,042 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,994 questions
0 comments No comments
{count} votes

Accepted answer
  1. PRADEEPCHEEKATLA-MSFT 84,051 Reputation points Microsoft Employee
    2023-12-18T10:11:19.4066667+00:00

    @Shambhu Rai - Thanks for the question and using MS Q&A platform.

    Based on the provided information, it seems like you want to complete the flow in Databricks notebook if there is no file in blob storage. If I understand correctly, you want to know how to handle this scenario.

    If the file is not available in the blob storage, you can use the dbutils.fs.ls command to check if the file exists in the mounted directory. If the directory is empty, you can complete the flow in the Databricks notebook. Here is an example code snippet that you can use to achieve this:

    import os
    from pyspark.sql import SparkSession
    
    # Check if the file exists in the mounted directory
    if len(dbutils.fs.ls("/mnt/test/")) == 0:
      print("No files found in the mounted directory. Completing the flow in Databricks notebook.")
      # Add your code to complete the flow in Databricks notebook here
    else:
      # Load the file from the blob storage
      spark = SparkSession.builder.appName("Read CSV").getOrCreate()
      df = spark.read.format("csv").option("header", "true").load("wasbs://container@account.blob.core.windows.net/path/to/file.csv")
      # Add your code to process the file here
    

    In this example, we first check if the mounted directory /mnt/test/ is empty using the dbutils.fs.ls command. If the directory is empty, we print a message saying that no files were found and complete the flow in the Databricks notebook. If the directory is not empty, we load the file from the blob storage using the SparkSession and process the file as required.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful