[英]List files in a blob storage container using spark activity in Azure Data Factory V2
[英]Pass parameters/arguments to HDInsight/Spark Activity in Azure Data Factory
我有一個按需 HDInsight 群集,它從 Azure 數據工廠中的 Spark Activity 啟動並運行 PySpark 3.1。 為了測試我的代碼,我通常從創建的 HDInsight 群集頁面啟動 Jupyter Notebook。
現在,我想將一些參數傳遞給該 Spark 活動,並從 Jupyter 筆記本代碼中檢索這些參數。 我嘗試過兩種方法,但沒有一種方法對我有用:
方法 A. as Arguments 然后嘗試使用sys.argv[]
檢索它們。
方法 B.作為 Spark 配置,然后嘗試使用sc.getConf().getAll()
檢索它們。
我懷疑要么:
*.py
腳本有效,但不適用於 Jupyter 筆記本。任何有關如何將參數傳遞到 Azure 數據工廠中的 HDInsight Spark 活動的指針將不勝感激。
問題在於entryFilePath
。 在 HDInsight 群集的Spark
活動中,您必須將entryFilePath
作為.jar 文件或.py 文件提供。 當我們遵循這一點時,我們可以成功通過 arguments ,可以使用sys.argv
使用它。
nb1.py
(示例)內的代碼如下所示:from pyspark import SparkContext
from pyspark.sql import *
import sys
sc = SparkContext()
sqlContext = HiveContext(sc)
# Create an RDD from sample data which is already available
hvacText = sc.textFile("wasbs:///HdiSamples/HdiSamples/SensorSampleData/hvac/HVAC.csv")
# Create a schema for our data
Entry = Row('Date', 'Time', 'TargetTemp', 'ActualTemp', 'BuildingID')
# Parse the data and create a schema
hvacParts = hvacText.map(lambda s: s.split(',')).filter(lambda s: s[0] != 'Date')
hvac = hvacParts.map(lambda p: Entry(str(p[0]), str(p[1]), int(p[2]), int(p[3]), int(p[6])))
# Infer the schema and create a table
hvacTable = sqlContext.createDataFrame(hvac)
hvacTable.registerTempTable('hvactemptable')
dfw = DataFrameWriter(hvacTable)
#using agrument from pipeline to create table.
dfw.saveAsTable(sys.argv[1])
Jupyter notebook
中查詢此表:select * from new_hvac
筆記:
因此,請確保您將 arguments 傳遞給 python 腳本(.py 文件),而不是 python 筆記本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.