gpt4 book ai didi

scala - 为什么 "java.lang.ClassNotFoundException: Failed to find data source: kinesis"具有 spark-streaming-kinesis-asl 依赖性?

转载 作者:行者123 更新时间:2023-12-05 06:29:24 26 4
gpt4 key购买 nike

我的设置:

  scala:2.11.8
spark:2.3.0.cloudera4

我已经在我的 .pom 文件中添加了:

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kinesis-asl_2.11</artifactId>
<version>2.3.0</version>
</dependency>

但是,当我运行我的 spark-streaming 代码以使用来自 kinesis 的数据时,它返回:

Exception in thread "main" java.lang.ClassNotFoundException: Failed to find data source: kinesis.

当我从 Kafka 消费数据时,我遇到了类似的错误,并通过在提交命令中指示依赖的 jar 来解决它。但这次似乎不起作用:

sudo -u hdfs spark2-submit --packages org.apache.spark:spark-streaming-kinesis-asl_2.11:2.3.0 --class com.package.newkinesis --master yarn  sparktest-1.0-SNAPSHOT.jar 

如何解决这个问题?感谢您的帮助。

我的代码:

val spark = SparkSession
.builder.master("local[4]")
.appName("SpeedTester")
.config("spark.driver.memory", "3g")
.getOrCreate()

val kinesis = spark.readStream
.format("kinesis")
.option("streamName", kinesisStreamName)
.option("endpointUrl", kinesisEndpointUrl)
.option("initialPosition", "TRIM_HORIZON")
.option("awsAccessKey", awsAccessKeyId)
.option("awsSecretKey", awsSecretKey)
.load()

kinesis.writeStream.format("console").start().awaitTermination()

我的完整 .pom 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.netease</groupId>
<artifactId>sparktest</artifactId>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<properties>
<scala.version>2.11.8</scala.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<includes>
<include>org/apache/spark/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<scope>provided</scope>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.11</artifactId>
<scope>provided</scope>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<scope>provided</scope>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_2.11</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kinesis-asl_2.11</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</project>

最佳答案

tl;dr 它不会起作用。

您将 spark-streaming-kinesis-asl_2.11 依赖项用于旧的 Spark Streaming API 和新的 Spark Structured Streaming,因此异常(exception)。

您必须为 AWS Kinesis 找到一个兼容的 Spark Structured Streaming 数据源,它不受 Apache Spark 项目的正式支持。

关于scala - 为什么 "java.lang.ClassNotFoundException: Failed to find data source: kinesis"具有 spark-streaming-kinesis-asl 依赖性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53534395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com