Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Cassandra表中的水滴图_Scala_Cassandra_Phantom Dsl - Fatal编程技术网

Scala Cassandra表中的水滴图

Scala Cassandra表中的水滴图,scala,cassandra,phantom-dsl,Scala,Cassandra,Phantom Dsl,尝试创建新表,其中每一行都可以有称为上下文的额外数据,即键/值映射。键是字符串,值可以是几个字节(字节数组) 以下定义未编译,出现以下错误: Error:(55, 30) Cannot find primitive implementation for class Array object context extends MapColumn[String, Array[Byte]] 这是我的密码: case class UserJourny(

尝试创建新表,其中每一行都可以有称为上下文的额外数据,即键/值映射。键是字符串,值可以是几个字节(字节数组)

以下定义未编译,出现以下错误:

Error:(55, 30) Cannot find primitive implementation for class Array
  object context extends MapColumn[String, Array[Byte]] 
这是我的密码:

case class UserJourny(
                       id: Long,
                       time: Int,
                       activity_type: Int,
                       context: Map[String, Array[Byte]]
               )


abstract class UserJournyModel extends Table[UserJournyModel, UserJourny] {
  override def tableName: String = "user_journy"

  object dyid extends BigIntColumn with PartitionKey {
    override lazy val name = "id"
  }

  object time extends IntColumn with ClusteringOrder with Descending {
    override lazy val name = "time"
  }

  object activity_type extends IntColumn
  object context extends MapColumn[String, Array[Byte]]
}

我应该怎样做才对呢?

使用
MapColumn[String,ByteBuffer]
,这是卡桑德拉天生理解的。然后,您需要一些基本的有趣的东西来将字节数组编码到缓冲区

val buf = ByteBuffer.wrap(Array[Byte](1, 2, 3, 4, 5))
您还可以派生一个基本元素,使您的生活总体上更轻松

implicit val byteArrayPrimitive = Primitive.derive[
  Array[Byte],
  ByteBuffer
](ByteBuffer.wrap)(_.array)
现在,您可以成功地使用
MapColumn[String,Array[Byte]]
,Cassandra将其存储为
缓冲区
,无论如何,它内部将有
map
类型