Apache DataFusion SQL Query Engine
ARROW-2384: [Rust] Additional test & Trait standardization
Maximilian Roosf96ecfe7f8e1
diff --git a/rust/src/array.rs b/rust/src/array.rsindex 7fd343346a..1c0a653d7a 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.rsindex 7d5cc7c49e..517583e909 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 bufferdiff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rsindex 4f022ba45d..8589a84314 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 }])")+ }}