@@ -837,7 +837,30 @@ def to_database(self, value):
837837
838838
839839class BaseContainerColumn (BaseCollectionColumn ):
840- pass
840+ """
841+ Base class for container columns (Set, List, Map).
842+
843+ Supports optional freezing for immutable collections.
844+ """
845+
846+ frozen = False
847+ """
848+ bool flag, indicates this collection should be frozen (immutable).
849+ Frozen collections use FULL indexes instead of VALUES indexes.
850+ """
851+
852+ def __init__ (self , types , frozen = False , ** kwargs ):
853+ """
854+ :param types: a sequence of sub types in this collection
855+ :param frozen: if True, the collection will be frozen (immutable)
856+ """
857+ self .frozen = frozen
858+ super (BaseContainerColumn , self ).__init__ (types , ** kwargs )
859+
860+ def _apply_frozen (self ):
861+ """Apply frozen wrapper to db_type if frozen=True."""
862+ if self .frozen :
863+ self ._freeze_db_type ()
841864
842865
843866class Set (BaseContainerColumn ):
@@ -849,18 +872,21 @@ class Set(BaseContainerColumn):
849872
850873 _python_type_hashable = False
851874
852- def __init__ (self , value_type , strict = True , default = set , ** kwargs ):
875+ def __init__ (self , value_type , strict = True , default = set , frozen = False , ** kwargs ):
853876 """
854877 :param value_type: a column class indicating the types of the value
855878 :param strict: sets whether non set values will be coerced to set
856879 type on validation, or raise a validation error, defaults to True
880+ :param frozen: if True, the collection will be frozen (immutable) and
881+ use FULL indexes instead of VALUES indexes
857882 """
858883 self .strict = strict
859- super (Set , self ).__init__ ((value_type ,), default = default , ** kwargs )
884+ super (Set , self ).__init__ ((value_type ,), frozen = frozen , default = default , ** kwargs )
860885 self .value_col = self .types [0 ]
861886 if not self .value_col ._python_type_hashable :
862887 raise ValidationError ("Cannot create a Set with unhashable value type (see PYTHON-494)" )
863888 self .db_type = 'set<{0}>' .format (self .value_col .db_type )
889+ self ._apply_frozen ()
864890
865891 def validate (self , value ):
866892 val = super (Set , self ).validate (value )
@@ -899,13 +925,16 @@ class List(BaseContainerColumn):
899925
900926 _python_type_hashable = False
901927
902- def __init__ (self , value_type , default = list , ** kwargs ):
928+ def __init__ (self , value_type , default = list , frozen = False , ** kwargs ):
903929 """
904930 :param value_type: a column class indicating the types of the value
931+ :param frozen: if True, the collection will be frozen (immutable) and
932+ use FULL indexes instead of VALUES indexes
905933 """
906- super (List , self ).__init__ ((value_type ,), default = default , ** kwargs )
934+ super (List , self ).__init__ ((value_type ,), frozen = frozen , default = default , ** kwargs )
907935 self .value_col = self .types [0 ]
908936 self .db_type = 'list<{0}>' .format (self .value_col .db_type )
937+ self ._apply_frozen ()
909938
910939 def validate (self , value ):
911940 val = super (List , self ).validate (value )
@@ -937,19 +966,22 @@ class Map(BaseContainerColumn):
937966
938967 _python_type_hashable = False
939968
940- def __init__ (self , key_type , value_type , default = dict , ** kwargs ):
969+ def __init__ (self , key_type , value_type , default = dict , frozen = False , ** kwargs ):
941970 """
942971 :param key_type: a column class indicating the types of the key
943972 :param value_type: a column class indicating the types of the value
973+ :param frozen: if True, the collection will be frozen (immutable) and
974+ use FULL indexes instead of VALUES indexes
944975 """
945- super (Map , self ).__init__ ((key_type , value_type ), default = default , ** kwargs )
976+ super (Map , self ).__init__ ((key_type , value_type ), frozen = frozen , default = default , ** kwargs )
946977 self .key_col = self .types [0 ]
947978 self .value_col = self .types [1 ]
948979
949980 if not self .key_col ._python_type_hashable :
950981 raise ValidationError ("Cannot create a Map with unhashable key type (see PYTHON-494)" )
951982
952983 self .db_type = 'map<{0}, {1}>' .format (self .key_col .db_type , self .value_col .db_type )
984+ self ._apply_frozen ()
953985
954986 def validate (self , value ):
955987 val = super (Map , self ).validate (value )
0 commit comments