简体   繁体   English

pandas to_csv function 从 Spark UDF 调用时不写入 Blob 存储

[英]pandas to_csv function not writing to Blob Storage when called from Spark UDF

I am using a Spark UDF to read some data from a GET endpoint and write them as a CSV file to a Azure BLOB location.我正在使用 Spark UDF 从 GET 端点读取一些数据并将它们作为 CSV 文件写入 Azure BLOB 位置。

My GET endpoint takes 2 query parameters,param1 and param2.我的 GET 端点采用 2 个查询参数,param1 和 param2。 So initially, I have a dataframe paramDF that has two columns param1 and param2.所以最初,我有一个 dataframe paramDF,它有两列 param1 和 param2。

param1   param2
12        25
45        95

Schema:    paramDF:pyspark.sql.dataframe.DataFrame
           param1:string
           param2:string

Now I write a UDF that accept the two parameters, register it, and then invoke this UDF for each row in the dataframe. UDF is as below:现在我写了一个接受这两个参数的UDF,注册它,然后为dataframe中的每一行调用这个UDF。UDF如下:

    def executeRestApi(param1,param2):
      dlist=[]
      try:
        print(DataUrl.format(token=TOKEN, q1=param1,q2=param2))
        response=requests.get(DataUrl.format(token=TOKEN, oid=param1,wid=param2))
        if(response.status_code==200):
          metrics=response.json()['data']['metrics']
          dic={}
          dic['metric1'] = metrics['metric1']
          dic['metric2'] = metrics['metric2']
          dlist.append(dic)
        
    pandas.DataFrame(dlist).to_csv("../../dbfs/mnt/raw/Important/MetricData/listofmetrics.csv",header=True,index=False,mode='x')
    return "Success"
          
   except Exception as e:
        return "Failure"

Register the UDF:注册 UDF:

udf_executeRestApi = udf(executeRestApi, StringType())

Finally the call the UDF this way最后以这种方式调用 UDF

paramDf.withColumn("result",udf_executeRestApi(col("param1"),col("param2"))

I dont see any errors while calling the UDF, in fact the UDF returns the value "Success" correctly.我在调用 UDF 时没有看到任何错误,实际上 UDF 正确返回值“Success”。 Only thing is that the files are not written to Azure BLOB storage, no matter what I try.唯一的问题是文件没有写入 Azure BLOB 存储,无论我尝试什么。 UDFs' are primarily meant for custom functionality(and return a value).However,in my case, I am trying to execute the GET API call and the write operation using the UDF(and that is my main intention here). UDF' 主要用于自定义功能(并返回一个值)。但是,就我而言,我正在尝试使用 UDF 执行 GET API 调用和写入操作(这是我的主要意图)。

There is no issue with my pandas.DataFrame().tocsv(),as the same line, when tried separately,with a simple list is writing data to the BLOB correctly.我的 pandas.DataFrame().tocsv() 没有问题,因为同一行,当单独尝试时,使用一个简单的列表正确地将数据写入 BLOB。

What could be going wrong here?这里可能出了什么问题?

Note: Env is Spark on Databricks.注意:Env 是 Databricks 上的 Spark。 There isn't any problem with the indentation, even though it looks untidy here.缩进没有任何问题,尽管它在这里看起来不整洁。

Try calling display on the dataframe尝试在 dataframe 上调用display

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure function C#:写入 Azure 上的块 blob(csv 文件)存储帐户创建了两个版本的 blob - Azure function C#: Writing to Block blob (csv file) on Azure Storage Account creates two versions of the blob pandas to_csv 到 S3 的 CreateBucket 权限出现 AccessDenied 错误 - AccessDenied error from CreateBucket Permissions for pandas to_csv to S3 将 CSV 从 Azure Automation 导出到 Microsoft Teams 而不是 blob 存储? - Export a CSV from Azure Automation to Microsoft Teams instead of blob storage? 从笔记本电脑 spark 读取 Azure blob 存储中的文件时出错 - Error in reading files in Azure blob storage from laptop spark 用于将 csv 个文件从 sftp 服务器复制到 blob 存储的数据集格式 - Dataset format for copying csv files from a sftp server to blob storage 无法将 csv 文件上传到 azure 存储 blob - Not able to uploading csv file to azure storage blob 如何使用 Airflow 将 CSV 文件从 Azure Data Lake/Blob 存储传输到 PostgreSQL 数据库 - How to transfer a CSV file from Azure Data Lake/Blob Storage to PostgreSQL database with Airflow 并行化 MLflow 项目在 Azure Databricks Spark 上使用 Pandas UDF 运行 - Parallelize MLflow Project runs with Pandas UDF on Azure Databricks Spark HTTP 触发器 azure function 从 blob 存储错误获取图像 - HTTP trigger azure function get image from blob storage error 从事件网格触发的 function 访问存储容器中的 blob - Access blob in storage container from function triggered by Event Grid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM