Skip to content

Commit 0e2ed56

Browse files
Show truncation indicator when display values exceed limit
Signed-off-by: Dimitar Dimitrov <dimitar@spiraldb.com>
1 parent 12fe78e commit 0e2ed56

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • vortex-array/src/display

vortex-array/src/display/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,13 @@ impl dyn DynArray + '_ {
490490
.map_or_else(|e| format!("<error: {e}>"), |s| s.to_string()))
491491
.format(sep)
492492
)?;
493-
write!(f, "{}", if f.alternate() { "\n]" } else { "]" })
493+
let ellipsis = if self.len() > limit {
494+
format!("{sep}...")
495+
} else {
496+
"".to_string()
497+
};
498+
let closing_brace = if f.alternate() { "\n]" } else { "]" };
499+
write!(f, "{ellipsis}{closing_brace}",)
494500
}
495501
DisplayOptions::TreeDisplay {
496502
buffers,
@@ -583,6 +589,7 @@ mod test {
583589
use crate::arrays::BoolArray;
584590
use crate::arrays::ListArray;
585591
use crate::arrays::StructArray;
592+
use crate::display::DISPLAY_LIMIT;
586593
use crate::dtype::FieldNames;
587594
use crate::validity::Validity;
588595

@@ -596,6 +603,15 @@ mod test {
596603

597604
let x = buffer![1, 2, 3, 4].into_array();
598605
assert_eq!(x.display_values().to_string(), "[1i32, 2i32, 3i32, 4i32]");
606+
607+
let x = crate::arrays::PrimitiveArray::from_iter(
608+
0i32..i32::try_from(DISPLAY_LIMIT).unwrap() + 1,
609+
)
610+
.into_array();
611+
assert_eq!(
612+
x.display_values().to_string(),
613+
"[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, 13i32, 14i32, 15i32, ...]"
614+
);
599615
}
600616

601617
#[test]

0 commit comments

Comments
 (0)