anu*_*rag 7 hive azure external-tables databricks azure-databricks
我是 azure databricks 的新手,并尝试创建一个指向 Azure Data Lake Storage (ADLS) Gen-2 位置的外部表。
从 databricks 笔记本中,我尝试为 ADLS 访问设置 spark 配置。我仍然无法执行创建的 DDL。
注意:对我有用的一种解决方案是将 ADLS 帐户安装到集群,然后使用外部表的 DDL 中的安装位置。但是我需要检查是否可以使用没有安装位置的 ADLS 路径创建外部表 DDL。
# Using Principal credentials
spark.conf.set("dfs.azure.account.auth.type", "OAuth")
spark.conf.set("dfs.azure.account.oauth.provider.type", "ClientCredential")
spark.conf.set("dfs.azure.account.oauth2.client.id", "client_id")
spark.conf.set("dfs.azure.account.oauth2.client.secret", "client_secret")
spark.conf.set("dfs.azure.account.oauth2.client.endpoint",
"https://login.microsoftonline.com/tenant_id/oauth2/token")
Run Code Online (Sandbox Code Playgroud)
数据线
create external table test(
id string,
name string
)
partitioned by (pt_batch_id bigint, pt_file_id integer)
STORED as parquet
location 'abfss://container@account_name.dfs.core.windows.net/dev/data/employee
Run Code Online (Sandbox Code Playgroud)
收到错误
Error in SQL statement: AnalysisException: org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Got exception: shaded.databricks.v20180920_b33d810.org.apache.hadoop.fs.azurebfs.contracts.exceptions.ConfigurationPropertyNotFoundException Configuration property account_name.dfs.core.windows.net not found.);
Run Code Online (Sandbox Code Playgroud)
我需要帮助知道这是否可以直接在 DDL 中引用 ADLS 位置?
谢谢。
如果您可以使用 Python(或 Scala),就可以了。
首先建立连接:
TenantID = "blah"
def connectLake():
spark.conf.set("fs.azure.account.auth.type", "OAuth")
spark.conf.set("fs.azure.account.oauth.provider.type", "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
spark.conf.set("fs.azure.account.oauth2.client.id", dbutils.secrets.get(scope = "LIQUIX", key = "lake-sp"))
spark.conf.set("fs.azure.account.oauth2.client.secret", dbutils.secrets.get(scope = "LIQUIX", key = "lake-key"))
spark.conf.set("fs.azure.account.oauth2.client.endpoint", "https://login.microsoftonline.com/"+TenantID+"/oauth2/token")
connectLake()
lakePath = "abfss://liquix@mystorageaccount.dfs.core.windows.net/"
Run Code Online (Sandbox Code Playgroud)
使用 Python,您可以使用以下方法注册表:
spark.sql("CREATE TABLE DimDate USING PARQUET LOCATION '"+lakePath+"/PRESENTED/DIMDATE/V1'")
Run Code Online (Sandbox Code Playgroud)
如果您已执行 connectLake() 函数,您现在可以查询该表 - 这在您当前的会话/笔记本中没问题。
现在的问题是,如果有新会话进入并且他们尝试从该表中选择 * ,除非他们首先运行 connectLake() 函数,否则它将失败。没有办法绕过这个限制,因为你必须证明访问该湖的凭据。
您可能需要考虑 ADLS Gen2 凭据传递:https://docs.azuredatabricks.net/spark/latest/data-sources/azure/adls-passthrough.html
请注意,这需要使用高并发集群。
| 归档时间: |
|
| 查看次数: |
5148 次 |
| 最近记录: |