我正在尝试遵循维基中的异步迭代器示例
我收到以下错误:
值片不是play.api.libs.iteratee.Enumerator的成员。
对问题的任何投入都是非常感谢的。
这是为了使我能够从一个大型集合中分页结果。
libraryDependencies ++= Seq(
"com.websudos" %% "phantom-dsl" % 1.22.0,
"com.websudos" %% "phantom-reactivestreams" % 1.22.0
)import com.datastax.driver.core.{ResultSet, Row}
import com.websudos.phantom.CassandraTable
import com.websudos.phantom.dsl._
import com.websudos.phantom.iteratee.Iteratee
import org.dyne.danielsan.openblockchain.data.entity.Block
import scala.concurrent.Future
import com.websudos.phantom.reactivestreams._
import scala.concurrent.Await
import scala.concurrent.duration._
sealed class BlocksModel extends CassandraTable[BlocksModel, Block] {
override def fromRow(row: Row): Block = {
Block(
hash(row),
height(row)
}
object hash extends StringColumn(this) with PartitionKey[String]
object height extends IntColumn(this) with ClusteringOrder[Int] with Descending
object order_id extends LongColumn(this) with ClusteringOrder[Long] with Descending
abstract class ConcreteBlocksModel extends BlocksModel with RootConnector {
override val tableName = "blocks"
def getBlocks(start: Int, limit: Int): Future[Set[Block]] = {
select.fetchEnumerator.slice(start, limit).collect
}
}发布于 2016-08-08 08:50:43
当您想要在枚举器上使用方法时,语法稍有错误--以下是您需要的:
abstract class ConcreteBlocksModel extends BlocksModel with RootConnector {
override val tableName = "blocks"
def getBlocks(start: Int, limit: Int): Future[Iterator[Block]] = {
select.fetchEnumerator run Iterator.slice(start, limit)
}
}如果你想要分页你的记录,有一个不同的方法,在卡桑德拉,但自动分页。
def getPage(limit: Int, paging: Option[PagingState] = None): Future[ListResult[JodaRow]] = {
select.limit(limit).fetchRecord(paging)
}基本上,您需要提供一个分页状态来运行下一个查询。现在返回的Future将在其中包含一个ListResult项,这意味着您将得到两个方法:
def records: List[R] // the list of records from the db, just like fetch()
def pagingState: PagingState // the state you care about.基本上,pagingState有一个toString方法,它将给出您需要存储在客户端的令牌。当用户想获得“下一页”时,需要从上一页提供pagingState字符串,将分页状态看作指向Cassandra表中特定位置的指针,这样Cassandra就知道如何“跳转”或“跳过页面”。
因此,假设您从页面0开始,您的下一个API调用应该包含一个pagingState作为字符串。
然后,您可以PagingState.fromString(pagingState)并传递其结果,以获得“下一页”。
我将在幻影中添加一个这方面的例子,但这将基本上解决您当前的问题。
https://stackoverflow.com/questions/38819414
复制相似问题