@@ -23,11 +23,9 @@ use common_time::{Date, IntervalDayTime, IntervalMonthDayNano, IntervalYearMonth
2323use datatypes:: json:: value:: { JsonNumber , JsonValue , JsonValueRef , JsonVariant } ;
2424use datatypes:: prelude:: { ConcreteDataType , ValueRef } ;
2525use datatypes:: types:: {
26- IntervalType , JsonFormat , StructField , StructType , TimeType , TimestampType ,
27- } ;
28- use datatypes:: value:: {
29- ListValue , ListValueRef , OrderedF32 , OrderedF64 , StructValue , StructValueRef , Value ,
26+ IntervalType , JsonFormat , JsonType , StructField , StructType , TimeType , TimestampType ,
3027} ;
28+ use datatypes:: value:: { ListValueRef , OrderedF32 , OrderedF64 , StructValueRef , Value } ;
3129use datatypes:: vectors:: VectorRef ;
3230use greptime_proto:: v1:: column_data_type_extension:: TypeExt ;
3331use greptime_proto:: v1:: ddl_request:: Expr ;
@@ -127,6 +125,7 @@ impl From<ColumnDataTypeWrapper> for ConcreteDataType {
127125 } ;
128126 ConcreteDataType :: json_native_datatype ( inner_type. into ( ) )
129127 }
128+ None => ConcreteDataType :: Json ( JsonType :: empty ( ) ) ,
130129 _ => {
131130 // invalid state, type extension is missing or invalid
132131 ConcreteDataType :: null_datatype ( )
@@ -405,19 +404,22 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
405404 JsonFormat :: Jsonb => Some ( ColumnDataTypeExtension {
406405 type_ext : Some ( TypeExt :: JsonType ( JsonTypeExtension :: JsonBinary . into ( ) ) ) ,
407406 } ) ,
408- JsonFormat :: Native ( inner) => {
407+ JsonFormat :: Native ( inner) => ( !ConcreteDataType :: from ( inner. as_ref ( ) )
408+ . is_null ( ) )
409+ . then ( || {
409410 let inner_type = ColumnDataTypeWrapper :: try_from (
410411 ConcreteDataType :: from ( inner. as_ref ( ) ) ,
411412 ) ?;
412- Some ( ColumnDataTypeExtension {
413+ Ok ( ColumnDataTypeExtension {
413414 type_ext : Some ( TypeExt :: JsonNativeType ( Box :: new (
414415 JsonNativeTypeExtension {
415416 datatype : inner_type. datatype . into ( ) ,
416417 datatype_extension : inner_type. datatype_ext . map ( Box :: new) ,
417418 } ,
418419 ) ) ) ,
419420 } )
420- }
421+ } )
422+ . transpose ( ) ?,
421423 }
422424 } else {
423425 None
@@ -824,116 +826,11 @@ pub fn is_column_type_value_eq(
824826 ColumnDataTypeWrapper :: try_new ( type_value, type_extension)
825827 . map ( |wrapper| {
826828 let datatype = ConcreteDataType :: from ( wrapper) ;
827- expect_type == & datatype
829+ expect_type. is_json ( ) && datatype . is_json ( ) || & datatype == expect_type
828830 } )
829831 . unwrap_or ( false )
830832}
831833
832- /// Convert value into proto's value.
833- pub fn to_proto_value ( value : Value ) -> v1:: Value {
834- match value {
835- Value :: Null => v1:: Value { value_data : None } ,
836- Value :: Boolean ( v) => v1:: Value {
837- value_data : Some ( ValueData :: BoolValue ( v) ) ,
838- } ,
839- Value :: UInt8 ( v) => v1:: Value {
840- value_data : Some ( ValueData :: U8Value ( v. into ( ) ) ) ,
841- } ,
842- Value :: UInt16 ( v) => v1:: Value {
843- value_data : Some ( ValueData :: U16Value ( v. into ( ) ) ) ,
844- } ,
845- Value :: UInt32 ( v) => v1:: Value {
846- value_data : Some ( ValueData :: U32Value ( v) ) ,
847- } ,
848- Value :: UInt64 ( v) => v1:: Value {
849- value_data : Some ( ValueData :: U64Value ( v) ) ,
850- } ,
851- Value :: Int8 ( v) => v1:: Value {
852- value_data : Some ( ValueData :: I8Value ( v. into ( ) ) ) ,
853- } ,
854- Value :: Int16 ( v) => v1:: Value {
855- value_data : Some ( ValueData :: I16Value ( v. into ( ) ) ) ,
856- } ,
857- Value :: Int32 ( v) => v1:: Value {
858- value_data : Some ( ValueData :: I32Value ( v) ) ,
859- } ,
860- Value :: Int64 ( v) => v1:: Value {
861- value_data : Some ( ValueData :: I64Value ( v) ) ,
862- } ,
863- Value :: Float32 ( v) => v1:: Value {
864- value_data : Some ( ValueData :: F32Value ( * v) ) ,
865- } ,
866- Value :: Float64 ( v) => v1:: Value {
867- value_data : Some ( ValueData :: F64Value ( * v) ) ,
868- } ,
869- Value :: String ( v) => v1:: Value {
870- value_data : Some ( ValueData :: StringValue ( v. as_utf8 ( ) . to_string ( ) ) ) ,
871- } ,
872- Value :: Binary ( v) => v1:: Value {
873- value_data : Some ( ValueData :: BinaryValue ( v. to_vec ( ) ) ) ,
874- } ,
875- Value :: Date ( v) => v1:: Value {
876- value_data : Some ( ValueData :: DateValue ( v. val ( ) ) ) ,
877- } ,
878- Value :: Timestamp ( v) => match v. unit ( ) {
879- TimeUnit :: Second => v1:: Value {
880- value_data : Some ( ValueData :: TimestampSecondValue ( v. value ( ) ) ) ,
881- } ,
882- TimeUnit :: Millisecond => v1:: Value {
883- value_data : Some ( ValueData :: TimestampMillisecondValue ( v. value ( ) ) ) ,
884- } ,
885- TimeUnit :: Microsecond => v1:: Value {
886- value_data : Some ( ValueData :: TimestampMicrosecondValue ( v. value ( ) ) ) ,
887- } ,
888- TimeUnit :: Nanosecond => v1:: Value {
889- value_data : Some ( ValueData :: TimestampNanosecondValue ( v. value ( ) ) ) ,
890- } ,
891- } ,
892- Value :: Time ( v) => match v. unit ( ) {
893- TimeUnit :: Second => v1:: Value {
894- value_data : Some ( ValueData :: TimeSecondValue ( v. value ( ) ) ) ,
895- } ,
896- TimeUnit :: Millisecond => v1:: Value {
897- value_data : Some ( ValueData :: TimeMillisecondValue ( v. value ( ) ) ) ,
898- } ,
899- TimeUnit :: Microsecond => v1:: Value {
900- value_data : Some ( ValueData :: TimeMicrosecondValue ( v. value ( ) ) ) ,
901- } ,
902- TimeUnit :: Nanosecond => v1:: Value {
903- value_data : Some ( ValueData :: TimeNanosecondValue ( v. value ( ) ) ) ,
904- } ,
905- } ,
906- Value :: IntervalYearMonth ( v) => v1:: Value {
907- value_data : Some ( ValueData :: IntervalYearMonthValue ( v. to_i32 ( ) ) ) ,
908- } ,
909- Value :: IntervalDayTime ( v) => v1:: Value {
910- value_data : Some ( ValueData :: IntervalDayTimeValue ( v. to_i64 ( ) ) ) ,
911- } ,
912- Value :: IntervalMonthDayNano ( v) => v1:: Value {
913- value_data : Some ( ValueData :: IntervalMonthDayNanoValue (
914- convert_month_day_nano_to_pb ( v) ,
915- ) ) ,
916- } ,
917- Value :: Decimal128 ( v) => v1:: Value {
918- value_data : Some ( ValueData :: Decimal128Value ( convert_to_pb_decimal128 ( v) ) ) ,
919- } ,
920- Value :: List ( list_value) => v1:: Value {
921- value_data : Some ( ValueData :: ListValue ( v1:: ListValue {
922- items : convert_list_to_pb_values ( list_value) ,
923- } ) ) ,
924- } ,
925- Value :: Struct ( struct_value) => v1:: Value {
926- value_data : Some ( ValueData :: StructValue ( v1:: StructValue {
927- items : convert_struct_to_pb_values ( struct_value) ,
928- } ) ) ,
929- } ,
930- Value :: Json ( v) => v1:: Value {
931- value_data : Some ( ValueData :: JsonValue ( encode_json_value ( * v) ) ) ,
932- } ,
933- Value :: Duration ( _) => v1:: Value { value_data : None } ,
934- }
935- }
936-
937834fn encode_json_value ( value : JsonValue ) -> v1:: JsonValue {
938835 fn helper ( json : JsonVariant ) -> v1:: JsonValue {
939836 let value = match json {
@@ -994,22 +891,6 @@ fn decode_json_value(value: &v1::JsonValue) -> JsonValueRef<'_> {
994891 }
995892}
996893
997- fn convert_list_to_pb_values ( list_value : ListValue ) -> Vec < v1:: Value > {
998- list_value
999- . take_items ( )
1000- . into_iter ( )
1001- . map ( to_proto_value)
1002- . collect ( )
1003- }
1004-
1005- fn convert_struct_to_pb_values ( struct_value : StructValue ) -> Vec < v1:: Value > {
1006- struct_value
1007- . take_items ( )
1008- . into_iter ( )
1009- . map ( to_proto_value)
1010- . collect ( )
1011- }
1012-
1013894/// Returns the [ColumnDataTypeWrapper] of the value.
1014895///
1015896/// If value is null, returns `None`.
@@ -1211,6 +1092,7 @@ mod tests {
12111092 use common_time:: interval:: IntervalUnit ;
12121093 use datatypes:: scalars:: ScalarVector ;
12131094 use datatypes:: types:: { Int8Type , Int32Type , UInt8Type , UInt32Type } ;
1095+ use datatypes:: value:: { ListValue , StructValue } ;
12141096 use datatypes:: vectors:: {
12151097 BooleanVector , DateVector , Float32Vector , PrimitiveVector , StringVector ,
12161098 } ;
@@ -1788,7 +1670,7 @@ mod tests {
17881670 Arc :: new ( ConcreteDataType :: boolean_datatype ( ) ) ,
17891671 ) ) ;
17901672
1791- let pb_value = to_proto_value ( value) ;
1673+ let pb_value = value_to_grpc_value ( value) ;
17921674
17931675 match pb_value. value_data . unwrap ( ) {
17941676 ValueData :: ListValue ( pb_list_value) => {
@@ -1817,7 +1699,7 @@ mod tests {
18171699 . unwrap ( ) ,
18181700 ) ;
18191701
1820- let pb_value = to_proto_value ( value) ;
1702+ let pb_value = value_to_grpc_value ( value) ;
18211703
18221704 match pb_value. value_data . unwrap ( ) {
18231705 ValueData :: StructValue ( pb_struct_value) => {
0 commit comments