How to work with Table with more than 22 columns?

102 views
Skip to first unread message

Harit Himanshu

unread,
May 12, 2016, 4:28:25 PM5/12/16
to Slick / ScalaQuery
Hello there, 

I am trying to model a table which has 27 columns. I am using slick 3.1.1. Initially, I did following


class Anomaly(tag:Tag) extends Table[(Int, String, Int, Timestamp, Timestamp, Int, Int, Float, Int, String, String, Int,
  Blob, Timestamp, Int, Int, String, Int, Int, String, Int, String, Int, Int, Int, Float, Int)](tag, "Anomaly"){

  def id = column[Int]("id")
  def serviceName = column[String]("ServiceName")
  def serviceId = column[Int]("ServiceId")
  def timeUpdated = column[Timestamp]("TimeUpdated")
  def timestamp = column[Timestamp]("Timestamp")
  def anomalyCategoryId = column[Int]("AnomalyCategoryId")
  def userGroup = column[Int]("UserGroup")
  def riskValue = column[Float]("RiskValue")
  def activityTypeId = column[Int]("ActivityTypeId")
  def destinationHost = column[String]("DestinationHost")
  def userName = column[String]("UserName")
  def tenantId = column[Int]("TenantId")
  def information = column[Blob]("Information")
  def timeCreated = column[Timestamp]("TimeCreated")
  def userId = column[Int]("UserId")
  def anomalyType = column[Int]("AnomalyType")
  def anomalyValue = column[String]("AnomalyValue")
  def measure = column[Int]("Measure")
  def userAction = column[Int]("UserAction")
  def uniqueIdentifier = column[String]("UniqueIdentifier")
  def similarCount = column[Int]("SimilarCount")
  def trainingValue = column[String]("TrainingValue")
  def state = column[Int]("State")
  def riskLevel = column[Int]("RiskLevel")
  def userRiskLevel = column[Int]("UserRiskLevel")
  def userRiskScore = column[Float]("UserRiskScore")
  def response = column[Int]("Response")


  def * = (id, serviceName, serviceId, timeUpdated, timestamp, anomalyCategoryId, userGroup,
    riskValue, activityTypeId, destinationHost, userName, tenantId, information, timeCreated, userId, anomalyType, anomalyValue,
    measure, userAction, uniqueIdentifier, similarCount, trainingValue, state, riskLevel, userRiskLevel, userRiskScore, response)
}

