[ 
https://issues.apache.org/jira/browse/ARROW-2472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16445476#comment-16445476
 ] 

ASF GitHub Bot commented on ARROW-2472:
---------------------------------------

pitrou closed pull request #1912: ARROW-2472: [Rust] Remove public attributes 
from Schema and Field and add accessors
URL: https://github.com/apache/arrow/pull/1912
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 58f5e8e47..d486ab30c 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);
+    }
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [Rust] The Schema and Fields types should not have public attributes
> --------------------------------------------------------------------
>
>                 Key: ARROW-2472
>                 URL: https://issues.apache.org/jira/browse/ARROW-2472
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Rust
>            Reporter: Andy Grove
>            Assignee: Andy Grove
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to