refactor: Use value_as_[type]_values methods

These call value_type anyway, so it feels like this eliminates duplicate
calls... not seeing too much of a difference in profiling though.
pull/24376/head
Carol (Nichols || Goulding) 2020-09-24 14:27:08 -04:00
parent cbc11717cc
commit 818ffff411
1 changed files with 20 additions and 48 deletions

View File

@ -1047,7 +1047,7 @@ impl Table {
let column_name = value.column().expect("WAL Value should have column");
let column_id = dictionary.lookup_value_or_insert(column_name);
let column = match self.column_id_to_index.get(&column_id) {
let mut column = match self.column_id_to_index.get(&column_id) {
Some(idx) => &mut self.columns[*idx],
None => {
// Add the column and make all values for existing rows None
@ -1060,55 +1060,27 @@ impl Table {
}
};
match (column, value.value_type()) {
(Column::Tag(vals), wb::ColumnValue::TagValue) => {
let v = value.value_as_tag_value().context(WalValueTypeMismatch {
column: column_name,
expected: "tag",
})?;
if let (Column::Bool(vals), Some(v)) = (&mut column, value.value_as_bool_value()) {
vals.push(Some(v.value()));
} else if let (Column::I64(vals), Some(v)) = (&mut column, value.value_as_i64value()) {
vals.push(Some(v.value()));
} else if let (Column::F64(vals), Some(v)) = (&mut column, value.value_as_f64value()) {
vals.push(Some(v.value()));
} else if let (Column::String(vals), Some(v)) =
(&mut column, value.value_as_string_value())
{
vals.push(Some(v.value().unwrap().to_string()));
} else if let (Column::Tag(vals), Some(v)) = (&mut column, value.value_as_tag_value()) {
let v_id = dictionary.lookup_value_or_insert(v.value().unwrap());
let v_id = dictionary.lookup_value_or_insert(v.value().unwrap());
vals.push(Some(v_id));
}
(Column::Bool(vals), wb::ColumnValue::BoolValue) => {
let v = value.value_as_bool_value().context(WalValueTypeMismatch {
column: column_name,
expected: "bool",
})?;
vals.push(Some(v.value()));
}
(Column::String(vals), wb::ColumnValue::StringValue) => {
let v = value
.value_as_string_value()
.context(WalValueTypeMismatch {
column: column_name,
expected: "String",
})?;
vals.push(Some(v.value().unwrap().to_string()));
}
(Column::I64(vals), wb::ColumnValue::I64Value) => {
let v = value.value_as_i64value().context(WalValueTypeMismatch {
column: column_name,
expected: "i64",
})?;
vals.push(Some(v.value()));
}
(Column::F64(vals), wb::ColumnValue::F64Value) => {
let v = value.value_as_f64value().context(WalValueTypeMismatch {
column: column_name,
expected: "f64",
})?;
vals.push(Some(v.value()));
}
(existing_column, inserted_value) => {
return ColumnTypeMismatch {
column: column_name,
existing_column_type: existing_column.type_description(),
inserted_value_type: type_description(inserted_value),
}
.fail()
vals.push(Some(v_id));
} else {
return ColumnTypeMismatch {
column: column_name,
existing_column_type: column.type_description(),
inserted_value_type: type_description(value.value_type()),
}
.fail();
}
}