@@ -607,7 +607,7 @@ def to_database(self, value):
607607 return self .validate (value )
608608
609609
610- class BaseContainerColumn (Column ):
610+ class BaseCollectionColumn (Column ):
611611 """
612612 Base Container type for collection-like columns.
613613
@@ -630,10 +630,10 @@ def __init__(self, types, **kwargs):
630630 instances .append (inst )
631631
632632 self .types = instances
633- super (BaseContainerColumn , self ).__init__ (** kwargs )
633+ super (BaseCollectionColumn , self ).__init__ (** kwargs )
634634
635635 def validate (self , value ):
636- value = super (BaseContainerColumn , self ).validate (value )
636+ value = super (BaseCollectionColumn , self ).validate (value )
637637 # It is dangerous to let collections have more than 65535.
638638 # See: https://issues.apache.org/jira/browse/CASSANDRA-5428
639639 if value is not None and len (value ) > 65535 :
@@ -652,6 +652,45 @@ def sub_types(self):
652652 return self .types
653653
654654
655+ class Tuple (BaseCollectionColumn ):
656+ """
657+ Stores a fixed-length set of positional values
658+
659+ http://docs.datastax.com/en/cql/3.1/cql/cql_reference/tupleType.html
660+ """
661+ def __init__ (self , * args , ** kwargs ):
662+ """
663+ :param args: column types representing tuple composition
664+ """
665+ if not args :
666+ raise ValueError ("Tuple must specify at least one inner type" )
667+ super (Tuple , self ).__init__ (args , ** kwargs )
668+ self .db_type = 'tuple<{0}>' .format (', ' .join (typ .db_type for typ in self .types ))
669+
670+ def validate (self , value ):
671+ val = super (Tuple , self ).validate (value )
672+ if val is None :
673+ return
674+ if len (val ) > len (self .types ):
675+ raise ValidationError ("Value %r has more fields than tuple definition (%s)" %
676+ (val , ', ' .join (t for t in self .types )))
677+ return tuple (t .validate (v ) for t , v in zip (self .types , val ))
678+
679+ def to_python (self , value ):
680+ if value is None :
681+ return tuple ()
682+ return tuple (t .to_python (v ) for t , v in zip (self .types , value ))
683+
684+ def to_database (self , value ):
685+ if value is None :
686+ return
687+ return tuple (t .to_database (v ) for t , v in zip (self .types , value ))
688+
689+
690+ class BaseContainerColumn (BaseCollectionColumn ):
691+ pass
692+
693+
655694class Set (BaseContainerColumn ):
656695 """
657696 Stores a set of unordered, unique values
@@ -787,41 +826,6 @@ def to_database(self, value):
787826 return dict ((self .key_col .to_database (k ), self .value_col .to_database (v )) for k , v in value .items ())
788827
789828
790- class Tuple (BaseContainerColumn ):
791- """
792- Stores a fixed-length set of positional values
793-
794- http://docs.datastax.com/en/cql/3.1/cql/cql_reference/tupleType.html
795- """
796- def __init__ (self , * args , ** kwargs ):
797- """
798- :param args: column types representing tuple composition
799- """
800- if not args :
801- raise ValueError ("Tuple must specify at least one inner type" )
802- super (Tuple , self ).__init__ (args , ** kwargs )
803- self .db_type = 'tuple<{0}>' .format (', ' .join (typ .db_type for typ in self .types ))
804-
805- def validate (self , value ):
806- val = super (Tuple , self ).validate (value )
807- if val is None :
808- return
809- if len (val ) > len (self .types ):
810- raise ValidationError ("Value %r has more fields than tuple definition (%s)" %
811- (val , ', ' .join (t for t in self .types )))
812- return tuple (t .validate (v ) for t , v in zip (self .types , val ))
813-
814- def to_python (self , value ):
815- if value is None :
816- return tuple ()
817- return tuple (t .to_python (v ) for t , v in zip (self .types , value ))
818-
819- def to_database (self , value ):
820- if value is None :
821- return
822- return tuple (t .to_database (v ) for t , v in zip (self .types , value ))
823-
824-
825829class UDTValueManager (BaseValueManager ):
826830 @property
827831 def changed (self ):
0 commit comments