@@ -111,6 +111,7 @@ type AggregateMetadata struct {
111
111
type MaterializedViewMetadata struct {
112
112
Keyspace string
113
113
Name string
114
+ AdditionalWritePolicy string
114
115
BaseTableId UUID
115
116
BaseTable * TableMetadata
116
117
BloomFilterFpChance float64
@@ -128,7 +129,8 @@ type MaterializedViewMetadata struct {
128
129
MaxIndexInterval int
129
130
MemtableFlushPeriodInMs int
130
131
MinIndexInterval int
131
- ReadRepairChance float64
132
+ ReadRepair string // Only present in Cassandra 4.0+
133
+ ReadRepairChance float64 // Note: Cassandra 4.0 removed ReadRepairChance and added ReadRepair instead
132
134
SpeculativeRetry string
133
135
134
136
baseTableName string
@@ -975,69 +977,201 @@ func getUserTypeMetadata(session *Session, keyspaceName string) ([]UserTypeMetad
975
977
return uTypes , nil
976
978
}
977
979
980
+ func bytesMapToStringsMap (byteData map [string ][]byte ) map [string ]string {
981
+ extensions := make (map [string ]string , len (byteData ))
982
+ for key , rowByte := range byteData {
983
+ extensions [key ] = string (rowByte )
984
+ }
985
+
986
+ return extensions
987
+ }
988
+
989
+ func materializedViewMetadataFromMap (currentObject map [string ]interface {}, materializedView * MaterializedViewMetadata ) error {
990
+ const errorMessage = "gocql.materializedViewMetadataFromMap failed to read column %s"
991
+ var ok bool
992
+ for key , value := range currentObject {
993
+ switch key {
994
+ case "keyspace_name" :
995
+ materializedView .Keyspace , ok = value .(string )
996
+ if ! ok {
997
+ return fmt .Errorf (errorMessage , key )
998
+ }
999
+
1000
+ case "view_name" :
1001
+ materializedView .Name , ok = value .(string )
1002
+ if ! ok {
1003
+ return fmt .Errorf (errorMessage , key )
1004
+ }
1005
+
1006
+ case "additional_write_policy" :
1007
+ materializedView .AdditionalWritePolicy , ok = value .(string )
1008
+ if ! ok {
1009
+ return fmt .Errorf (errorMessage , key )
1010
+ }
1011
+
1012
+ case "base_table_id" :
1013
+ materializedView .BaseTableId , ok = value .(UUID )
1014
+ if ! ok {
1015
+ return fmt .Errorf (errorMessage , key )
1016
+ }
1017
+
1018
+ case "base_table_name" :
1019
+ materializedView .baseTableName , ok = value .(string )
1020
+ if ! ok {
1021
+ return fmt .Errorf (errorMessage , key )
1022
+ }
1023
+
1024
+ case "bloom_filter_fp_chance" :
1025
+ materializedView .BloomFilterFpChance , ok = value .(float64 )
1026
+ if ! ok {
1027
+ return fmt .Errorf (errorMessage , key )
1028
+ }
1029
+
1030
+ case "caching" :
1031
+ materializedView .Caching , ok = value .(map [string ]string )
1032
+ if ! ok {
1033
+ return fmt .Errorf (errorMessage , key )
1034
+ }
1035
+
1036
+ case "comment" :
1037
+ materializedView .Comment , ok = value .(string )
1038
+ if ! ok {
1039
+ return fmt .Errorf (errorMessage , key )
1040
+ }
1041
+
1042
+ case "compaction" :
1043
+ materializedView .Compaction , ok = value .(map [string ]string )
1044
+ if ! ok {
1045
+ return fmt .Errorf (errorMessage , key )
1046
+ }
1047
+
1048
+ case "compression" :
1049
+ materializedView .Compression , ok = value .(map [string ]string )
1050
+ if ! ok {
1051
+ return fmt .Errorf (errorMessage , key )
1052
+ }
1053
+
1054
+ case "crc_check_chance" :
1055
+ materializedView .CrcCheckChance , ok = value .(float64 )
1056
+ if ! ok {
1057
+ return fmt .Errorf (errorMessage , key )
1058
+ }
1059
+
1060
+ case "dclocal_read_repair_chance" :
1061
+ materializedView .DcLocalReadRepairChance , ok = value .(float64 )
1062
+ if ! ok {
1063
+ return fmt .Errorf (errorMessage , key )
1064
+ }
1065
+
1066
+ case "default_time_to_live" :
1067
+ materializedView .DefaultTimeToLive , ok = value .(int )
1068
+ if ! ok {
1069
+ return fmt .Errorf (errorMessage , key )
1070
+ }
1071
+
1072
+ case "extensions" :
1073
+ byteData , ok := value .(map [string ][]byte )
1074
+ if ! ok {
1075
+ return fmt .Errorf (errorMessage , key )
1076
+ }
1077
+
1078
+ materializedView .Extensions = bytesMapToStringsMap (byteData )
1079
+
1080
+ case "gc_grace_seconds" :
1081
+ materializedView .GcGraceSeconds , ok = value .(int )
1082
+ if ! ok {
1083
+ return fmt .Errorf (errorMessage , key )
1084
+ }
1085
+
1086
+ case "id" :
1087
+ materializedView .Id , ok = value .(UUID )
1088
+ if ! ok {
1089
+ return fmt .Errorf (errorMessage , key )
1090
+ }
1091
+
1092
+ case "include_all_columns" :
1093
+ materializedView .IncludeAllColumns , ok = value .(bool )
1094
+ if ! ok {
1095
+ return fmt .Errorf (errorMessage , key )
1096
+ }
1097
+
1098
+ case "max_index_interval" :
1099
+ materializedView .MaxIndexInterval , ok = value .(int )
1100
+ if ! ok {
1101
+ return fmt .Errorf (errorMessage , key )
1102
+ }
1103
+
1104
+ case "memtable_flush_period_in_ms" :
1105
+ materializedView .MemtableFlushPeriodInMs , ok = value .(int )
1106
+ if ! ok {
1107
+ return fmt .Errorf (errorMessage , key )
1108
+ }
1109
+
1110
+ case "min_index_interval" :
1111
+ materializedView .MinIndexInterval , ok = value .(int )
1112
+ if ! ok {
1113
+ return fmt .Errorf (errorMessage , key )
1114
+ }
1115
+
1116
+ case "read_repair" :
1117
+ materializedView .ReadRepair , ok = value .(string )
1118
+ if ! ok {
1119
+ return fmt .Errorf (errorMessage , key )
1120
+ }
1121
+
1122
+ case "read_repair_chance" :
1123
+ materializedView .ReadRepairChance , ok = value .(float64 )
1124
+ if ! ok {
1125
+ return fmt .Errorf (errorMessage , key )
1126
+ }
1127
+
1128
+ case "speculative_retry" :
1129
+ materializedView .SpeculativeRetry , ok = value .(string )
1130
+ if ! ok {
1131
+ return fmt .Errorf (errorMessage , key )
1132
+ }
1133
+
1134
+ }
1135
+ }
1136
+ return nil
1137
+ }
1138
+
1139
+ func parseSystemSchemaViews (iter * Iter ) ([]MaterializedViewMetadata , error ) {
1140
+ var materializedViews []MaterializedViewMetadata
1141
+ s , err := iter .SliceMap ()
1142
+ if err != nil {
1143
+ return nil , err
1144
+ }
1145
+
1146
+ for _ , row := range s {
1147
+ var materializedView MaterializedViewMetadata
1148
+ err = materializedViewMetadataFromMap (row , & materializedView )
1149
+ if err != nil {
1150
+ return nil , err
1151
+ }
1152
+
1153
+ materializedViews = append (materializedViews , materializedView )
1154
+ }
1155
+
1156
+ return materializedViews , nil
1157
+ }
1158
+
978
1159
func getMaterializedViewsMetadata (session * Session , keyspaceName string ) ([]MaterializedViewMetadata , error ) {
979
1160
if ! session .useSystemSchema {
980
1161
return nil , nil
981
1162
}
982
1163
var tableName = "system_schema.views"
983
1164
stmt := fmt .Sprintf (`
984
- SELECT
985
- view_name,
986
- base_table_id,
987
- base_table_name,
988
- bloom_filter_fp_chance,
989
- caching,
990
- comment,
991
- compaction,
992
- compression,
993
- crc_check_chance,
994
- dclocal_read_repair_chance,
995
- default_time_to_live,
996
- extensions,
997
- gc_grace_seconds,
998
- id,
999
- include_all_columns,
1000
- max_index_interval,
1001
- memtable_flush_period_in_ms,
1002
- min_index_interval,
1003
- read_repair_chance,
1004
- speculative_retry
1165
+ SELECT *
1005
1166
FROM %s
1006
1167
WHERE keyspace_name = ?` , tableName )
1007
1168
1008
1169
var materializedViews []MaterializedViewMetadata
1009
1170
1010
- rows := session .control .query (stmt , keyspaceName ).Scanner ()
1011
- for rows .Next () {
1012
- materializedView := MaterializedViewMetadata {Keyspace : keyspaceName }
1013
- err := rows .Scan (& materializedView .Name ,
1014
- & materializedView .BaseTableId ,
1015
- & materializedView .baseTableName ,
1016
- & materializedView .BloomFilterFpChance ,
1017
- & materializedView .Caching ,
1018
- & materializedView .Comment ,
1019
- & materializedView .Compaction ,
1020
- & materializedView .Compression ,
1021
- & materializedView .CrcCheckChance ,
1022
- & materializedView .DcLocalReadRepairChance ,
1023
- & materializedView .DefaultTimeToLive ,
1024
- & materializedView .Extensions ,
1025
- & materializedView .GcGraceSeconds ,
1026
- & materializedView .Id ,
1027
- & materializedView .IncludeAllColumns ,
1028
- & materializedView .MaxIndexInterval ,
1029
- & materializedView .MemtableFlushPeriodInMs ,
1030
- & materializedView .MinIndexInterval ,
1031
- & materializedView .ReadRepairChance ,
1032
- & materializedView .SpeculativeRetry ,
1033
- )
1034
- if err != nil {
1035
- return nil , err
1036
- }
1037
- materializedViews = append (materializedViews , materializedView )
1038
- }
1171
+ iter := session .control .query (stmt , keyspaceName )
1039
1172
1040
- if err := rows .Err (); err != nil {
1173
+ materializedViews , err := parseSystemSchemaViews (iter )
1174
+ if err != nil {
1041
1175
return nil , err
1042
1176
}
1043
1177
0 commit comments