Skip to content

Commit

Permalink
fix: clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Dec 20, 2021
1 parent 824f8ff commit 8ade651
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions arrow/src/datatypes/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ impl Schema {
/// Returns a new schema with only the specified columns in the new schema
/// This carries metadata from the parent schema over as well
pub fn project(&self, indices: &[usize]) -> Result<Schema> {
let new_fields = indices.into_iter()
let new_fields = indices
.iter()
.map(|i| {
self.fields.get(*i).cloned().ok_or_else(|| {
ArrowError::SchemaError(format!(
Expand Down Expand Up @@ -132,7 +133,7 @@ impl Schema {
/// ]),
/// );
/// ```
pub fn try_merge(schemas: impl IntoIterator<Item=Self>) -> Result<Self> {
pub fn try_merge(schemas: impl IntoIterator<Item = Self>) -> Result<Self> {
schemas
.into_iter()
.try_fold(Self::empty(), |mut merged, schema| {
Expand Down Expand Up @@ -423,11 +424,14 @@ mod tests {
metadata,
);

let projected: Result<Schema> = schema.project(&vec![0, 3]);
let projected: Result<Schema> = schema.project(&[0, 3]);

assert!(projected.is_err());
if let Err(e) = projected {
assert_eq!(e.to_string(), "Schema error: project index 3 out of bounds, max field 3".to_string())
assert_eq!(
e.to_string(),
"Schema error: project index 3 out of bounds, max field 3".to_string()
)
}
}
}
18 changes: 9 additions & 9 deletions arrow/src/record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl RecordBatch {
pub fn project(&self, indices: &[usize]) -> Result<RecordBatch> {
let projected_schema = self.schema.project(indices)?;
let batch_fields = indices
.into_iter()
.iter()
.map(|f| {
self.columns.get(*f).cloned().ok_or_else(|| {
ArrowError::SchemaError(format!(
Expand Down Expand Up @@ -922,20 +922,20 @@ mod tests {

#[test]
fn project() {
let a: ArrayRef = Arc::new(Int32Array::from(vec![
Some(1),
None,
Some(3),
]));
let a: ArrayRef = Arc::new(Int32Array::from(vec![Some(1), None, Some(3)]));
let b: ArrayRef = Arc::new(StringArray::from(vec!["a", "b", "c"]));
let c: ArrayRef = Arc::new(StringArray::from(vec!["d", "e", "f"]));

let record_batch = RecordBatch::try_from_iter(vec![("a", a.clone()), ("b", b.clone()), ("c", c.clone())])
.expect("valid conversion");
let record_batch = RecordBatch::try_from_iter(vec![
("a", a.clone()),
("b", b.clone()),
("c", c.clone()),
])
.expect("valid conversion");

let expected = RecordBatch::try_from_iter(vec![("a", a), ("c", c)])
.expect("valid conversion");

assert_eq!(expected, record_batch.project(&vec![0, 2]).unwrap());
assert_eq!(expected, record_batch.project(&[0, 2]).unwrap());
}
}

0 comments on commit 8ade651

Please sign in to comment.