当前位置: 首页 > 知识库问答 >
问题:

通过Spark查询Cassandra表

杜思远
2023-03-14

我正在尝试通过以下步骤通过 spark-1.6.0 和 scala-2.11.7 从 Cassandra 2.0.17 表中获取值

  1. 已启动cassandra--服务cassandr启动
  2. 已启动spark--sbin/start all。sh
  3. 规定的火花标度-箱/火花壳-罐子火花-盒-连接器_2.10-1.5.0-M1.jar

在 Scala 中执行了这些命令

import org.apache.spark.SparkContext
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext._

sc.stop

val conf = new SparkConf(true).set("spark.cassandra.connection.host","127.0.0.1")

val sc=new SparkContext("local[2]","test",conf)

import com.datastax.spark.connector._

直到现在一切都很好,但当我执行-

val rdd=sc.cassandraTable("tutorialspoint","emp")

它给了我以下错误

error: bad symbolic reference. A signature in CassandraTableScanRDD.class refers to term driver
in package com.datastax which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling CassandraTableScanRDD.class.
error: bad symbolic reference. A signature in CassandraTableScanRDD.class refers to term core
in value com.datastax.driver which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling CassandraTableScanRDD.class.
error: bad symbolic reference. A signature in CassandraTableScanRDD.class refers to term core
in value com.datastax.driver which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling CassandraTableScanRDD.class.

添加了来自cassandra lib的jar来激发和引用它。我的使用java版本1.8.0_72

我错过了一些东西?

共有1个答案

令狐宣
2023-03-14

您使用的驱动程序与您的 scala 和 Spark 版本不兼容。您使用的是 scala-2.11.7,但此驱动程序适用于 scala 2.10。同样对于火花,此驱动程序支持火花 1.5.x。

 类似资料:
  • 我正在通过Spark Cassandra连接器应用以下内容:

  • 我想在Scala IDE中测试DSE Cassandra表上的Spark-SQL查询。当在dse spark-submit中执行jar文件时,查询将完美无缺地运行。但在Scala IDE中运行时会出现错误。错误是, 我想是spark主机配置错误,因为我在本地模式下运行主机。 这是我发起的星火会议。 但我不知道该把什么地址设为主人。我尝试将主地址设置为“spark://127.0.0.1:7077”

  • 创建TABLE TABLE(int键、time时间戳、度量浮点、主键(key、time)); 我需要创建一个火花作业,这将读取数据从上一个表,在指定的开始和结束时间戳做一些处理,并刷新结果回Cassandra。 因此,我的spark-cassandra-connector必须对集群cassandra表列进行范围查询。 范围查询的选择性约为1%,不可能在查询中包含分区键。 这两种解决方案哪一种更好?

  • 使用Spark连接器通过分区键查询cassandra的理想方法是什么。我使用传入键,但这导致cassandra在引擎盖下添加,从而导致超时。 当前设置: 这里是分区(不是主)键,我有一个复合主键,只使用分区键进行查询 更新:是的,我得到了一个异常:

  • 我正在尝试使用Scala中的Spark SQL查询Cassandra数据。 并抛出错误: org.apache.spark.sql.AnalysisException:找不到表或视图:.;第1行第14位;'Project[*]+-'UnresolvedRelation. 谢谢你。

  • 因此,我尝试使用Spark SQL进行以下查询('timestamp'是分区键): 虽然作业产生200个任务,但查询不会返回任何数据。 另外,我可以保证会返回数据,因为在cqlsh上运行查询(使用'token'函数进行适当的转换)确实会返回数据。 但不幸的是我不知道什么是“过滤器”...