我在Astyanax AllRowsReader收据中写了以下代码
object CassandraScanner extends App with CassandraHelper {
val context = getContext("movielens_small")
val cf = new ColumnFamily[UUID, String]("movielens_small", UUIDSerializer.get, StringSerializer.get)
val keyspace = context.getClient
var count : AtomicInteger = new AtomicInteger(0)
val allReader = new AllRowsReader.Builder(keyspace, cf)
.withPageSize(100)
.withConcurrencyLevel(10)
.withPartitioner(null)
.forEachRow { case row : Row[UUID, String] =>
val cols = row.getColumns
val movieName = cols.getColumnByName("name")
val movieNameVal = movieName.getStringValue
count.incrementAndGet()
true
}
.build()
.call()
println(s"Total value ${count.get()}")
}
此代码抛出异常
18:12:22,759 INFO ThriftKeyspaceImpl:745 - Detected partitioner org.apache.cassandra.dht.Murmur3Partitioner for keyspace movielens_small
18:12:22,820 ERROR AllRowsReader:524 - Error process token/key range
com.netflix.astyanax.connectionpool.exceptions.BadRequestException: BadRequestException: [host=192.168.1.169(192.168.1.169):9160, latency=32(32), attempts=1]InvalidRequestException(why:unconfigured table movielens_small)
at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:159)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:65)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:28)
at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$ThriftConnection.execute(ThriftSyncConnectionFactoryImpl.java:153)
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:119)
at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:352)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$2.execute(ThriftColumnFamilyQueryImpl.java:397)
at com.netflix.astyanax.recipes.reader.AllRowsReader$1.call(AllRowsReader.java:447)
at com.netflix.astyanax.recipes.reader.AllRowsReader$1.call(AllRowsReader.java:419)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: InvalidRequestException(why:unconfigured table movielens_small)
at org.apache.cassandra.thrift.Cassandra$get_range_slices_result$get_range_slices_resultStandardScheme.read(Cassandra.java:17430)
at org.apache.cassandra.thrift.Cassandra$get_range_slices_result$get_range_slices_resultStandardScheme.read(Cassandra.java:17397)
at org.apache.cassandra.thrift.Cassandra$get_range_slices_result.read(Cassandra.java:17323)
答案 0 :(得分:0)
我能够解决这个问题。问题在于行
val cf = new ColumnFamily[UUID, String]("movielens_small", UUIDSerializer.get, StringSerializer.get)
此处列系列的名称必须是我们正在扫描的表的名称。所以在我的情况下它是“电影”。 (movielens_small是我的键空间的名称......不是列族)。
所以工作线是
val cf = new ColumnFamily[UUID, String]("movies", UUIDSerializer.get, StringSerializer.get)
当我做这个改变时,我能够轻松地扫描桌子。