@@ -1988,35 +1988,54 @@ def _build_table_metadata(self, row, col_rows, trigger_rows):
19881988
19891989 table_meta = TableMetadataV3 (keyspace_name , table_name )
19901990
1991- for col_row in cf_col_rows :
1992- column_meta = self ._build_column_metadata (table_meta , col_row )
1993- table_meta .columns [column_meta .name ] = column_meta
1991+ table_meta .options = self ._build_table_options (row )
1992+ flags = row .get ('flags' , set ())
1993+ if flags :
1994+ compact_static = False
1995+ table_meta .is_compact_storage = 'dense' in flags or 'super' in flags or 'compound' not in flags
1996+ else :
1997+ # example: create table t (a int, b int, c int, primary key((a,b))) with compact storage
1998+ compact_static = True
1999+ table_meta .is_compact_storage = True
19942000
19952001 # partition key
19962002 partition_rows = [r for r in cf_col_rows
19972003 if r .get ('type' , None ) == "partition_key" ]
19982004 if len (partition_rows ) > 1 :
19992005 partition_rows = sorted (partition_rows , key = lambda row : row .get ('component_index' ))
20002006 for r in partition_rows :
2007+ # we have to add meta here (and not in the later loop) because TableMetadata.columns is an
2008+ # OrderedDict, and it assumes keys are inserted first, in order, when exporting CQL
2009+ column_meta = self ._build_column_metadata (table_meta , r )
2010+ table_meta .columns [column_meta .name ] = column_meta
20012011 table_meta .partition_key .append (table_meta .columns [r .get ('column_name' )])
20022012
20032013 # clustering key
2004- clustering_rows = [r for r in cf_col_rows
2005- if r .get ('type' , None ) == "clustering" ]
2006- if len (clustering_rows ) > 1 :
2007- clustering_rows = sorted (clustering_rows , key = lambda row : row .get ('component_index' ))
2008- for r in clustering_rows :
2009- table_meta .clustering_key .append (table_meta .columns [r .get ('column_name' )])
2014+ if not compact_static :
2015+ clustering_rows = [r for r in cf_col_rows
2016+ if r .get ('type' , None ) == "clustering" ]
2017+ if len (clustering_rows ) > 1 :
2018+ clustering_rows = sorted (clustering_rows , key = lambda row : row .get ('component_index' ))
2019+ for r in clustering_rows :
2020+ column_meta = self ._build_column_metadata (table_meta , r )
2021+ table_meta .columns [column_meta .name ] = column_meta
2022+ table_meta .clustering_key .append (table_meta .columns [r .get ('column_name' )])
2023+
2024+ for col_row in (r for r in cf_col_rows
2025+ if r .get ('type' , None ) not in ('parition_key' , 'clustering_key' )):
2026+ column_meta = self ._build_column_metadata (table_meta , col_row )
2027+ if not compact_static or column_meta .is_static :
2028+ # for compact static tables, we omit the clustering key and value, and only add the logical columns.
2029+ # They are marked not static so that it generates appropriate CQL
2030+ if compact_static :
2031+ column_meta .is_static = False
2032+ table_meta .columns [column_meta .name ] = column_meta
20102033
20112034 if trigger_rows :
20122035 for trigger_row in trigger_rows [table_name ]:
20132036 trigger_meta = self ._build_trigger_metadata (table_meta , trigger_row )
20142037 table_meta .triggers [trigger_meta .name ] = trigger_meta
20152038
2016- table_meta .options = self ._build_table_options (row )
2017- flags = row .get ('flags' , set ())
2018- if flags :
2019- table_meta .is_compact_storage = 'dense' in flags or 'super' in flags or 'compound' not in flags
20202039 return table_meta
20212040
20222041 def _build_table_options (self , row ):
0 commit comments