You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2018/04/20 08:15:43 UTC

[arrow] branch master updated: ARROW-2472: [Rust] Remove public attributes from Schema and Field and add accessors

This is an automated email from the ASF dual-hosted git repository.

apitrou 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 09be7b4  ARROW-2472: [Rust] Remove public attributes from Schema and Field and add accessors
09be7b4 is described below

commit 09be7b4ae16a9267831c53632c8a02d74469dbd9
Author: Andy Grove <an...@gmail.com>
AuthorDate: Fri Apr 20 10:15:20 2018 +0200

    ARROW-2472: [Rust] Remove public attributes from Schema and Field and add accessors
    
    Author: Andy Grove <an...@gmail.com>
    
    Closes #1912 from andygrove/field_accessors and squashes the following commits:
    
    280063a <Andy Grove> add unit test
    1a8c786 <Andy Grove> Remove public attributes from Schema and Field and add accessors
    bd4fbb5 <Andy Grove> Merge remote-tracking branch 'upstream/master'
    9c8a10a <Andy Grove> Merge remote-tracking branch 'upstream/master'
    05592f8 <Andy Grove> Merge remote-tracking branch 'upstream/master'
    8c0e698 <Andy Grove> Merge remote-tracking branch 'upstream/master'
    31ef90b <Andy Grove> Merge remote-tracking branch 'upstream/master'
    2f87c70 <Andy Grove> Fix build - add missing import
---
 rust/src/datatypes.rs | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 58f5e8e..d486ab3 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -150,6 +150,18 @@ impl Field {
         }
     }
 
+    pub fn name(&self) -> &String {
+        &self.name
+    }
+
+    pub fn data_type(&self) -> &DataType {
+        &self.data_type
+    }
+
+    pub fn is_nullable(&self) -> bool {
+        self.nullable
+    }
+
     /// Parse a field definition from a JSON representation
     pub fn from(json: &Value) -> Result<Self, ArrowError> {
         //println!("Field::from({:?}", json);
@@ -214,7 +226,7 @@ impl fmt::Display for Field {
 /// Arrow Schema
 #[derive(Debug, Clone)]
 pub struct Schema {
-    pub columns: Vec<Field>,
+    columns: Vec<Field>,
 }
 
 impl Schema {
@@ -227,6 +239,10 @@ impl Schema {
         Schema { columns: columns }
     }
 
+    pub fn columns(&self) -> &Vec<Field> {
+        &self.columns
+    }
+
     /// look up a column by name and return a reference to the column along with it's index
     pub fn column(&self, name: &str) -> Option<(usize, &Field)> {
         self.columns
@@ -345,4 +361,29 @@ mod tests {
         ]);
         assert_eq!(_person.to_string(), "first_name: Utf8, last_name: Utf8, address: Struct([Field { name: \"street\", data_type: Utf8, nullable: false }, Field { name: \"zip\", data_type: UInt16, nullable: false }])")
     }
+
+    #[test]
+    fn schema_field_accessors() {
+        let _person = Schema::new(vec![
+            Field::new("first_name", DataType::Utf8, false),
+            Field::new("last_name", DataType::Utf8, false),
+            Field::new(
+                "address",
+                DataType::Struct(vec![
+                    Field::new("street", DataType::Utf8, false),
+                    Field::new("zip", DataType::UInt16, false),
+                ]),
+                false,
+            ),
+        ]);
+
+        // test schema accessors
+        assert_eq!(_person.columns().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);
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
apitrou@apache.org.