You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/04/05 07:16:13 UTC
[arrow] branch master updated: ARROW-2384: [Rust] Additional test &
Trait standardization
This is an automated email from the ASF dual-hosted git repository.
uwe 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 486d592 ARROW-2384: [Rust] Additional test & Trait standardization
486d592 is described below
commit 486d592f243363953aa916933b73dad391b76f25
Author: Maximilian Roos <m...@maxroos.com>
AuthorDate: Thu Apr 5 09:16:03 2018 +0200
ARROW-2384: [Rust] Additional test & Trait standardization
A test for the string representation of a Schema.
& some standardization on `Trait`s rather than their method
...but mainly getting my feet wet with rust & arrow
Author: Maximilian Roos <m...@maxroos.com>
Closes #1818 from maxim-lian/rust-tweak and squashes the following commits:
6b3fd47 <Maximilian Roos> no need for display for datatype yet
6c33977 <Maximilian Roos> merge
8879b65 <Maximilian Roos> cargofmt
c29b667 <Maximilian Roos> Merge branch 'master' into rust-tweak
730050b <Maximilian Roos> fmt
5449cc0 <Maximilian Roos> merge
1a6d6d4 <Maximilian Roos> changes from @sadikovi
58273d8 <Maximilian Roos> Merge branch 'rustfmt' into rust-tweak
260ba24 <Maximilian Roos> cargo fmt
bfeeb54 <Maximilian Roos> rustfmt-preview
fe7c228 <Maximilian Roos> move cargo fmt to rust script
e224515 <Maximilian Roos> hanging space
2c6375b <Maximilian Roos> travis lint
8a6f223 <Maximilian Roos> cargo fmt
2e3b4c0 <Maximilian Roos> display for Field
945caa7 <Maximilian Roos> test and impl
---
rust/src/array.rs | 6 +++---
rust/src/buffer.rs | 2 +-
rust/src/datatypes.rs | 35 ++++++++++++++++++++++++++++++++---
3 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/rust/src/array.rs b/rust/src/array.rs
index 7fd3433..1c0a653 100644
--- a/rust/src/array.rs
+++ b/rust/src/array.rs
@@ -42,7 +42,7 @@ pub enum ArrayData {
}
macro_rules! arraydata_from_primitive {
- ($DT:ty, $AT:ident) => {
+ ($DT: ty, $AT: ident) => {
impl From<Vec<$DT>> for ArrayData {
fn from(v: Vec<$DT>) -> Self {
ArrayData::$AT(Buffer::from(v))
@@ -91,7 +91,7 @@ impl Array {
}
macro_rules! array_from_primitive {
- ($DT:ty) => {
+ ($DT: ty) => {
impl From<Vec<$DT>> for Array {
fn from(v: Vec<$DT>) -> Self {
Array {
@@ -117,7 +117,7 @@ array_from_primitive!(i32);
array_from_primitive!(i64);
macro_rules! array_from_optional_primitive {
- ($DT:ty, $DEFAULT:expr) => {
+ ($DT: ty, $DEFAULT: expr) => {
impl From<Vec<Option<$DT>>> for Array {
fn from(v: Vec<Option<$DT>>) -> Self {
let mut null_count = 0;
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index 7d5cc7c..517583e 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -92,7 +92,7 @@ where
}
macro_rules! array_from_primitive {
- ($DT:ty) => {
+ ($DT: ty) => {
impl From<Vec<$DT>> for Buffer<$DT> {
fn from(v: Vec<$DT>) -> Self {
// allocate aligned memory buffer
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index 4f022ba..8589a84 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+use std::fmt;
use serde_json;
use serde_json::Value;
@@ -201,6 +202,12 @@ impl Field {
}
}
+impl fmt::Display for Field {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}: {:?}", self.name, self.data_type)
+ }
+}
+
#[derive(Debug, Clone)]
pub struct Schema {
pub columns: Vec<Field>,
@@ -223,10 +230,15 @@ impl Schema {
.enumerate()
.find(|&(_, c)| c.name == name)
}
+}
- pub fn to_string(&self) -> String {
- let s: Vec<String> = self.columns.iter().map(|c| c.to_string()).collect();
- s.join(",")
+impl fmt::Display for Schema {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(&self.columns
+ .iter()
+ .map(|c| c.to_string())
+ .collect::<Vec<String>>()
+ .join(", "))
}
}
@@ -311,4 +323,21 @@ mod tests {
let dt = DataType::from(&value).unwrap();
assert_eq!(DataType::Int32, dt);
}
+
+ #[test]
+ fn create_schema_string() {
+ 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,
+ ),
+ ]);
+ 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 }])")
+ }
}
--
To stop receiving notification emails like this one, please contact
uwe@apache.org.