Skip to content

ARROW-2384: [Rust] Additional test & Trait standardization#1818

Closed
max-sixty wants to merge 16 commits intoapache:masterfrom
max-sixty:rust-tweak
Closed

ARROW-2384: [Rust] Additional test & Trait standardization#1818
max-sixty wants to merge 16 commits intoapache:masterfrom
max-sixty:rust-tweak

Conversation

@max-sixty
Copy link
Contributor

A test for the string representation of a Schema.

& some standardization on Traits rather than their method

...but mainly getting my feet wet with rust & arrow

@andygrove
Copy link
Member

LGTM

@wesm
Copy link
Member

wesm commented Apr 1, 2018

Can you create a JIRA? @cpcloud @xhochy @pitrou could I ask you to help with maintaining the Rust patches while I am away for the project the rest of this month?

@pitrou
Copy link
Member

pitrou commented Apr 1, 2018

I've never used Rust but I can provide non-technical guidance.

Copy link
Contributor

@sadikovi sadikovi left a comment

Choose a reason for hiding this comment

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

Thanks a lot for making the change! I just left some optional minor comments that could improve readability.


impl Field {

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall we rustfmt the whole thing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t know, I am not very familiar with how Rust project is set up for Arrow:). It might be easier to fix manually, if you want to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andygrove OK with you to run rustfmt on all the files?

Copy link

Choose a reason for hiding this comment

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

👍 to rustfmt-ing everything. Makes it much easier for new contributers.

let s : Vec<String> = self.columns.iter()
impl fmt::Display for Schema {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s: Vec<String> = self.columns
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor, but you could consider using write!, like you added, e.g.

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  for (i, col) in self.columns.iter().enumerate() {
    write!(f, "{}", col)?;
    if i < self.columns.len() - 1 {
      write!(f, ", ")?;
    }
  }
  Ok(())
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK great, thanks for the pointer, I'll make that change.

Why do we need the ? at the end of the lines there?

Copy link
Contributor

@sadikovi sadikovi Apr 2, 2018

Choose a reason for hiding this comment

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

? is a special shortcut token that is basically unrolled into something like this:

match write!(f, "...") {
  Ok(...) => // do something,
  Err(...) => // return err immediately,
}

You would see it very often in the code, it is quite handy for unwrap Result with very minimum amount of code.

.map(|c| c.to_string())
.collect();
s.join(",")
write!(f, "{}", s.join(","))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you like to keep a whitespace after comma? IMHO, it makes it easier to read the schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but is there a standard? Ideally we'd test against that

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! I actually do not know, and asked similar question down in the comments thread.

Field::new("street", DataType::Utf8, false),
Field::new("zip", DataType::UInt16, false),
]), false),
Field::new("street", DataType::Utf8, false),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the shift might have been accidental here:)

// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::fmt;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think, based on other source files, we keep a new line after the license header.

@sadikovi
Copy link
Contributor

sadikovi commented Apr 2, 2018

@wesm @andygrove Is there a standard way of printing schema like in Parquet (with message type)?

@pitrou
Copy link
Member

pitrou commented Apr 2, 2018

Side note: if you choose to use an automatic formatter on Rust code, you should probably add a lint step to the CI setup.

@pitrou
Copy link
Member

pitrou commented Apr 2, 2018

Is there a standard way of printing schema like in Parquet (with message type)?

I don't think a "standard" is mandated, but see arrow::PrettyPrint and also pretty_print-test.cc in the C++ codebase. You may want to reproduce something similar.

For the specific question in the comments, adding a space after commas is good typographical practice.

@andygrove
Copy link
Member

andygrove commented Apr 2, 2018 via email

@max-sixty
Copy link
Contributor Author

@andygrove should I rustfmt for this PR or a separate one? There's not that much here - was mainly a way of getting my feet wet. But fine to split up if you prefer

@wesm
Copy link
Member

wesm commented Apr 2, 2018

@pitrou I mean more helping with PR workflow. This PR has an unclear title and does not reference any JIRA. At some point, someone will need to merge the patch and make sure the JIRA metadata is correct (fix version, assignee, component)

@xhochy
Copy link
Member

xhochy commented Apr 3, 2018

@wesm Yes, I can. Probably not going to have time to learn Rust but taking care of titles, consensus in PR comments & co is manageable.

xhochy pushed a commit that referenced this pull request Apr 3, 2018
As discussed in #1818

Probably worth merging fairly soon to minimize conflicts. I'll iterate quickly on any feedback.

Author: Maximilian Roos <m@maxroos.com>

Closes #1825 from maxim-lian/rustfmt and squashes the following commits:

bfeeb54 <Maximilian Roos> rustfmt-preview
fe7c228 <Maximilian Roos> move cargo fmt to rust script
e224515 <Maximilian Roos> hanging space
2c6375b <Maximilian Roos> travis lint
8a6f223 <Maximilian Roos> cargo fmt
@xhochy
Copy link
Member

xhochy commented Apr 3, 2018

Needs to be rebased on master after the rustfmt and other patches were merged.

.iter()
.map(|c| c.to_string())
.collect::<Vec<String>>()
.join(", "))
Copy link
Contributor Author

@max-sixty max-sixty Apr 3, 2018

Choose a reason for hiding this comment

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

@sadikovi what do you think of this? I will revert to your suggestion if you prefer. This feels nicer from a functional POV (but I'm only starting rust)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, I suggest you keep your version.

@max-sixty max-sixty changed the title Rust test ARROW-TBD: [Rust] Additional test & Trait standardization Apr 3, 2018
}
}

impl<T> Drop for Buffer<T> {
Copy link
Contributor Author

@max-sixty max-sixty Apr 3, 2018

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@maxim-lian Would you be able to fix this in a PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - this the fix!

@max-sixty max-sixty changed the title ARROW-TBD: [Rust] Additional test & Trait standardization ARROW-2384: [Rust] Additional test & Trait standardization Apr 3, 2018
@max-sixty
Copy link
Contributor Author

Gentle ping @sadikovi

Copy link
Contributor

@sadikovi sadikovi left a comment

Choose a reason for hiding this comment

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

Looks good. Great to see formatted code! Thanks for making all the changes!

.iter()
.map(|c| c.to_string())
.collect::<Vec<String>>()
.join(", "))
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, I suggest you keep your version.

@max-sixty
Copy link
Contributor Author

Thanks @sadikovi !

@xhochy - lmk if anything else is needed before merging

@xhochy
Copy link
Member

xhochy commented Apr 4, 2018

@maxim-lian I think there are some rebase artifacts in here due to merges to master. Can you rebase again?

@max-sixty
Copy link
Contributor Author

@xhochy updated!

@xhochy xhochy closed this in 486d592 Apr 5, 2018
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.

7 participants