How to create an update statement where a UDT value need to be updated using QueryBuilder

Author: Manu Chadha

Originally Sourced from:

I have the following udt type

CREATE TYPE tag_partitions(
  year bigint,
  month bigint);

and the following table

CREATE TABLE ${tableName} (
  tag text,
  partition_info set<FROZEN<tag_partitions>>,
  PRIMARY KEY ((tag))

The table schema is mapped using the following model

case class TagPartitionsInfo(year:Long, month:Long)
case class TagPartitions(tag:String, partition_info:Set[TagPartitionsInfo])

I have written a function which should create an Update.IfExists query: But I don't know how I should update the udt value. I tried to use set but it isn't working.

def updateValues(tableName:String, model:TagPartitions, id:TagPartitionKeys):Update.IfExists = {
   val partitionInfoType:UserType = session.getCluster().getMetadata
   //create value
   //the logic below assumes that there is only one element in the set
   val partitionsInfoSet:Set[UDTValue] = =>{
   println("partition info converted to UDTValue: "+partitionsInfoSet)

      .where(QueryBuilder.eq("tag", id.tag)).ifExists()