But then error came that the column limit is 22, so I followed example mentioned on Github (https://github.com/slick/slick/issues/519) and changed it to

 import java.sql.{Blob, Timestamp}

import slick.collection.heterogeneous.HNil
import slick.collection.heterogeneous.syntax._
import slick.driver.MySQLDriver.api._


case class Anomaly1(id: Int, serviceName: String, timeUpdated: Timestamp, timestamp: Timestamp, anomalyCategoryId: Int,
                    userGroup:Int, riskValue: Float, activityTypeId: Int, destinationHost: String, userName: String)

case class Anomaly2(tenantId: Int, information:Blob, timeCreated: Timestamp, userId: Int, anomalyType:Int, anomalyValue:String, measure:Int,
                    userAction:Int, uniqueIdentifier:Int, similarCount:Int, trainingValue:String, state: Int, riskLevel:Int, userRiskLevel:Int,
                    userRiskScore: Float, response:Int)

case class AnomalyC(anomaly1: Anomaly1, anomaly2: Anomaly2)

class Anomaly(tag:Tag) extends Table[AnomalyC](tag, "Anomaly") {
  def id = column[Int]("id")
  def serviceName = column[String]("ServiceName")
  def serviceId = column[Int]("ServiceId")
  def timeUpdated = column[Timestamp]("TimeUpdated")
  def timestamp = column[Timestamp]("Timestamp")
  def anomalyCategoryId = column[Int]("AnomalyCategoryId")
  def userGroup = column[Int]("UserGroup")
  def riskValue = column[Float]("RiskValue")
  def activityTypeId = column[Int]("ActivityTypeId")
  def destinationHost = column[String]("DestinationHost")
  def userName = column[String]("UserName")
  def tenantId = column[Int]("TenantId")
  def information = column[Blob]("Information")
  def timeCreated = column[Timestamp]("TimeCreated")
  def userId = column[Int]("UserId")
  def anomalyType = column[Int]("AnomalyType")
  def anomalyValue = column[String]("AnomalyValue")
  def measure = column[Int]("Measure")
  def userAction = column[Int]("UserAction")
  def uniqueIdentifier = column[String]("UniqueIdentifier")
  def similarCount = column[Int]("SimilarCount")
  def trainingValue = column[String]("TrainingValue")
  def state = column[Int]("State")
  def riskLevel = column[Int]("RiskLevel")
  def userRiskLevel = column[Int]("UserRiskLevel")
  def userRiskScore = column[Float]("UserRiskScore")
  def response = column[Int]("Response")

  def * = id :: serviceName :: serviceId :: timeUpdated :: timestamp :: anomalyCategoryId :: userGroup ::
  riskValue :: activityTypeId :: destinationHost :: userName :: tenantId :: information :: timeCreated :: userId :: anomalyType :: anomalyValue ::
  measure :: userAction :: uniqueIdentifier :: similarCount :: trainingValue :: state :: riskLevel :: userRiskLevel :: userRiskScore :: response :: HNil <>
  (Anomaly1.unapply, Anomaly2.unapply)
}

But now I see compilation error as

Error:(60, 13) type mismatch;
 found   : com.shn.db.tables.Anomaly1 => Option[(Int, String, java.sql.Timestamp, java.sql.Timestamp, Int, Int, Float, Int, String, String)]
 required: ((Int, java.sql.Blob, java.sql.Timestamp, Int, Int, String, Int, Int, Int, Int, String, Int, Int, Int, Float, Int)) => Option[(Int, String, java.sql.Timestamp, java.sql.Timestamp, Int, Int, Float, Int, String, String)]
  (Anomaly1.unapply, Anomaly2.unapply)
            ^
Error:(60, 31) type mismatch;
 found   : com.shn.db.tables.Anomaly2 => Option[(Int, java.sql.Blob, java.sql.Timestamp, Int, Int, String, Int, Int, Int, Int, String, Int, Int, Int, Float, Int)]
 required: Option[(Int, String, java.sql.Timestamp, java.sql.Timestamp, Int, Int, Float, Int, String, String)] => Option[(Int, java.sql.Blob, java.sql.Timestamp, Int, Int, String, Int, Int, Int, Int, String, Int, Int, Int, Float, Int)]
  (Anomaly1.unapply, Anomaly2.unapply)
                              ^
Error:(59, 154) No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
  Required level: slick.lifted.FlatShapeLevel
     Source type: slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[java.sql.Timestamp],slick.collection.heterogeneous.HCons[slick.lifted.Rep[java.sql.Timestamp],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Float],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[java.sql.Blob],slick.collection.heterogeneous.HCons[slick.lifted.Rep[java.sql.Timestamp],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[String],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Float],slick.collection.heterogeneous.HCons[slick.lifted.Rep[Int],slick.collection.heterogeneous.HNil.type]]]]]]]]]]]]]]]]]]]]]]]]]]]
   Unpacked type: (Int, java.sql.Blob, java.sql.Timestamp, Int, Int, String, Int, Int, Int, Int, String, Int, Int, Int, Float, Int)
     Packed type: Any
  measure :: userAction :: uniqueIdentifier :: similarCount :: trainingValue :: state :: riskLevel :: userRiskLevel :: userRiskScore :: response :: HNil <>
                                                                                                                                                         ^

How do I fix it?

Thanks

Roy Phillips

unread,
May 18, 2016, 3:40:51 PM5/18/16
to Slick / ScalaQuery


On Thursday, 12 May 2016 21:28:25 UTC+1, Harit Himanshu wrote:
Hello there, 

I am trying to model a table which has 27 columns. I am using slick 3.1.1. Initially, I did following...

Christian Enrique Ortega Loaiza

unread,
May 18, 2016, 5:27:07 PM5/18/16
to Slick / ScalaQuery
I got the same problem in past....and my option to "solve" this was to group the fields per semantical similarity and to create other tables from them, so, for instance, you could have something like this:


class Anomaly(tag:Tag) extends Table[AnomalyC](tag, "Anomaly") {
  def id = column[Int]("id")
  def serviceName = column[String]("ServiceName")
  def serviceId = column[Int]("ServiceId")
  def timeUpdated = column[Timestamp]("TimeUpdated")
  def timestamp = column[Timestamp]("Timestamp")
  def anomalyCategoryId = column[Int]("AnomalyCategoryId")
  ---
  def user = column[UserAnomaly]("User")
}

class UserAnomaly() extends Table[UserAnomalyC]("UserAnomaly") {

  def userGroup = column[Int]("UserGroup")
  def userName = column[String]("UserName")
  def userId = column[Int]("UserId")
  ...
}

So, the quantity of fields into table Anomaly decrease (but the quantity of tables will increase).

Good luck!
Reply all
Reply to author
Forward
0 new messages