【问题标题】:How to check Azure blob storage path exists or not using scala spark or python spark如何使用 scala spark 或 python spark 检查 Azure blob 存储路径是否存在
【发布时间】:2019-10-04 15:08:01
【问题描述】:

请告诉我如何检查以下 blob 文件是否存在。

文件路径名:“wasbs://containername@storageaccountname.blob.core.windows.net/directoryname/meta_loaddate=20190512/”

【问题讨论】:

  • 提供的答案对您有帮助吗?如果是,请标记为已回答,以帮助社区找到相关答案。

标签: scala azure pyspark blob azure-blob-storage


【解决方案1】:

以下是适合您的代码,您可以根据需要随意编辑/自定义:

  from azure.storage.blob import BlockBlobService

session = SparkSession.builder.getOrCreate() #setup spark session
    session.conf.set("fs.azure.account.key.storage-account-name.blob.core.windows.net","<storage-account-key>")
    sdf = session.read.parquet("wasbs://<container-name>@<storage-account-name>.blob.core.windows.net/<prefix>")

    block_blob_service = BlockBlobService(account_name='', account_key='')

    def blob_exists():

            container_name = ""
            blob_name = ""

            exists=(block_blob_service.exists(container_name, blob_name))
            return exists
    blobstat = blob_exists()
    print(blobstat)# will return a boolean if the blob exists = True, else False

【讨论】:

    【解决方案2】:
    private val storageConnectionString = s"DefaultEndpointsProtocol=http;AccountName=$account;AccountKey=$accessKey"
    
    private val cloudStorageAccount = CloudStorageAccount.parse(storageConnectionString)
    
    private val serviceClient = cloudStorageAccount.createCloudBlobClient
    
    private val container = serviceClient.getContainerReference("data")
    
    val ref = container.getBlockBlobReference(path)
    val existOrNot = ref.exist()
    

    【讨论】:

      猜你喜欢
      • 2018-12-24
      • 1970-01-01
      • 2013-07-05
      • 2011-02-08
      • 2014-02-06
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      相关资源
      最近更新 更多