1。引用挂载目录
您可以将 Azure Data Lake Store (ADLS) 装载到 Azure Databricks DBFS(需要 4.0 运行时或更高版本):
# Get Azure Data Lake Store credentials from the secret store
clientid = dbutils.preview.secret.get(scope = "adls", key = "clientid")
credential = dbutils.preview.secret.get(scope = "adls", key = "credential")
refreshurl = dbutils.preview.secret.get(scope = "adls", key = "refreshurl")
accounturl = dbutils.preview.secret.get(scope = "adls", key = "accounturl")
# Mount the ADLS
configs = {"dfs.adls.oauth2.access.token.provider.type": "ClientCredential",
"dfs.adls.oauth2.client.id": clientid,
"dfs.adls.oauth2.credential": credential,
"dfs.adls.oauth2.refresh.url": refreshurl}
dbutils.fs.mount(
source = accounturl,
mount_point = "/mnt/adls",
extra_configs = configs)
表创建的工作方式与 DBFS 相同。只需使用 ADLS 中的目录引用挂载点,例如。 g.:
%sql
CREATE TABLE product
USING CSV
OPTIONS (header "true", inferSchema "true")
LOCATION "/mnt/adls/productscsv/"
location 子句自动暗示EXTERNAL。另见Azure Databricks Documentation。
2。直接在表定义中引用Data Lake Store
您也可以直接引用存储而不安装存储。如果元数据或部分代码也用于其他平台,则这种情况是有意义的。在这种情况下,必须在集群或笔记本级别定义对存储的访问(请参阅 Databricks documentation 了解 ADLS Gen1 或 this documentation 了解 Gen2 配置详细信息)或使用 Azure AD Credential Passthrough。
ADLS Gen1 的表定义如下所示:
CREATE TABLE sampletable
(L_ORDERKEY BIGINT,
L_PARTKEY BIGINT,
L_SUPPKEY BIGINT,
L_SHIPMODE STRING,
L_COMMENT STRING)
USING csv
OPTIONS ('DELIMITER' '|')
LOCATION "adl://<your adls>.azuredatalakestore.net/directory1/sampletable"
;
对于 Azure Data Lake Gen2,位置参考如下所示:
LOCATION "abfss://<file_system>@<account_name.dfs.core.windows.net/directory/tablename"