Skip to content

Commit

Permalink
Implement Display for ListScalar (#1850)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Jan 8, 2025
1 parent 4cc3aac commit e2e2c57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions vortex-scalar/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::binary::BinaryScalar;
use crate::extension::ExtScalar;
use crate::struct_::StructScalar;
use crate::utf8::Utf8Scalar;
use crate::Scalar;
use crate::{ListScalar, Scalar};

impl Display for Scalar {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -59,7 +59,15 @@ impl Display for Scalar {
write!(f, "}}")
}
}
DType::List(..) => todo!(),
DType::List(..) => {
let v = ListScalar::try_from(self).map_err(|_| std::fmt::Error)?;

if v.is_null() {
write!(f, "null")
} else {
write!(f, "[{}]", v.elements().format(","))
}
}
// Specialized handling for date/time/timestamp builtin extension types.
DType::Extension(dtype) if is_temporal_ext_type(dtype.id()) => {
let metadata =
Expand Down
5 changes: 4 additions & 1 deletion vortex-scalar/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::{Display, Write};
use std::sync::Arc;

use itertools::Itertools;
use vortex_buffer::{BufferString, ByteBuffer};
use vortex_dtype::DType;
use vortex_error::{vortex_err, VortexResult};
Expand Down Expand Up @@ -71,7 +72,9 @@ impl Display for InnerScalarValue {
write!(f, "{}", bufstr.as_str())
}
}
Self::List(_) => todo!(),
Self::List(elems) => {
write!(f, "[{}]", elems.iter().format(","))
}
Self::Null => write!(f, "null"),
}
}
Expand Down

0 comments on commit e2e2c57

Please sign in to comment.