From 818ffff411e9a14a9775cd5bdc0da0fb1c732269 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 24 Sep 2020 14:27:08 -0400 Subject: [PATCH] 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. --- delorean_write_buffer/src/database.rs | 68 ++++++++------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/delorean_write_buffer/src/database.rs b/delorean_write_buffer/src/database.rs index f4dd7d6f37..ea8d99e7c6 100644 --- a/delorean_write_buffer/src/database.rs +++ b/delorean_write_buffer/src/database.rs @@ -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(); } }