0

I'm trying to create a frozen list in Cassandra so that I can use that column as a primary key, I can do that if I run the query manually,

some_field frozen <list<int>>

but I'm having a hard time figuring out how to do it using cqlengine in Python,

some_field = columns.List(columns.Integer(), primary_key=True)

How can I accomplish the same thing using cqlengine?

EDIT: Final code snippet looks like this,

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model

class MyModel(Model):
    __table_name__ = 'my_table'
    __options__ = {'compaction': {'class': 'DateTieredCompactionStrategy',
                              'base_time_seconds': 3600,
                              'max_sstable_age_days': 1}}

    keys = columns.Set(columns.Integer(), primary_key=True)
    columns.BaseCollectionColumn._freeze_db_type(keys)
    time_stamp = columns.DateTime(primary_key=True, clustering_order="DESC")
    ...
Gonçalo Cabrita
  • 353
  • 1
  • 5
  • 11

1 Answers1

1

As I see in the source code, you need to call function _freeze_db_type on the instance of the collection type after you created it - this will change type to frozen<...>.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132