是否可以将 .yaml 文件加载到 Azure Synapse Sparkr Notebook 中?如何加载包含 ADLS Gen2 目录中的凭据的 .yaml 文件?
如果您的 ADLS gen 2 帐户是突触工作区的主要 ADLS 帐户,那么您无需安装即可访问该帐户。否则,安装帐户并使用以下代码读取将凭据写入突触笔记本中的数据帧的.yaml文件:
import yaml
from pyspark.sql import SparkSession
# Read the YAML file as text
yaml_file_path = "abfss://<containerName>@<adlsName>.dfs.core.windows.net/inp/cred.yml"
yaml_rdd = spark.sparkContext.textFile(yaml_file_path)
# Parse the YAML content
yaml_content = yaml_rdd.collect()
yaml_docs = list(yaml.safe_load_all("\n".join(yaml_content)))
# Convert each document into a DataFrame and union them
yaml_dfs = [spark.createDataFrame([doc]) for doc in yaml_docs]
yaml_df = yaml_dfs[0]
for df in yaml_dfs[1:]:
yaml_df = yaml_df.union(df)
# Display the DataFrame
yaml_df.show()
它将给出以下数据框作为输出: