-
Notifications
You must be signed in to change notification settings - Fork 3.7k
ARROW-4749: [Rust] Return Result for RecordBatch::new() #3800
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
Conversation
@andygrove @paddyhoran PTAL when you get a chance |
@andygrove there's a failure in sql.rs re. mismatching column and batch lengths. If that's not supposed to error, I can remove the validation on |
@nevi-me Nice! You found a bug in aggregate schemas ... I couldn't figure out how to push the fix direct to your branch but here is the new code (for aggregate.rs around line 188):
You can also look at the ARROW-4749 branch in my repo (andygrove). |
I'll fix it manually when I get home. I normally submit a PR on the author's branch |
LGTM, but returning result from |
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.
LGTM except a few nits. Also as @kszucs mentioned, maybe we can change new
to try_new
to reflect the fact that it returns a Result
now?
rust/arrow/examples/dynamic_types.rs
Outdated
@@ -58,7 +58,8 @@ fn main() { | |||
]); | |||
|
|||
// build a record batch | |||
let batch = RecordBatch::new(Arc::new(schema), vec![Arc::new(id), Arc::new(nested)]); | |||
let batch = | |||
RecordBatch::new(Arc::new(schema), vec![Arc::new(id), Arc::new(nested)]).unwrap(); |
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.
nit: you can replace unwrap()
with ?
for better error message.
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.
The function doesn't return a Result, so I can't ?
there. Should I leave the unwrap?
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.
In main
you can actually use ?
, see here.
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.
If my main has a Result
return type? I tried it before commenting, and I got an error about needing to implement TryFrom
.
I've got it working with returning Result<()>
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.
Yes you are right - seems you have to change the main
interface and add return Ok(())
from the main as well.. I guess it may not worth it for this purpose. We can just keep as it is.
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.
:( I had already changed it, can I keep it the way it is now? If I need to change anything else on the PR I'll revert it back to its original form
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.
OK. Let's keep as it is.
rust/arrow/src/record_batch.rs
Outdated
pub fn new(schema: Arc<Schema>, columns: Vec<ArrayRef>) -> Result<Self> { | ||
// check that there are some columns | ||
if columns.is_empty() { | ||
return Err(ArrowError::ParseError( |
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.
nit: not sure ParseError
is appropriate here. Do we have other candidate such as InvalidArgumentError
?
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.
InvalidArgumentError
sounds good, I was avoiding adding another error option
Adds more validation between schemas and columns, returning an error when record types mismatch the schema
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.
LGTM - agree with the other comments on this PR
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.
LGTM.
Adds more validation between schemas and columns,
returning an error when record types mismatch the schema