@@ -224,10 +224,12 @@ impl From<&DataType> for protobuf::arrow_type::ArrowTypeEnum {
224224 fractional : * fractional as u64 ,
225225 } ) ,
226226 DataType :: Decimal256 ( _, _) => {
227- unimplemented ! ( "The Decimal256 data type is not yet supported" )
227+ unimplemented ! ( "Proto serialization error: The Decimal256 data type is not yet supported" )
228228 }
229229 DataType :: Map ( _, _) => {
230- unimplemented ! ( "The Map data type is not yet supported" )
230+ unimplemented ! (
231+ "Proto serialization error: The Map data type is not yet supported"
232+ )
231233 }
232234 }
233235 }
@@ -612,7 +614,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
612614 expr_type : Some ( ExprType :: AggregateExpr ( aggregate_expr) ) ,
613615 }
614616 }
615- Expr :: ScalarVariable ( _, _) => unimplemented ! ( ) ,
617+ Expr :: ScalarVariable ( _, _) => return Err ( Error :: General ( "Proto serialization error: Scalar Variable not supported" . to_string ( ) ) ) ,
616618 Expr :: ScalarFunction { ref fun, ref args } => {
617619 let fun: protobuf:: ScalarFunction = fun. try_into ( ) ?;
618620 let args: Vec < Self > = args
@@ -820,7 +822,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
820822 Expr :: ScalarSubquery ( _) | Expr :: InSubquery { .. } | Expr :: Exists { .. } => {
821823 // we would need to add logical plan operators to datafusion.proto to support this
822824 // see discussion in https://github.com/apache/arrow-datafusion/issues/2565
823- unimplemented ! ( "subquery expressions are not supported yet" )
825+ return Err ( Error :: General ( "Proto serialization error: Expr::ScalarSubquery(_) | Expr::InSubquery { .. } | Expr::Exists { .. } not supported" . to_string ( ) ) )
824826 }
825827 Expr :: GetIndexedField { key, expr } => Self {
826828 expr_type : Some ( ExprType :: GetIndexedField ( Box :: new (
@@ -865,7 +867,8 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
865867 } ) ) ,
866868 } ,
867869
868- Expr :: QualifiedWildcard { .. } | Expr :: TryCast { .. } => unimplemented ! ( ) ,
870+ Expr :: QualifiedWildcard { .. } | Expr :: TryCast { .. } =>
871+ return Err ( Error :: General ( "Proto serialization error: Expr::QualifiedWildcard { .. } | Expr::TryCast { .. } not supported" . to_string ( ) ) ) ,
869872 } ;
870873
871874 Ok ( expr_node)
@@ -945,127 +948,115 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue {
945948 Value :: LargeUtf8Value ( s. to_owned ( ) )
946949 } )
947950 }
948- scalar:: ScalarValue :: List ( value, boxed_field) => {
949- println ! ( "Current field of list: {:?}" , boxed_field) ;
950- match value {
951- Some ( values) => {
952- if values. is_empty ( ) {
953- protobuf:: ScalarValue {
954- value : Some ( protobuf:: scalar_value:: Value :: ListValue (
955- protobuf:: ScalarListValue {
956- field : Some ( boxed_field. as_ref ( ) . into ( ) ) ,
957- values : Vec :: new ( ) ,
958- } ,
959- ) ) ,
951+ scalar:: ScalarValue :: List ( value, boxed_field) => match value {
952+ Some ( values) => {
953+ if values. is_empty ( ) {
954+ protobuf:: ScalarValue {
955+ value : Some ( protobuf:: scalar_value:: Value :: ListValue (
956+ protobuf:: ScalarListValue {
957+ field : Some ( boxed_field. as_ref ( ) . into ( ) ) ,
958+ values : Vec :: new ( ) ,
959+ } ,
960+ ) ) ,
961+ }
962+ } else {
963+ let scalar_type = match boxed_field. data_type ( ) {
964+ DataType :: List ( field) => field. as_ref ( ) . data_type ( ) ,
965+ unsupported => {
966+ return Err ( Error :: General ( format ! ( "Proto serialization error: {:?} not supported to convert to DataType::List" , unsupported) ) ) ;
960967 }
961- } else {
962- let scalar_type = match boxed_field. data_type ( ) {
963- DataType :: List ( field) => field. as_ref ( ) . data_type ( ) ,
964- unsupported => {
965- todo ! ( "Proper error handling {}" , unsupported)
966- }
967- } ;
968- println ! ( "Current scalar type for list: {:?}" , scalar_type) ;
968+ } ;
969969
970- let type_checked_values: Vec < protobuf:: ScalarValue > = values
971- . iter ( )
972- . map ( |scalar| match ( scalar, scalar_type) {
973- (
974- scalar:: ScalarValue :: List ( _, list_type) ,
975- DataType :: List ( field) ,
976- ) => {
977- if let DataType :: List ( list_field) =
978- list_type. data_type ( )
970+ let type_checked_values: Vec < protobuf:: ScalarValue > = values
971+ . iter ( )
972+ . map ( |scalar| match ( scalar, scalar_type) {
973+ (
974+ scalar:: ScalarValue :: List ( _, list_type) ,
975+ DataType :: List ( field) ,
976+ ) => {
977+ if let DataType :: List ( list_field) =
978+ list_type. data_type ( )
979+ {
980+ let scalar_datatype = field. data_type ( ) ;
981+ let list_datatype = list_field. data_type ( ) ;
982+ if std:: mem:: discriminant ( list_datatype)
983+ != std:: mem:: discriminant ( scalar_datatype)
979984 {
980- let scalar_datatype = field. data_type ( ) ;
981- let list_datatype = list_field. data_type ( ) ;
982- if std:: mem:: discriminant ( list_datatype)
983- != std:: mem:: discriminant ( scalar_datatype)
984- {
985- return Err (
986- Error :: inconsistent_list_typing (
987- list_datatype,
988- scalar_datatype,
989- ) ,
990- ) ;
991- }
992- scalar. try_into ( )
993- } else {
994- Err ( Error :: inconsistent_list_designated (
995- scalar,
996- boxed_field. data_type ( ) ,
997- ) )
985+ return Err ( Error :: inconsistent_list_typing (
986+ list_datatype,
987+ scalar_datatype,
988+ ) ) ;
998989 }
999- }
1000- (
1001- scalar:: ScalarValue :: Boolean ( _) ,
1002- DataType :: Boolean ,
1003- ) => scalar. try_into ( ) ,
1004- (
1005- scalar:: ScalarValue :: Float32 ( _) ,
1006- DataType :: Float32 ,
1007- ) => scalar. try_into ( ) ,
1008- (
1009- scalar:: ScalarValue :: Float64 ( _) ,
1010- DataType :: Float64 ,
1011- ) => scalar. try_into ( ) ,
1012- ( scalar:: ScalarValue :: Int8 ( _) , DataType :: Int8 ) => {
1013990 scalar. try_into ( )
991+ } else {
992+ Err ( Error :: inconsistent_list_designated (
993+ scalar,
994+ boxed_field. data_type ( ) ,
995+ ) )
1014996 }
1015- ( scalar:: ScalarValue :: Int16 ( _) , DataType :: Int16 ) => {
1016- scalar. try_into ( )
1017- }
1018- ( scalar:: ScalarValue :: Int32 ( _) , DataType :: Int32 ) => {
1019- scalar. try_into ( )
1020- }
1021- ( scalar:: ScalarValue :: Int64 ( _) , DataType :: Int64 ) => {
1022- scalar. try_into ( )
1023- }
1024- ( scalar:: ScalarValue :: UInt8 ( _) , DataType :: UInt8 ) => {
1025- scalar. try_into ( )
1026- }
1027- (
1028- scalar:: ScalarValue :: UInt16 ( _) ,
1029- DataType :: UInt16 ,
1030- ) => scalar. try_into ( ) ,
1031- (
1032- scalar:: ScalarValue :: UInt32 ( _) ,
1033- DataType :: UInt32 ,
1034- ) => scalar. try_into ( ) ,
1035- (
1036- scalar:: ScalarValue :: UInt64 ( _) ,
1037- DataType :: UInt64 ,
1038- ) => scalar. try_into ( ) ,
1039- ( scalar:: ScalarValue :: Utf8 ( _) , DataType :: Utf8 ) => {
1040- scalar. try_into ( )
1041- }
1042- (
1043- scalar:: ScalarValue :: LargeUtf8 ( _) ,
1044- DataType :: LargeUtf8 ,
1045- ) => scalar. try_into ( ) ,
1046- _ => Err ( Error :: inconsistent_list_designated (
1047- scalar,
1048- boxed_field. data_type ( ) ,
1049- ) ) ,
1050- } )
1051- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
1052- protobuf:: ScalarValue {
1053- value : Some ( protobuf:: scalar_value:: Value :: ListValue (
1054- protobuf:: ScalarListValue {
1055- field : Some ( boxed_field. as_ref ( ) . into ( ) ) ,
1056- values : type_checked_values,
1057- } ,
997+ }
998+ ( scalar:: ScalarValue :: Boolean ( _) , DataType :: Boolean ) => {
999+ scalar. try_into ( )
1000+ }
1001+ ( scalar:: ScalarValue :: Float32 ( _) , DataType :: Float32 ) => {
1002+ scalar. try_into ( )
1003+ }
1004+ ( scalar:: ScalarValue :: Float64 ( _) , DataType :: Float64 ) => {
1005+ scalar. try_into ( )
1006+ }
1007+ ( scalar:: ScalarValue :: Int8 ( _) , DataType :: Int8 ) => {
1008+ scalar. try_into ( )
1009+ }
1010+ ( scalar:: ScalarValue :: Int16 ( _) , DataType :: Int16 ) => {
1011+ scalar. try_into ( )
1012+ }
1013+ ( scalar:: ScalarValue :: Int32 ( _) , DataType :: Int32 ) => {
1014+ scalar. try_into ( )
1015+ }
1016+ ( scalar:: ScalarValue :: Int64 ( _) , DataType :: Int64 ) => {
1017+ scalar. try_into ( )
1018+ }
1019+ ( scalar:: ScalarValue :: UInt8 ( _) , DataType :: UInt8 ) => {
1020+ scalar. try_into ( )
1021+ }
1022+ ( scalar:: ScalarValue :: UInt16 ( _) , DataType :: UInt16 ) => {
1023+ scalar. try_into ( )
1024+ }
1025+ ( scalar:: ScalarValue :: UInt32 ( _) , DataType :: UInt32 ) => {
1026+ scalar. try_into ( )
1027+ }
1028+ ( scalar:: ScalarValue :: UInt64 ( _) , DataType :: UInt64 ) => {
1029+ scalar. try_into ( )
1030+ }
1031+ ( scalar:: ScalarValue :: Utf8 ( _) , DataType :: Utf8 ) => {
1032+ scalar. try_into ( )
1033+ }
1034+ (
1035+ scalar:: ScalarValue :: LargeUtf8 ( _) ,
1036+ DataType :: LargeUtf8 ,
1037+ ) => scalar. try_into ( ) ,
1038+ _ => Err ( Error :: inconsistent_list_designated (
1039+ scalar,
1040+ boxed_field. data_type ( ) ,
10581041 ) ) ,
1059- }
1042+ } )
1043+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
1044+ protobuf:: ScalarValue {
1045+ value : Some ( protobuf:: scalar_value:: Value :: ListValue (
1046+ protobuf:: ScalarListValue {
1047+ field : Some ( boxed_field. as_ref ( ) . into ( ) ) ,
1048+ values : type_checked_values,
1049+ } ,
1050+ ) ) ,
10601051 }
10611052 }
1062- None => protobuf:: ScalarValue {
1063- value : Some ( protobuf:: scalar_value:: Value :: NullListValue (
1064- boxed_field. as_ref ( ) . try_into ( ) ?,
1065- ) ) ,
1066- } ,
10671053 }
1068- }
1054+ None => protobuf:: ScalarValue {
1055+ value : Some ( protobuf:: scalar_value:: Value :: NullListValue (
1056+ boxed_field. as_ref ( ) . try_into ( ) ?,
1057+ ) ) ,
1058+ } ,
1059+ } ,
10691060 datafusion:: scalar:: ScalarValue :: Date32 ( val) => {
10701061 create_proto_scalar ( val, PrimitiveScalarType :: Date32 , |s| {
10711062 Value :: Date32Value ( * s)
0 commit comments