Skip to content

ARROW-4749: [Rust] Return Result for RecordBatch::new() - #3800

Closed
nevi-me wants to merge 5 commits into
apache:masterfrom
nevi-me:ARROW-4749
Closed

ARROW-4749: [Rust] Return Result for RecordBatch::new()#3800
nevi-me wants to merge 5 commits into
apache:masterfrom
nevi-me:ARROW-4749

Conversation

@nevi-me

@nevi-me nevi-me commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

Adds more validation between schemas and columns,
returning an error when record types mismatch the schema

@nevi-me

nevi-me commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

@andygrove @paddyhoran PTAL when you get a chance

@nevi-me

nevi-me commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

@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 RecordBatch::new()

@andygrove

andygrove commented Mar 4, 2019

Copy link
Copy Markdown
Member

@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):

 let mut output_fields: Vec<Field> = vec![];
                for expr in group_expr {
                    output_fields.push(expr_to_field(expr, input_schema.as_ref()));
                }
                for expr in aggr_expr {
                    output_fields.push(expr_to_field(expr, input_schema.as_ref()));
                }
                let rel = AggregateRelation::new(
                    Arc::new(Schema::new(output_fields)),
                    input_rel,
                    compiled_group_expr,
                    compiled_aggr_expr,
                );

You can also look at the ARROW-4749 branch in my repo (andygrove).

@nevi-me

nevi-me commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

I'll fix it manually when I get home. I normally submit a PR on the author's branch

@kszucs

kszucs commented Mar 5, 2019

Copy link
Copy Markdown
Member

LGTM, but returning result from new feels a bit odd to me, especially because other types' new return Self.

@sunchao sunchao left a comment

Copy link
Copy Markdown
Member

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?

Comment thread rust/arrow/examples/dynamic_types.rs Outdated

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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<()>

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Member

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.

Comment thread rust/arrow/src/record_batch.rs Outdated

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

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

@sunchao sunchao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants