azure - 配置独立 Spark 以进行 Azure 存储访问

标签 azure apache-spark azure-blob-storage azure-data-lake

我需要能够在本地计算机上运行 Spark 来访问 azure wasb 和 adl url,但我无法让它工作。我这里有一个精简的示例:

maven pom.xml(全新的pom,只设置了依赖):

<dependencies>
<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.11</artifactId>
  <version>2.3.0</version>
</dependency>
  <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_2.11</artifactId>
      <version>2.3.0</version>
  </dependency>
<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-common</artifactId>
  <version>2.8.0</version>
</dependency>
<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-azure-datalake</artifactId>
  <version>3.1.0</version>
</dependency>
<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-storage</artifactId>
  <version>6.0.0</version>
</dependency>
<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-data-lake-store-sdk</artifactId>
  <version>2.2.3</version>
</dependency>
<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-azure</artifactId>
  <version>3.1.0</version>
</dependency>
<dependency>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-storage</artifactId>
  <version>7.0.0</version>
</dependency>

Java 代码(不需要是 java - 可以是 scala):

import org.apache.spark.SparkConf;
import org.apache.spark.SparkContext;
import org.apache.spark.sql.SparkSession;

public class App {
    public static void main(String[] args) {
        SparkConf config = new SparkConf();
        config.setMaster("local");
        config.setAppName("app");
        SparkSession spark = new SparkSession(new SparkContext(config));
        spark.read().parquet("wasb://container@host/path");
        spark.read().parquet("adl://host/path");
    }
}

无论我尝试什么,我都会得到:

Exception in thread "main" java.io.IOException: No FileSystem for scheme: wasb

adl 也一样。我能找到的每个文档要么只是说添加 azure-storage 依赖项(我已经完成了),要么说使用 HDInsight。

有什么想法吗?

最佳答案

我想通了这一点并决定发布一个工作项目,因为这一直是我所寻找的。它托管在这里:

azure-spark-local-sample

问题的关键正如 @Shankar Koirala 所建议的:

对于 WASB,设置属性以允许识别 url 方案:

config.set("spark.hadoop.fs.wasb.impl", "org.apache.hadoop.fs.azure.NativeAzureFileSystem");

然后设置授权访问该帐户的属性。对于您需要访问的每个帐户,您都需要其中之一。这些是通过 Azure 门户的“存储帐户”边栏选项卡的“访问 key ”部分生成的。

    config.set("fs.azure.account.key.[storage-account-name].blob.core.windows.net", "[access-key]");

现在对于 adl,像 WASB 一样分配 fs 方案:

    config.set("spark.hadoop.fs.adl.impl", "org.apache.hadoop.fs.adl.AdlFileSystem");
    // I don't know why this would be needed, but I saw it
    // on an otherwise very helpful page . . .
    config.set("spark.fs.AbstractFileSystem.adl.impl", "org.apache.hadoop.fs.adl.Adl");

。 。 。最后,在这些属性中设置客户端访问 key ,再次针对您需要访问的每个不同帐户:

    config.set("fs.adl.oauth2.access.token.provider.type", "ClientCredential");

    /* Client ID is generally the application ID from the azure portal app registrations*/
    config.set("fs.adl.oauth2.client.id", "[client-id]");

    /*The client secret is the key generated through the portal*/
    config.set("fs.adl.oauth2.credential", "[client-secret]");

    /*This is the OAUTH 2.0 TOKEN ENDPOINT under the ENDPOINTS section of the app registrations under Azure Active Directory*/
    config.set("fs.adl.oauth2.refresh.url", "[oauth-2.0-token-endpoint]");

我希望这对您有所帮助,我希望我能感谢 Shankar 的回答,但我也想了解确切的细节。

关于azure - 配置独立 Spark 以进行 Azure 存储访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50454075/

相关文章:

c# - 如何在 blob 容器中使用 azure 搜索搜索最新文件中的匹配数据 C#

node.js - 在 Azure Functions 上部署 Node 应用程序

ASP.net 使用 OWIN 进行 Azure Active Directory 联合身份验证服务单点登录

azure - 在 Azure 上,我可以在 ASE 中运行 Windows Docker 容器吗?

python - Spark 创建数据帧,其中包含整数和 float 混合的列

scala - 如何在对RDD中找到最大值?

sql-server - 来自 SQL Server 的 Azure 存储中的 blob 列表

python - 如何打印 "object at somthing"的值

sql - 如何使用 Spark Scala 或 sql 对特定时间间隔内的记录进行分组?

azure - 使用 Azure 函数将文件从 Azure Blob 存储复制到 Azure 文件存储