Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added Debug to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jun 3, 2022
1 parent 7decd19 commit d607c33
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/array/equal/mod.rs
Expand Up @@ -165,6 +165,18 @@ impl PartialEq<&dyn Array> for UnionArray {
}
}

impl PartialEq<MapArray> for MapArray {
fn eq(&self, other: &Self) -> bool {
map::equal(self, other)
}
}

impl PartialEq<&dyn Array> for MapArray {
fn eq(&self, other: &&dyn Array) -> bool {
equal(self, *other)
}
}

/// Logically compares two [`Array`]s.
/// Two arrays are logically equal if and only if:
/// * their data types are equal
Expand Down
24 changes: 24 additions & 0 deletions src/array/map/fmt.rs
@@ -0,0 +1,24 @@
use std::fmt::{Debug, Formatter, Result, Write};

use super::super::fmt::{get_display, write_vec};
use super::MapArray;

pub fn write_value<W: Write>(
array: &MapArray,
index: usize,
null: &'static str,
f: &mut W,
) -> Result {
let values = array.value(index);
let writer = |f: &mut W, index| get_display(values.as_ref(), null)(f, index);
write_vec(f, writer, None, values.len(), null, false)
}

impl Debug for MapArray {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let writer = |f: &mut Formatter, index| write_value(self, index, "None", f);

write!(f, "MapArray")?;
write_vec(f, writer, self.validity.as_ref(), self.len(), "None", false)
}
}
3 changes: 2 additions & 1 deletion src/array/map/mod.rs
Expand Up @@ -10,11 +10,12 @@ use crate::{
use super::{new_empty_array, specification::try_check_offsets, Array};

mod ffi;
mod fmt;
mod iterator;
pub use iterator::*;

/// An array representing a (key, value), both of arbitrary logical types.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct MapArray {
data_type: DataType,
// invariant: field.len() == offsets.len() - 1
Expand Down
2 changes: 1 addition & 1 deletion src/array/mod.rs
Expand Up @@ -240,7 +240,7 @@ impl std::fmt::Debug for dyn Array + '_ {
fmt_dyn!(self, DictionaryArray::<$T>, f)
})
}
Map => todo!(),
Map => fmt_dyn!(self, MapArray, f),
}
}
}
Expand Down

0 comments on commit d607c33

Please sign in to comment.