scala:从scylla读取数据引发异常

e4yzc0pl  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(317)

我是scala的新手,我会运行一个简单的查询来从scylla检索一些数据。这是我的密码:

val my_name = "test"
val cluster = ScyllaConnector.getCluster(clusterIpString, scyllaPreferredDc, scyllaUsername, scyllaPassword)
val session = cluster.connect(keySpace)
val preparedStatement: PreparedStatement = session.prepare(GOID_QUERY)
val nameResults = session.execute(preparedStatement.bind(my_name))
val nameResult = nameResults.one()
if(nameResult != null){
  println("Here")
  val id_recent = nameResult.getSet("id_recent",  classOf[String])
  println(id_recent)
}
session.close()
cluster.close()

抛出:
线程“main”com.datastax.driver.core.exceptions.codecondNotFoundException中出现异常:在com.datastax.driver.core.codecondRegistry.notfound(codecondRegistry)处找不到请求操作的编解码器:[varchar<->java.util.set<java.lang.string>]。java:679)在com.datastax.driver.core.coderegistry.createcodec(coderegistry。java:526)在com.datastax.driver.core.coderegistry.findcodec(coderegistry。java:506)在com.datastax.driver.core.coderegistry.access$200(coderegistry。java:140)位于com.datastax.driver.core.coderegistry$typecodeccacheloader.load(coderegistry)。java:211)位于com.datastax.driver.core.coderegistry$typecodeccacheloader.load(coderegistry)。java:208)在shadeio.common.cache.localcache$loadingvaluereference.loadfuture(localcache。java:3527)在shadeio.common.cache.localcache$segment.loadsync(localcache。java:2319)在shadeio.common.cache.localcache$segment.lockedgetorload(localcache。java:2282)在shadeio.common.cache.localcache$segment.get(localcache。java:2197)在shadeio.common.cache.localcache.get(localcache。java:3937)在shadeio.common.cache.localcache.getorload(localcache。java:3941)在shadeio.common.cache.localcache$localloadingcache.get(localcache。java:4824)在com.datastax.driver.core.coderegistry.lookupcodec(coderegistry。java:480)在com.datastax.driver.core.coderegistry.codefor(coderegistry。java:448)在com.datastax.driver.core.abstractgettablebyindexdata.codecfor(abstractgettablebyindexdata。java:73)位于com.datastax.driver.core.abstractgettablebyindexdata.getset(abstractgettablebyindexdata)。java:318)在com.datastax.driver.core.abstractgettabledata.getset(abstractgettabledata)。java:26)位于com.datastax.driver.core.abstractgettablebyindexdata.getset(abstractgettablebyindexdata)。java:307)在com.datastax.driver.core.abstractgettabledata.getset(abstractgettabledata。java:26)在com.datastax.driver.core.abstractgettabledata.getset(abstractgettabledata)。java:215)在class.path$.main(代码名。scala:184)位于sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)的sun.reflect.nativemethodaccessorimpl.invoke(本机方法)的class.path.main(codename.scala)。java:62)在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.lang.reflect.method.invoke(方法。java:498)在org.apache.spark.deploy.javamainapplication.start(sparkapplication。scala:52)在org.apache.spark.deploy.sparksubmit.org$apache$spark$deploy$sparksubmit$$runmain(sparksubmit)。scala:845)在org.apache.spark.deploy.sparksubmit.dorunmain$1(sparksubmit。scala:161)在org.apache.spark.deploy.sparksubmit.submit(sparksubmit。scala:184)在org.apache.spark.deploy.sparksubmit.dosubmit(sparksubmit。scala:86)在org.apache.spark.deploy.sparksubmit$$anon$2.dosubmit(sparksubmit。scala:920)在org.apache.spark.deploy.sparksubmit$.main(sparksubmit。scala:929)位于org.apache.spark.deploy.sparksubmit.main(sparksubmit.scala)
我相信问题会在未来几年出现 getSet 在要求的地方排队 classOf[String] 但我不知道用什么来代替它。
以下是我的表定义:

-- auto-generated definition
create table name_table
(
    name       text,
    id_recent  text,
    primary key (name)
)
pes8fvy9

pes8fvy91#

你有不兼容的类型-你有 text 在数据库中键入,但您试图将其作为一组字符串检索( [varchar <-> java.util.Set<java.lang.String>] 信息直接说明了这一点)。
替换 getSetgetString ,如果您需要一个集合,那么您需要根据检索到的字符串自己构造它

相关问题