| 208 | } |
| 209 | |
| 210 | func (m *tableSchemaMutator) UpdateTable(namespace string, table metaCom.Table, force bool) (err error) { |
| 211 | tableListProto, tableListVersion, err := readEntityList(m.txnStore, utils.SchemaListKey(namespace)) |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | tableListProto, found := updateEntity(tableListProto, table.Name) |
| 217 | if !found { |
| 218 | m.logger.With( |
| 219 | "table", table, |
| 220 | ).Info("table not found for update, creating new table") |
| 221 | return m.CreateTable(namespace, &table, force) |
| 222 | } |
| 223 | |
| 224 | schemaProto, schemaVersion, err := m.readSchema(namespace, table.Name) |
| 225 | if err != nil { |
| 226 | return err |
| 227 | } |
| 228 | if schemaProto.Tomstoned { |
| 229 | return metaCom.ErrTableDoesNotExist |
| 230 | } |
| 231 | |
| 232 | var oldTable metaCom.Table |
| 233 | err = json.Unmarshal(schemaProto.Config, &oldTable) |
| 234 | if err != nil { |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | // always use old table's incarnation for update table operation will not modify incarnation |
| 239 | table.Incarnation = oldTable.Incarnation |
| 240 | |
| 241 | // merge existing table and column level configs if not specified in the input |
| 242 | if (metaCom.TableConfig{}) == table.Config { |
| 243 | table.Config = oldTable.Config |
| 244 | } |
| 245 | for columnID := range table.Columns { |
| 246 | if columnID < len(oldTable.Columns) && (metaCom.ColumnConfig{}) == table.Columns[columnID].Config { |
| 247 | table.Columns[columnID].Config = oldTable.Columns[columnID].Config |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // TODO: remove this when upstream supports archive sort columns |
| 252 | if len(table.ArchivingSortColumns) == 0 { |
| 253 | table.ArchivingSortColumns = oldTable.ArchivingSortColumns |
| 254 | } |
| 255 | |
| 256 | if !force { |
| 257 | validator := metastore.NewTableSchameValidator() |
| 258 | validator.SetNewTable(table) |
| 259 | validator.SetOldTable(oldTable) |
| 260 | err = validator.Validate() |
| 261 | if err != nil { |
| 262 | return |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | schemaProto.Tomstoned = false |
| 267 | schemaProto.Config, err = json.Marshal(table) |