@@ -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 ( )
@@ -441,19 +440,22 @@ impl TryFrom<ConcreteDataType> for ColumnDataTypeWrapper {
441440 JsonFormat :: Jsonb => Some ( ColumnDataTypeExtension {
442441 type_ext : Some ( TypeExt :: JsonType ( JsonTypeExtension :: JsonBinary . into ( ) ) ) ,
443442 } ) ,
444- JsonFormat :: Native ( inner) => {
443+ JsonFormat :: Native ( inner) => ( !ConcreteDataType :: from ( inner. as_ref ( ) )
444+ . is_null ( ) )
445+ . then ( || {
445446 let inner_type = ColumnDataTypeWrapper :: try_from (
446447 ConcreteDataType :: from ( inner. as_ref ( ) ) ,
447448 ) ?;
448- Some ( ColumnDataTypeExtension {
449+ Ok ( ColumnDataTypeExtension {
449450 type_ext : Some ( TypeExt :: JsonNativeType ( Box :: new (
450451 JsonNativeTypeExtension {
451452 datatype : inner_type. datatype . into ( ) ,
452453 datatype_extension : inner_type. datatype_ext . map ( Box :: new) ,
453454 } ,
454455 ) ) ) ,
455456 } )
456- }
457+ } )
458+ . transpose ( ) ?,
457459 }
458460 } else {
459461 None
@@ -882,116 +884,11 @@ pub fn is_column_type_value_eq(
882884 ColumnDataTypeWrapper :: try_new ( type_value, type_extension)
883885 . map ( |wrapper| {
884886 let datatype = ConcreteDataType :: from ( wrapper) ;
885- expect_type == & datatype
887+ expect_type. is_json ( ) && datatype . is_json ( ) || & datatype == expect_type
886888 } )
887889 . unwrap_or ( false )
888890}
889891
890- /// Convert value into proto's value.
891- pub fn to_proto_value ( value : Value ) -> v1:: Value {
892- match value {
893- Value :: Null => v1:: Value { value_data : None } ,
894- Value :: Boolean ( v) => v1:: Value {
895- value_data : Some ( ValueData :: BoolValue ( v) ) ,
896- } ,
897- Value :: UInt8 ( v) => v1:: Value {
898- value_data : Some ( ValueData :: U8Value ( v. into ( ) ) ) ,
899- } ,
900- Value :: UInt16 ( v) => v1:: Value {
901- value_data : Some ( ValueData :: U16Value ( v. into ( ) ) ) ,
902- } ,
903- Value :: UInt32 ( v) => v1:: Value {
904- value_data : Some ( ValueData :: U32Value ( v) ) ,
905- } ,
906- Value :: UInt64 ( v) => v1:: Value {
907- value_data : Some ( ValueData :: U64Value ( v) ) ,
908- } ,
909- Value :: Int8 ( v) => v1:: Value {
910- value_data : Some ( ValueData :: I8Value ( v. into ( ) ) ) ,
911- } ,
912- Value :: Int16 ( v) => v1:: Value {
913- value_data : Some ( ValueData :: I16Value ( v. into ( ) ) ) ,
914- } ,
915- Value :: Int32 ( v) => v1:: Value {
916- value_data : Some ( ValueData :: I32Value ( v) ) ,
917- } ,
918- Value :: Int64 ( v) => v1:: Value {
919- value_data : Some ( ValueData :: I64Value ( v) ) ,
920- } ,
921- Value :: Float32 ( v) => v1:: Value {
922- value_data : Some ( ValueData :: F32Value ( * v) ) ,
923- } ,
924- Value :: Float64 ( v) => v1:: Value {
925- value_data : Some ( ValueData :: F64Value ( * v) ) ,
926- } ,
927- Value :: String ( v) => v1:: Value {
928- value_data : Some ( ValueData :: StringValue ( v. as_utf8 ( ) . to_string ( ) ) ) ,
929- } ,
930- Value :: Binary ( v) => v1:: Value {
931- value_data : Some ( ValueData :: BinaryValue ( v. to_vec ( ) ) ) ,
932- } ,
933- Value :: Date ( v) => v1:: Value {
934- value_data : Some ( ValueData :: DateValue ( v. val ( ) ) ) ,
935- } ,
936- Value :: Timestamp ( v) => match v. unit ( ) {
937- TimeUnit :: Second => v1:: Value {
938- value_data : Some ( ValueData :: TimestampSecondValue ( v. value ( ) ) ) ,
939- } ,
940- TimeUnit :: Millisecond => v1:: Value {
941- value_data : Some ( ValueData :: TimestampMillisecondValue ( v. value ( ) ) ) ,
942- } ,
943- TimeUnit :: Microsecond => v1:: Value {
944- value_data : Some ( ValueData :: TimestampMicrosecondValue ( v. value ( ) ) ) ,
945- } ,
946- TimeUnit :: Nanosecond => v1:: Value {
947- value_data : Some ( ValueData :: TimestampNanosecondValue ( v. value ( ) ) ) ,
948- } ,
949- } ,
950- Value :: Time ( v) => match v. unit ( ) {
951- TimeUnit :: Second => v1:: Value {
952- value_data : Some ( ValueData :: TimeSecondValue ( v. value ( ) ) ) ,
953- } ,
954- TimeUnit :: Millisecond => v1:: Value {
955- value_data : Some ( ValueData :: TimeMillisecondValue ( v. value ( ) ) ) ,
956- } ,
957- TimeUnit :: Microsecond => v1:: Value {
958- value_data : Some ( ValueData :: TimeMicrosecondValue ( v. value ( ) ) ) ,
959- } ,
960- TimeUnit :: Nanosecond => v1:: Value {
961- value_data : Some ( ValueData :: TimeNanosecondValue ( v. value ( ) ) ) ,
962- } ,
963- } ,
964- Value :: IntervalYearMonth ( v) => v1:: Value {
965- value_data : Some ( ValueData :: IntervalYearMonthValue ( v. to_i32 ( ) ) ) ,
966- } ,
967- Value :: IntervalDayTime ( v) => v1:: Value {
968- value_data : Some ( ValueData :: IntervalDayTimeValue ( v. to_i64 ( ) ) ) ,
969- } ,
970- Value :: IntervalMonthDayNano ( v) => v1:: Value {
971- value_data : Some ( ValueData :: IntervalMonthDayNanoValue (
972- convert_month_day_nano_to_pb ( v) ,
973- ) ) ,
974- } ,
975- Value :: Decimal128 ( v) => v1:: Value {
976- value_data : Some ( ValueData :: Decimal128Value ( convert_to_pb_decimal128 ( v) ) ) ,
977- } ,
978- Value :: List ( list_value) => v1:: Value {
979- value_data : Some ( ValueData :: ListValue ( v1:: ListValue {
980- items : convert_list_to_pb_values ( list_value) ,
981- } ) ) ,
982- } ,
983- Value :: Struct ( struct_value) => v1:: Value {
984- value_data : Some ( ValueData :: StructValue ( v1:: StructValue {
985- items : convert_struct_to_pb_values ( struct_value) ,
986- } ) ) ,
987- } ,
988- Value :: Json ( v) => v1:: Value {
989- value_data : Some ( ValueData :: JsonValue ( encode_json_value ( * v) ) ) ,
990- } ,
991- Value :: Duration ( _) => v1:: Value { value_data : None } ,
992- }
993- }
994-
995892fn encode_json_value ( value : JsonValue ) -> v1:: JsonValue {
996893 fn helper ( json : JsonVariant ) -> v1:: JsonValue {
997894 let value = match json {
@@ -1052,22 +949,6 @@ fn decode_json_value(value: &v1::JsonValue) -> JsonValueRef<'_> {
1052949 }
1053950}
1054951
1055- fn convert_list_to_pb_values ( list_value : ListValue ) -> Vec < v1:: Value > {
1056- list_value
1057- . take_items ( )
1058- . into_iter ( )
1059- . map ( to_proto_value)
1060- . collect ( )
1061- }
1062-
1063- fn convert_struct_to_pb_values ( struct_value : StructValue ) -> Vec < v1:: Value > {
1064- struct_value
1065- . take_items ( )
1066- . into_iter ( )
1067- . map ( to_proto_value)
1068- . collect ( )
1069- }
1070-
1071952/// Returns the [ColumnDataTypeWrapper] of the value.
1072953///
1073954/// If value is null, returns `None`.
@@ -1269,6 +1150,7 @@ mod tests {
12691150 use common_time:: interval:: IntervalUnit ;
12701151 use datatypes:: scalars:: ScalarVector ;
12711152 use datatypes:: types:: { Int8Type , Int32Type , UInt8Type , UInt32Type } ;
1153+ use datatypes:: value:: { ListValue , StructValue } ;
12721154 use datatypes:: vectors:: {
12731155 BooleanVector , DateVector , Float32Vector , PrimitiveVector , StringVector ,
12741156 } ;
@@ -1872,7 +1754,7 @@ mod tests {
18721754 Arc :: new ( ConcreteDataType :: boolean_datatype ( ) ) ,
18731755 ) ) ;
18741756
1875- let pb_value = to_proto_value ( value) ;
1757+ let pb_value = value_to_grpc_value ( value) ;
18761758
18771759 match pb_value. value_data . unwrap ( ) {
18781760 ValueData :: ListValue ( pb_list_value) => {
@@ -1901,7 +1783,7 @@ mod tests {
19011783 . unwrap ( ) ,
19021784 ) ;
19031785
1904- let pb_value = to_proto_value ( value) ;
1786+ let pb_value = value_to_grpc_value ( value) ;
19051787
19061788 match pb_value. value_data . unwrap ( ) {
19071789 ValueData :: StructValue ( pb_struct_value) => {
0 commit comments