Skip to content

Apache DataFusion SQL Query Engine

ARROW-2615: [Rust] Post refactor cleanup

Andy Grove558da85ffb0c
diff --git a/rust/examples/dynamic_types.rs b/rust/examples/dynamic_types.rs
index acfd515d31..86a189041d 100644
--- a/rust/examples/dynamic_types.rs
+++ b/rust/examples/dynamic_types.rs
@@ -43,7 +43,7 @@ fn main() {
let id = PrimitiveArray::from(vec![1, 2, 3, 4, 5]);
let nested = StructArray::from(vec![
- Rc::new(PrimitiveArray::from(vec!["a", "b", "c", "d", "e"])) as Rc<Array>,
+ Rc::new(ListArray::from(vec!["a", "b", "c", "d", "e"])) as Rc<Array>,
Rc::new(PrimitiveArray::from(vec![1.1, 2.2, 3.3, 4.4, 5.5])),
Rc::new(PrimitiveArray::from(vec![2.2, 3.3, 4.4, 5.5, 6.6])),
]);
diff --git a/rust/src/array.rs b/rust/src/array.rs
index 5305279015..34294a54b8 100644
--- a/rust/src/array.rs
+++ b/rust/src/array.rs
@@ -55,6 +55,18 @@ impl<T> ListArray<T>
where
T: ArrowPrimitiveType,
{
+ pub fn len(&self) -> usize {
+ self.len
+ }
+
+ pub fn null_count(&self) -> usize {
+ self.null_count
+ }
+
+ pub fn validity_bitmap(&self) -> &Option<Bitmap> {
+ &self.validity_bitmap
+ }
+
pub fn get(&self, i: usize) -> &[T] {
self.data.get(i)
}
@@ -145,6 +157,10 @@ where
self.len
}
+ pub fn get(&self, i: usize) -> &T {
+ self.data.get(i)
+ }
+
pub fn iter(&self) -> BufferIterator<T> {
self.data.iter()
}
diff --git a/rust/src/datatypes.rs b/rust/src/datatypes.rs
index d1ac454920..83a157a931 100644
--- a/rust/src/datatypes.rs
+++ b/rust/src/datatypes.rs
@@ -20,7 +20,7 @@ use serde_json::Value;
use std::fmt;
/// Arrow data type
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DataType {
Boolean,
Int8,
@@ -40,7 +40,7 @@ pub enum DataType {
}
/// Arrow struct/schema field
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
name: String,
data_type: DataType,
@@ -61,7 +61,6 @@ impl ArrowPrimitiveType for i32 {}
impl ArrowPrimitiveType for i64 {}
impl ArrowPrimitiveType for f32 {}
impl ArrowPrimitiveType for f64 {}
-impl ArrowPrimitiveType for &'static str {}
impl DataType {
/// Parse a data type from a JSON representation
diff --git a/rust/src/record_batch.rs b/rust/src/record_batch.rs
index d8ca2f162b..69509e437e 100644
--- a/rust/src/record_batch.rs
+++ b/rust/src/record_batch.rs
@@ -66,7 +66,7 @@ mod tests {
]);
let a = PrimitiveArray::from(vec![1, 2, 3, 4, 5]);
- let b = PrimitiveArray::from(vec!["a", "b", "c", "d", "e"]);
+ let b = ListArray::from(vec!["a", "b", "c", "d", "e"]);
let record_batch = RecordBatch::new(Rc::new(schema), vec![Rc::new(a), Rc::new(b)]);