Add a new column to the memtable schema, backfilling existing rows with NULL-equivalent values. Used for ILP schema evolution: when a new field appears in a later batch, the column is added and old rows get NaN/0/null-symbol.
(&mut self, name: String, col_type: ColumnType)
| 407 | /// Used for ILP schema evolution: when a new field appears in a later |
| 408 | /// batch, the column is added and old rows get NaN/0/null-symbol. |
| 409 | pub fn add_column(&mut self, name: String, col_type: ColumnType) { |
| 410 | // Don't add duplicates. |
| 411 | if self.schema.columns.iter().any(|(n, _)| n == &name) { |
| 412 | return; |
| 413 | } |
| 414 | let existing_rows = self.row_count as usize; |
| 415 | let col = match col_type { |
| 416 | ColumnType::Float64 => ColumnData::Float64(vec![f64::NAN; existing_rows]), |
| 417 | ColumnType::Int64 => ColumnData::Int64(vec![0; existing_rows]), |
| 418 | ColumnType::Symbol => ColumnData::Symbol(vec![u32::MAX; existing_rows]), |
| 419 | ColumnType::Timestamp => return, // never add a second timestamp |
| 420 | }; |
| 421 | let idx = self.columns.len(); |
| 422 | self.columns.push(col); |
| 423 | self.schema.columns.push((name, col_type)); |
| 424 | self.schema.codecs.push(nodedb_codec::ColumnCodec::Auto); |
| 425 | if col_type == ColumnType::Symbol { |
| 426 | self.symbol_dicts.insert(idx, SymbolDictionary::new()); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | #[cfg(test)] |
no test coverage detected