加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 值切片不是play.api.libs.iteratee.Enumerator的成员

发布时间:2020-12-16 18:39:15 所属栏目:安全 来源:网络整理
导读:我正在编写基于 https://github.com/websudos/phantom#partial-select-queries所述的“用于大型记录集的异步迭代器”的代码 import scala.concurrent.ExecutionContext.Implicits.globalimport scala.concurrent.Futureimport org.joda.time.DateTimeimport
我正在编写基于 https://github.com/websudos/phantom#partial-select-queries所述的“用于大型记录集的异步迭代器”的代码

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter

import com.anomaly42.aml.dao.CassandraConnector
import com.websudos.phantom.CassandraTable
import com.websudos.phantom.Implicits._

object People extends People {
  def getPersonByUpdatedAt(from:String,to:String,start: Int,limit: Int) = {
    val dtf:DateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ");
    val fromDateTime = dtf.parseDateTime(from)
    val toDateTime = dtf.parseDateTime(to)

    People.select(_.updated_at,_.firstName).allowFiltering.where(_.updated_at gte fromDateTime).and(_.updated_at lte toDateTime).fetchEnumerator().slice(start,limit).collect
  }
}

我正在使用以下库依赖:

scalaVersion  := "2.11.6"
libraryDependencies ++= Seq(
  "com.websudos"        %%  "phantom-dsl"     % "1.5.4",many more...
)

但是我在编译时遇到以下错误:

value slice is not a member of play.api.libs.iteratee.Enumerator[(org.joda.time.DateTime,Option[String])]

我想要做的是编写一个查询,每次调用getPersonByUpdatedAt()方法时,从’start’开始返回下一个’limit’结果数.

解决方法

这里有很多实现细节需要解决.首先,如果您在分页之后,可能有一种更简单的方法来实现简单范围查询而不是过滤数据.

看看使用CLUSTERING ORDER,调用ALLOW FILTERING不应该在那里.此外,如果没有CLUSTERING ORDER,默认的Murmur3分区器实际上并没有订购,因此您无法保证按照您编写的顺序检索数据.

这可能意味着你的分页根本不起作用.最后但并非最不重要的是,直接使用枚举器可能不是你想要的.

它们是异步的,因此您必须在未来内部映射以获得切片,但除此之外,当像Spark一样加载整个表时,例如许多结果,枚举器很有用.

总而言之,在人员表内:

object id extends UUIDColumn(this) with PartitionKey[UUID]// doesn't have to be UUID
object start extends DateTimeColumn(this) with ClusteringOrder[DateTime] with Ascending
object end extends DateTimeColumn(this) with ClusteringOrder[DateTime] with Ascending

只需使用fetch(),然后使用Scala集合库中的Seq.slice.以上假设您要按升序分页,例如检索最早的分页.

您还需要弄清楚实际的分区键是什么.如果同时更新2个用户,最坏的情况是丢失数据并结束FIFO队列,例如在给定时间的最后更新“获胜”.我上面用的是id,但这显然不是你需要的.

而且您可能需要有几个表来存储人员,以便您可以覆盖所需的所有查询.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读