You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2018/09/10 08:13:57 UTC
[arrow] branch master updated: ARROW-2617: [Rust] Schema should
contain fields not columns
This is an automated email from the ASF dual-hosted git repository.
kszucs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new a42d4bf ARROW-2617: [Rust] Schema should contain fields not columns
a42d4bf is described below
commit a42d4bf1b0cef37849be0b019c34c96bf56a62f9
Author: Krisztián Szűcs <sz...@gmail.com>
AuthorDate: Mon Sep 10 10:13:44 2018 +0200
ARROW-2617: [Rust] Schema should contain fields not columns
Author: Krisztián Szűcs <sz...@gmail.com>
Closes #2531 from kszucs/ARROW-2617 and squashes the following commits:
a692be3a <Krisztián Szűcs> cargo fmt
0baf3574 <Krisztián Szűcs> replace columns to fields in Schema
---
rust/src/datatypes.rs | 30 +++++++++++++++---------------
rust/src/record_batch.rs | 7 ++-----
2 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 4ffb8e4..ec9b852 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -302,13 +302,13 @@ impl fmt::Display for Field {
/// layout.
#[derive(Debug, Clone)]
pub struct Schema {
- columns: Vec<Field>,
+ fields: Vec<Field>,
}
impl Schema {
/// Creates an empty `Schema`
pub fn empty() -> Self {
- Self { columns: vec![] }
+ Self { fields: vec![] }
}
/// Creates a new `Schema` from a sequence of `Field` values
@@ -323,25 +323,25 @@ impl Schema {
///
/// let schema = Schema::new(vec![field_a, field_b]);
/// ```
- pub fn new(columns: Vec<Field>) -> Self {
- Self { columns }
+ pub fn new(fields: Vec<Field>) -> Self {
+ Self { fields }
}
/// Returns an immutable reference of the vector of `Field` instances
- pub fn columns(&self) -> &Vec<Field> {
- &self.columns
+ pub fn fields(&self) -> &Vec<Field> {
+ &self.fields
}
/// Returns an immutable reference of a specific `Field` instance selected using an offset
- /// within the internal `columns` vector
- pub fn column(&self, i: usize) -> &Field {
- &self.columns[i]
+ /// within the internal `fields` vector
+ pub fn field(&self, i: usize) -> &Field {
+ &self.fields[i]
}
/// Look up a column by name and return a immutable reference to the column along with
/// it's index
pub fn column_with_name(&self, name: &str) -> Option<(usize, &Field)> {
- self.columns
+ self.fields
.iter()
.enumerate()
.find(|&(_, c)| c.name == name)
@@ -352,7 +352,7 @@ impl fmt::Display for Schema {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(
&self
- .columns
+ .fields
.iter()
.map(|c| c.to_string())
.collect::<Vec<String>>()
@@ -477,12 +477,12 @@ mod tests {
]);
// test schema accessors
- assert_eq!(_person.columns().len(), 3);
+ assert_eq!(_person.fields().len(), 3);
// test field accessors
- assert_eq!(_person.columns()[0].name(), "first_name");
- assert_eq!(_person.columns()[0].data_type(), &DataType::Utf8);
- assert_eq!(_person.columns()[0].is_nullable(), false);
+ assert_eq!(_person.fields()[0].name(), "first_name");
+ assert_eq!(_person.fields()[0].data_type(), &DataType::Utf8);
+ assert_eq!(_person.fields()[0].is_nullable(), false);
}
}
diff --git a/rust/src/record_batch.rs b/rust/src/record_batch.rs
index 48856b6..6819b63 100644
--- a/rust/src/record_batch.rs
+++ b/rust/src/record_batch.rs
@@ -97,11 +97,8 @@ mod tests {
assert_eq!(5, record_batch.num_rows());
assert_eq!(2, record_batch.num_columns());
- assert_eq!(
- &DataType::Int32,
- record_batch.schema().column(0).data_type()
- );
- assert_eq!(&DataType::Utf8, record_batch.schema().column(1).data_type());
+ assert_eq!(&DataType::Int32, record_batch.schema().field(0).data_type());
+ assert_eq!(&DataType::Utf8, record_batch.schema().field(1).data_type());
assert_eq!(5, record_batch.column(0).data().len());
assert_eq!(5, record_batch.column(1).data().len());
}