我想通过 TiSpark 将我的 Spark 集群连接到 TIDB,但是当我运行我的 Spark 应用程序时遇到问题,出现错误:
java.io.InvalidClassException: com.pingcap.tikv.region.TiRegion; 本地类不兼容:流 classdesc serialVersionUID = -3091715739322916126,本地类 serialVersionUID = -3556238418089320368
我正在按照https://pingcap.com/docs/v3.0/how-to/get-started/deploy-tidb-from-binary/上的指南设置 TIDB 集群
之后,我按照https://pingcap.com/docs/v3.0/reference/tispark/上的指南下载 tispark-core-2.2.0-SNAPSHOT-jar-with-dependencies.jar 并将其复制到我的 jar Spark 中的文件夹。
我还配置: spark.tispark.pd.addresses 127.0.0.1:2379 spark.sql.extensions org.apache.spark.sql.TiExtensions
这是我的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.vng</groupId>
<artifactId>testlan102</artifactId>
<version>1.0-SNAPSHOT</version>
<inceptionYear>2019</inceptionYear>
<properties>
<scala.version>2.11.12</scala.version>
<spark.version>2.4.3</spark.version>
</properties>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_2.11</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.11</artifactId>
<version>2.4.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.pingcap.tispark</groupId>
<artifactId>tispark-core</artifactId>
<version>2.1.1-spark_2.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.12</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.5</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<buildcommands>
<buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<additionalProjectnatures>
<projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
我的 Spark 会话是:
val _spark = SparkSession.builder()
.master("spark://127.0.0.1:7077")
.config("spark.tispark.pd.addresses", "127.0.0.1:2379")
.config("spark.sql.extensions","org.apache.spark.sql.TiExtensions")
.appName("SparkApp")
.getOrCreate()
当我对数据库调用一个简单的查询时:
_spark.sql("use locdb")
val df = _spark.sql("select * from bang")
df.show()
我收到一个错误:java.io.InvalidClassException: com.pingcap.tikv.region.TiRegion; 本地类不兼容:流 classdesc serialVersionUID = -3091715739322916126,本地类 serialVersionUID = -3556238418089320368
我的完整日志在这里: https ://gist.github.com/lploc94/bb6bf9db14c030ee123630f6362f6160
我认为原因是我在 maven pom 文件中使用了 TiSpark 2.1.1-2.4,但我下载并复制到 jars 文件夹的 Tispark jar 文件是 2.2.0。但我看不到任何其他版本的 TiSpark,例如 tispark-core-2.1.1-SNAPSHOT-jar-with-dependencies.jar