Question

I am trying to do the following but for some reason my code won't compile due to a type mismatch from the KeySerializer.

implicit val keyspace = ConnectionPool.bigdataKeyspace
  implicit val CF_PAST = ColumnFamily.newColumnFamily(CF, LongSerializer.get, StringSerializer.get)

  def update(model: M) = {
    val batch = keyspace.prepareMutationBatch().setConsistencyLevel(ConnectionPool.CL_WRITE)
    val rk = model.rowkey
    try {

        batch.withRow(CF_PAST, rk)
        .putColumnIfNotNull(model.epoch, model.value, model.ttl)

      batch.execute
      Option(model)

    } catch {
      case e: Exception =>
        logger.warn("Unable to insert past model", e)
        None
    }
  }

The compile error is as follows"

error: type mismatch;  found   
: com.netflix.astyanax.model.ColumnFamily[Long,String]  required: com.netflix.astyanax.model.ColumnFamily[Comparable[_ >: 
String with Long <: Comparable[_ >: String with Long <: 
Comparable[_ >: String with Long <: 
java.io.Serializable] with java.io.Serializable] with java.io.Serializable] with java.io.Serializable,String] Note: 
Long <: Comparable[_ >: String with Long <: Comparable[_ >: 
String with Long <: Comparable[_ >: String with Long <: 
java.io.Serializable] with java.io.Serializable] with java.io.Serializable] with java.io.Serializable, but Java-defined class ColumnFamily is invariant in type K. 
You may wish to investigate a wildcard type such as `_ <: 
Comparable[_ >: String with Long <: Comparable[_ >: 
String with Long <: Comparable[_ >: String with Long <: java.io.Serializable] with
 java.io.Serializable] with java.io.Serializable] with java.io.Serializable`. 
(SLS 3.2.10)
            batch.withRow(CF_PAST, rk)

This only seems to happen in Scala with KeySerializers that are not a String, ColumnSerializers as other types seem to work fine? Is there a work around for this?

Was it helpful?

Solution

Ah I realized that KeySerializer was incorrect for this case. I needed to set the ColumnSerializer:

  implicit val CF_PAST = ColumnFamily.newColumnFamily(CF, StringSerializer.get, LongSerializer.get)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top