Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Display for ListScalar #1850

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading