Skip to content

Apache DataFusion SQL Query Engine

ARROW-2617: [Rust] Schema should contain fields not columns

Krisztián Szűcs29c025b2e9dd
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 4ffb8e416f..ec9b852b5b 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 48856b6e43..6819b639a7 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());
}