【发布时间】: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