如何在Synapse(托管专用端点)中读取excel文件?

问题描述 投票:0回答:1

使用 Azure Synapse,我有一个笔记本,可以在其中读取位于 Azure Data Lake 中的 excel 文件。

通常它有效,改变的是现在我使用托管专用端点。

启动笔记本时出现错误:


ServiceRequestError: Cannot connect to host adlsdev.blob.core.windows.net:443 ssl:True [Name or service not known]

我尝试了以下方法(之前有效):

pd.read_excel('abfss://[email protected]/test/test1.xlsx')

我可以在 Synapse 中做什么?

azure-synapse azure-data-lake
1个回答
0
投票

要在 Synapse(托管专用端点)中读取 excel 文件,您需要使用链接服务。

  • 使用启用(托管专用端点)的集成运行时在存储帐户上创建链接服务

enter image description here

  • 批准特定存储帐户上的托管专用端点,如下所示

enter image description here

  • 然后从该 Microsoft doc 的突触笔记本中执行以下代码,以使用链接服务从 ADLS 读取文件。
%%pyspark
# Set the required configs
source_full_storage_account_name = "Storage_account_name.dfs.core.windows.net"
spark.conf.set(f"spark.storage.synapse.{source_full_storage_account_name}.linkedServiceName", "Linked_ervice_name")
sc._jsc.hadoopConfiguration().set(f"fs.azure.account.auth.type.{source_full_storage_account_name}", "SAS_Token")
sc._jsc.hadoopConfiguration().set(f"fs.azure.sas.token.provider.type.{source_full_storage_account_name}", "com.microsoft.azure.synapse.tokenlibrary.LinkedServiceBasedSASProvider")

import pandas as pd
# Python code
df = pd.read_excel('abfss://Container_name@Storage_account_name.dfs.core.windows.net/file.xlsx')
print(df)

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.