Search code examples
cassandracassandra-3.0phantom-dsl

Cassandra phantom-dsl derived column is missing in create database generated queries


I have following table definition

import com.outworkers.phantom.builder.primitives.Primitive
import com.outworkers.phantom.dsl._

abstract class DST[V, P <: TSP[V], T <: DST[V, P, T]] extends Table[T, P] {
  object entityKey extends StringColumn with PartitionKey {
    override lazy val name = "entity_key"
  }

 abstract class entityValue(implicit ev: Primitive[V]) extends PrimitiveColumn[V] {
    override lazy val name = "entity_value"
  }

In concrete table sub class

abstract class SDST[P <: TSP[String]] extends DST[String, P, SDST[P]] {
  override def tableName: String = "\"SDS\""

  object entityValue extends entityValue
}

Database class

class TestDatabase(override val connector: CassandraConnection) extends Database[TestDatabase](connector) {
object SDST extends SDST[SDSR] with connector.Connector {
    override def fromRow(r: Row): SDSR=
      SDSR(entityKey(r), entityValue(r))
 }
}

The create table query generated by phantom-dsl looks like below

database.create()

c.o.phantom Executing query: CREATE TABLE IF NOT EXISTS test."SDS" (entity_key text,PRIMARY KEY (entity_key))

As you can see derived column is missing from the create table DDL.

Please let me know if I am missing something in the implementation.

Omitted class definitions like SDSR and TSP are simple case classes.

Thanks


Solution

  • Phantom doesn't currently support table to table inheritance. The reasons behind that decision are complexities inherent in the Macro API that we rely on to power the DSL.

    This feature is planned for a future release, but until that stage we do not expect this to work, as the table helper macro does not read columns that are inherited basically.