簡體   English   中英

將參數從 adf 傳遞到筆記本

[英]passing the parameters from adf to notebook

我正在通過 api 調用獲取數據,並希望對widgets進行參數化。 在 azure 中,我進行了以下設置: 在此處輸入圖像描述

我有attribute_code的列表,使用lookup活動讀取它們並將這些參數傳遞到數據塊筆記本代碼中。 數據塊中的代碼:

data, response = get_data_url(url=f"https://p.cloud.com/api/rest/v1/attributes/{attribute_code}/options",access_token=access_token)
#Removing the folder in Data Lake
dbutils.fs.rm(f'/mnt/bronze/attribute_code/{day}',True)
#Creating the folder in the Data Lake
dbutils.fs.mkdirs(f'/mnt/bronze/attribute_code/{day}')

count = 0
#Putting the response inside of the Data Lake folder
dbutils.fs.put(f'/mnt/bronze/attribute_code/{day}/data_{count}.json', response.text)

我的問題是,由於它在ForEach循環中,每次傳遞新參數時,它都會刪除包含先前加載數據的整個文件夾。 現在有人可以說要刪除我放置的行並創建 spacific daily 文件夾,但管道應該每天運行多次,我需要在那天刪除以前加載的數據並加載新數據。

我的目標是迭代整個attribute_code列表並將它們全部加載到一個名為“data_{count}.json”的文件夾中

  • 除了在筆記本中使用dbutils.fs.rm ,您還可以對每個活動使用 delete activity before 以獲得所需的結果。

  • 使用dbutils.fs.rm ,每次在內部觸發筆記本時都會刪除該文件夾,因為每個循環也會刪除以前創建的文件。

  • 因此,僅在每個循環之前使用刪除活動來刪除文件夾(僅在存在時刪除),您可以根據需要加載數據。

在此處輸入圖像描述

  • 對於路徑,我使用了以下動態內容:
attribute/@{formatDateTime(utcNow(),'yyyy-MM-dd')}

在此處輸入圖像描述

  • 並在我的數據塊筆記本中使用以下代碼:
#I used similar code
data, response = get_data_url(url=f"https://p.cloud.com/api/rest/v1/attributes/{attribute_code}/options",access_token=access_token)


#Creating the folder in the Data Lake
dbutils.fs.mkdirs(f'/mnt/bronze/attribute_code/{day}')

count = 0
#Putting the response inside of the Data Lake folder
dbutils.fs.put(f'/mnt/bronze/attribute_code/{day}/data_{count}.json', response.text)
  • 假設我的查找活動中有以下 output:

在此處輸入圖像描述

  • 當我運行管道時,它會成功運行。 只會加載最新的查找數據。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM