【问题标题】:How to return data from azure databricks notebook in Azure Data Factory如何从 Azure 数据工厂中的 azure databricks notebook 返回数据
【发布时间】:2022-02-03 13:13:56
【问题描述】:

我有一个要求,我需要在 azure databricks 中转换数据,然后返回转换后的数据。下面是我试图返回一些 json 的笔记本示例代码。

from pyspark.sql.functions import *
from pyspark.sql.types import *
import json
import pandas as pd



# Define a dictionary containing ICC rankings
rankings = {'test': ['India', 'South Africa', 'England',
                            'New Zealand', 'Australia'],
              'odi': ['England', 'India', 'New Zealand',
                            'South Africa', 'Pakistan'],
               't20': ['Pakistan', 'India', 'Australia',
                              'England', 'New Zealand']}
   
# Convert the dictionary into DataFrame
rankings_pd = pd.DataFrame(rankings)
   
# Before renaming the columns
   
rankings_pd.rename(columns = {'test':'TEST'}, inplace = True)
rankings_pd.rename(columns = {'odi':'ODI'}, inplace = True)
rankings_pd.rename(columns = {'t20':'twenty-20'}, inplace = True)  
# After renaming the columns
#print(rankings_pd.to_json())
dbutils.notebook.exit(rankings_pd.to_json())

为了达到同样的效果,我在这个笔记本的集群下创建了一个作业,然后我还必须按照这篇文章 https://medium.com/@poojaanilshinde/create-azure-logic-apps-custom-connector-for-azure-databricks-e51f4524ab27 创建一个自定义连接器。在 Azure Logic App 中使用 API 端点 '/2.1/jobs/run-now''/2.1/jobs/runs/get-output' 的连接器,我能够获得返回值,但是在作业成功执行后,有时我只是得到状态为正在运行而没有输出。当作业通过转换成功执行时,我需要获取输出。 如果我遗漏任何东西,请为此提出更好的方法。

【问题讨论】:

    标签: azure-data-factory azure-logic-apps azure-databricks


    【解决方案1】:

    看起来 dbutils.notebooks.exit() 只接受“字符串”,您可以将值作为 json 字符串返回并在 DataFactory 或 Logic App 中转换为 json 对象。 https://docs.microsoft.com/en-us/azure/databricks/dev-tools/databricks-utils#--notebook-utility-dbutilsnotebook

    【讨论】:

      猜你喜欢
      • 2020-01-06
      • 2019-09-28
      • 2019-06-08
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      • 2015-02-21
      相关资源
      最近更新 更多