尝试运行以上代码时出现此错误。
错误:
Exception:
Caused by: java.lang.ClassCastException: com.datastax.driver.core.DefaultResultSetFuture cannot be cast to shade.com.datastax.spark.connector.google.common.util.concurrent.ListenableFuture
at com.datastax.spark.connector.writer.AsyncExecutor.com$datastax$spark$connector$writer$AsyncExecutor$$tryFuture$1(AsyncExecutor.scala:38) ~[spark-cassandra-connector_2.11-2.3.1.jar:2.3.1]
at com.datastax.spark.connector.writer.AsyncExecutor.executeAsync(AsyncExecutor.scala:71) ~[spark-cassandra-connector_2.11-2.3.1.jar:2.3.1]
at com.datastax.spark.connector.writer.TableWriter$$anonfun$writeInternal$1$$anonfun$apply$2.apply(TableWriter.scala:234) ~[spark-cassandra-connector_2.11-2.3.1.jar:2.3.1]
at com.datastax.spark.connector.writer.TableWriter$$anonfun$writeInternal$1$$anonfun$apply$2.apply(TableWriter.scala:233) ~[spark-cassandra-connector_2.11-2.3.1.jar:2.3.1]
at scala.collection.Iterator$class.foreach(Iterator.scala:893) ~[scala-library-2.11.8.jar:?]
代码段。
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.11</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.2.0</version>
</dependency>
能否请您解决此问题?预先感谢。
答案 0 :(得分:0)
仅当包含非阴影版本的Java驱动程序时,才会发生这种情况。由于番石榴不兼容,我们需要在Spark Cassandra连接器中为Java驱动程序着色。这意味着任何其他基于Java驱动程序的库都将破坏阴影并导致反射错误,如上面的一个。
如果您需要对Java驱动程序版本进行手动操作,请使用无阴影版本的Spark Cassandra Connector,包括您自己的库,然后再次对番石榴进行着色。