Repository navigation
Review use of panic in datafusion-proto crate #3365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dddaefe
removed panics from proto crate
comphead 7f0dee3
Merge branch 'master' into proto-no-panic
comphead 0c6c593
fixes
comphead 227e0e0
fixed comments
comphead 713c5a0
fix build
comphead 38afffd
fixed comments
comphead 3512cdd
Fixing proto json
comphead 8138d9a
formatting
comphead 4e6e920
fix build
comphead 625fcf0
addresed comments
comphead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,10 +224,12 @@ impl From<&DataType> for protobuf::arrow_type::ArrowTypeEnum { | |
| fractional: *fractional as u64, | ||
| }), | ||
| DataType::Decimal256(_, _) => { | ||
| unimplemented!("The Decimal256 data type is not yet supported") | ||
| unimplemented!("Proto serialization error: The Decimal256 data type is not yet supported") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #3401 |
||
| } | ||
| DataType::Map(_, _) => { | ||
| unimplemented!("The Map data type is not yet supported") | ||
| unimplemented!( | ||
| "Proto serialization error: The Map data type is not yet supported" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -612,7 +614,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |
| expr_type: Some(ExprType::AggregateExpr(aggregate_expr)), | ||
| } | ||
| } | ||
| Expr::ScalarVariable(_, _) => unimplemented!(), | ||
| Expr::ScalarVariable(_, _) => return Err(Error::General("Proto serialization error: Scalar Variable not supported".to_string())), | ||
| Expr::ScalarFunction { ref fun, ref args } => { | ||
| let fun: protobuf::ScalarFunction = fun.try_into()?; | ||
| let args: Vec<Self> = args | ||
|
|
@@ -820,7 +822,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |
| Expr::ScalarSubquery(_) | Expr::InSubquery { .. } | Expr::Exists { .. } => { | ||
| // we would need to add logical plan operators to datafusion.proto to support this | ||
| // see discussion in https://github.com/apache/arrow-datafusion/issues/2565 | ||
| unimplemented!("subquery expressions are not supported yet") | ||
| return Err(Error::General("Proto serialization error: Expr::ScalarSubquery(_) | Expr::InSubquery { .. } | Expr::Exists { .. } not supported".to_string())) | ||
| } | ||
| Expr::GetIndexedField { key, expr } => Self { | ||
| expr_type: Some(ExprType::GetIndexedField(Box::new( | ||
|
|
@@ -865,7 +867,8 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode { | |
| })), | ||
| }, | ||
|
|
||
| Expr::QualifiedWildcard { .. } | Expr::TryCast { .. } => unimplemented!(), | ||
| Expr::QualifiedWildcard { .. } | Expr::TryCast { .. } => | ||
| return Err(Error::General("Proto serialization error: Expr::QualifiedWildcard { .. } | Expr::TryCast { .. } not supported".to_string())), | ||
| }; | ||
|
|
||
| Ok(expr_node) | ||
|
|
@@ -945,127 +948,115 @@ impl TryFrom<&ScalarValue> for protobuf::ScalarValue { | |
| Value::LargeUtf8Value(s.to_owned()) | ||
| }) | ||
| } | ||
| scalar::ScalarValue::List(value, boxed_field) => { | ||
| println!("Current field of list: {:?}", boxed_field); | ||
| match value { | ||
| Some(values) => { | ||
| if values.is_empty() { | ||
| protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::ListValue( | ||
| protobuf::ScalarListValue { | ||
| field: Some(boxed_field.as_ref().into()), | ||
| values: Vec::new(), | ||
| }, | ||
| )), | ||
| scalar::ScalarValue::List(value, boxed_field) => match value { | ||
| Some(values) => { | ||
| if values.is_empty() { | ||
| protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::ListValue( | ||
| protobuf::ScalarListValue { | ||
| field: Some(boxed_field.as_ref().into()), | ||
| values: Vec::new(), | ||
| }, | ||
| )), | ||
| } | ||
| } else { | ||
| let scalar_type = match boxed_field.data_type() { | ||
| DataType::List(field) => field.as_ref().data_type(), | ||
| unsupported => { | ||
| return Err(Error::General(format!("Proto serialization error: {:?} not supported to convert to DataType::List", unsupported))); | ||
| } | ||
| } else { | ||
| let scalar_type = match boxed_field.data_type() { | ||
| DataType::List(field) => field.as_ref().data_type(), | ||
| unsupported => { | ||
| todo!("Proper error handling {}", unsupported) | ||
| } | ||
| }; | ||
| println!("Current scalar type for list: {:?}", scalar_type); | ||
| }; | ||
|
|
||
| let type_checked_values: Vec<protobuf::ScalarValue> = values | ||
| .iter() | ||
| .map(|scalar| match (scalar, scalar_type) { | ||
| ( | ||
| scalar::ScalarValue::List(_, list_type), | ||
| DataType::List(field), | ||
| ) => { | ||
| if let DataType::List(list_field) = | ||
| list_type.data_type() | ||
| let type_checked_values: Vec<protobuf::ScalarValue> = values | ||
| .iter() | ||
| .map(|scalar| match (scalar, scalar_type) { | ||
| ( | ||
| scalar::ScalarValue::List(_, list_type), | ||
| DataType::List(field), | ||
| ) => { | ||
| if let DataType::List(list_field) = | ||
| list_type.data_type() | ||
| { | ||
| let scalar_datatype = field.data_type(); | ||
| let list_datatype = list_field.data_type(); | ||
| if std::mem::discriminant(list_datatype) | ||
| != std::mem::discriminant(scalar_datatype) | ||
| { | ||
| let scalar_datatype = field.data_type(); | ||
| let list_datatype = list_field.data_type(); | ||
| if std::mem::discriminant(list_datatype) | ||
| != std::mem::discriminant(scalar_datatype) | ||
| { | ||
| return Err( | ||
| Error::inconsistent_list_typing( | ||
| list_datatype, | ||
| scalar_datatype, | ||
| ), | ||
| ); | ||
| } | ||
| scalar.try_into() | ||
| } else { | ||
| Err(Error::inconsistent_list_designated( | ||
| scalar, | ||
| boxed_field.data_type(), | ||
| )) | ||
| return Err(Error::inconsistent_list_typing( | ||
| list_datatype, | ||
| scalar_datatype, | ||
| )); | ||
| } | ||
| } | ||
| ( | ||
| scalar::ScalarValue::Boolean(_), | ||
| DataType::Boolean, | ||
| ) => scalar.try_into(), | ||
| ( | ||
| scalar::ScalarValue::Float32(_), | ||
| DataType::Float32, | ||
| ) => scalar.try_into(), | ||
| ( | ||
| scalar::ScalarValue::Float64(_), | ||
| DataType::Float64, | ||
| ) => scalar.try_into(), | ||
| (scalar::ScalarValue::Int8(_), DataType::Int8) => { | ||
| scalar.try_into() | ||
| } else { | ||
| Err(Error::inconsistent_list_designated( | ||
| scalar, | ||
| boxed_field.data_type(), | ||
| )) | ||
| } | ||
| (scalar::ScalarValue::Int16(_), DataType::Int16) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int32(_), DataType::Int32) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int64(_), DataType::Int64) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::UInt8(_), DataType::UInt8) => { | ||
| scalar.try_into() | ||
| } | ||
| ( | ||
| scalar::ScalarValue::UInt16(_), | ||
| DataType::UInt16, | ||
| ) => scalar.try_into(), | ||
| ( | ||
| scalar::ScalarValue::UInt32(_), | ||
| DataType::UInt32, | ||
| ) => scalar.try_into(), | ||
| ( | ||
| scalar::ScalarValue::UInt64(_), | ||
| DataType::UInt64, | ||
| ) => scalar.try_into(), | ||
| (scalar::ScalarValue::Utf8(_), DataType::Utf8) => { | ||
| scalar.try_into() | ||
| } | ||
| ( | ||
| scalar::ScalarValue::LargeUtf8(_), | ||
| DataType::LargeUtf8, | ||
| ) => scalar.try_into(), | ||
| _ => Err(Error::inconsistent_list_designated( | ||
| scalar, | ||
| boxed_field.data_type(), | ||
| )), | ||
| }) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
| protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::ListValue( | ||
| protobuf::ScalarListValue { | ||
| field: Some(boxed_field.as_ref().into()), | ||
| values: type_checked_values, | ||
| }, | ||
| } | ||
| (scalar::ScalarValue::Boolean(_), DataType::Boolean) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Float32(_), DataType::Float32) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Float64(_), DataType::Float64) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int8(_), DataType::Int8) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int16(_), DataType::Int16) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int32(_), DataType::Int32) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Int64(_), DataType::Int64) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::UInt8(_), DataType::UInt8) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::UInt16(_), DataType::UInt16) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::UInt32(_), DataType::UInt32) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::UInt64(_), DataType::UInt64) => { | ||
| scalar.try_into() | ||
| } | ||
| (scalar::ScalarValue::Utf8(_), DataType::Utf8) => { | ||
| scalar.try_into() | ||
| } | ||
| ( | ||
| scalar::ScalarValue::LargeUtf8(_), | ||
| DataType::LargeUtf8, | ||
| ) => scalar.try_into(), | ||
| _ => Err(Error::inconsistent_list_designated( | ||
| scalar, | ||
| boxed_field.data_type(), | ||
| )), | ||
| } | ||
| }) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
| protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::ListValue( | ||
| protobuf::ScalarListValue { | ||
| field: Some(boxed_field.as_ref().into()), | ||
| values: type_checked_values, | ||
| }, | ||
| )), | ||
| } | ||
| } | ||
| None => protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::NullListValue( | ||
| boxed_field.as_ref().try_into()?, | ||
| )), | ||
| }, | ||
| } | ||
| } | ||
| None => protobuf::ScalarValue { | ||
| value: Some(protobuf::scalar_value::Value::NullListValue( | ||
| boxed_field.as_ref().try_into()?, | ||
| )), | ||
| }, | ||
| }, | ||
| datafusion::scalar::ScalarValue::Date32(val) => { | ||
| create_proto_scalar(val, PrimitiveScalarType::Date32, |s| { | ||
| Value::Date32Value(*s) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expectseems semi-reasonable in tests orbuild.rsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imho expect here gives more user friendly message than
.unwrapwith very generic textThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect is a definite improvement to
unwrapin my opinion too