From 092ee0c1c560ae90de897925547298443994b637 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Wed, 28 Aug 2024 17:24:38 +0800 Subject: [PATCH] refactor: use binary as grpc value of json --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/api/src/helper.rs | 21 +++++++++------------ src/operator/src/req_convert/common.rs | 1 - 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4389703aee37..579f6f7aa37d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4269,7 +4269,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "greptime-proto" version = "0.1.0" -source = "git+https://github.com/CookiePieWw/greptime-proto.git?rev=4346f484c14bb8a6711d10906ee6db54a896030a#4346f484c14bb8a6711d10906ee6db54a896030a" +source = "git+https://github.com/GreptimeTeam/greptime-proto.git?rev=c437b55725b7f5224fe9d46db21072b4a682ee4b#c437b55725b7f5224fe9d46db21072b4a682ee4b" dependencies = [ "prost 0.12.6", "serde", diff --git a/Cargo.toml b/Cargo.toml index c6366886fc04..048358aef6a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,7 +120,7 @@ etcd-client = { version = "0.13" } fst = "0.4.7" futures = "0.3" futures-util = "0.3" -greptime-proto = { git = "https://github.com/CookiePieWw/greptime-proto.git", rev = "4346f484c14bb8a6711d10906ee6db54a896030a" } +greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "c437b55725b7f5224fe9d46db21072b4a682ee4b" } humantime = "2.1" humantime-serde = "1.1" itertools = "0.10" diff --git a/src/api/src/helper.rs b/src/api/src/helper.rs index b837c15b9ef0..6f561242051b 100644 --- a/src/api/src/helper.rs +++ b/src/api/src/helper.rs @@ -137,7 +137,6 @@ impl From for ConcreteDataType { ConcreteDataType::decimal128_default_datatype() } } - ColumnDataType::Json => ConcreteDataType::json_datatype(), } } } @@ -237,7 +236,7 @@ impl TryFrom for ColumnDataTypeWrapper { ConcreteDataType::UInt64(_) => ColumnDataType::Uint64, ConcreteDataType::Float32(_) => ColumnDataType::Float32, ConcreteDataType::Float64(_) => ColumnDataType::Float64, - ConcreteDataType::Binary(_) => ColumnDataType::Binary, + ConcreteDataType::Binary(_) | ConcreteDataType::Json(_) => ColumnDataType::Binary, ConcreteDataType::String(_) => ColumnDataType::String, ConcreteDataType::Date(_) => ColumnDataType::Date, ConcreteDataType::DateTime(_) => ColumnDataType::Datetime, @@ -259,7 +258,6 @@ impl TryFrom for ColumnDataTypeWrapper { IntervalType::MonthDayNano(_) => ColumnDataType::IntervalMonthDayNano, }, ConcreteDataType::Decimal128(_) => ColumnDataType::Decimal128, - ConcreteDataType::Json(_) => ColumnDataType::Json, ConcreteDataType::Null(_) | ConcreteDataType::List(_) | ConcreteDataType::Dictionary(_) @@ -397,10 +395,6 @@ pub fn values_with_capacity(datatype: ColumnDataType, capacity: usize) -> Values decimal128_values: Vec::with_capacity(capacity), ..Default::default() }, - ColumnDataType::Json => Values { - json_values: Vec::with_capacity(capacity), - ..Default::default() - }, } } @@ -575,7 +569,6 @@ pub fn pb_value_to_value_ref<'a>( )) } } - ValueData::JsonValue(v) => ValueRef::Json(v), } } @@ -840,7 +833,12 @@ pub fn is_column_type_value_eq( expect_type: &ConcreteDataType, ) -> bool { ColumnDataTypeWrapper::try_new(type_value, type_extension) - .map(|wrapper| ConcreteDataType::from(wrapper) == *expect_type) + .map(|wrapper| { + let datatype = ConcreteDataType::from(wrapper); + (datatype == *expect_type) + || (datatype == ConcreteDataType::binary_datatype() + && *expect_type == ConcreteDataType::json_datatype()) + }) .unwrap_or(false) } @@ -938,7 +936,7 @@ pub fn to_proto_value(value: Value) -> Option { value_data: Some(ValueData::Decimal128Value(convert_to_pb_decimal128(v))), }, Value::Json(v) => v1::Value { - value_data: Some(ValueData::JsonValue(v.to_vec())), + value_data: Some(ValueData::BinaryValue(v.to_vec())), }, Value::List(_) | Value::Duration(_) => return None, }; @@ -978,7 +976,6 @@ pub fn proto_value_type(value: &v1::Value) -> Option { ValueData::IntervalDayTimeValue(_) => ColumnDataType::IntervalDayTime, ValueData::IntervalMonthDayNanoValue(_) => ColumnDataType::IntervalMonthDayNano, ValueData::Decimal128Value(_) => ColumnDataType::Decimal128, - ValueData::JsonValue(_) => ColumnDataType::Json, }; Some(value_type) } @@ -1036,7 +1033,7 @@ pub fn value_to_grpc_value(value: Value) -> GrpcValue { } }), Value::Decimal128(v) => Some(ValueData::Decimal128Value(convert_to_pb_decimal128(v))), - Value::Json(v) => Some(ValueData::JsonValue(v.to_vec())), + Value::Json(v) => Some(ValueData::BinaryValue(v.to_vec())), Value::List(_) | Value::Duration(_) => unreachable!(), }, } diff --git a/src/operator/src/req_convert/common.rs b/src/operator/src/req_convert/common.rs index b6a859f744dc..3994b32fc7f7 100644 --- a/src/operator/src/req_convert/common.rs +++ b/src/operator/src/req_convert/common.rs @@ -164,7 +164,6 @@ fn push_column_to_rows(column: Column, rows: &mut [Row]) -> Result<()> { interval_month_day_nano_values ), (Decimal128, Decimal128Value, decimal128_values), - (Json, JsonValue, json_values), ); Ok(())