Skip to content

Commit 1c79cc4

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

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • vortex-array/src/display

vortex-array/src/display/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum DisplayOptions {
2929
/// );
3030
/// ```
3131
MetadataOnly,
32-
/// Only the logical values of the array: `[0i16, 1i16, 2i16, 3i16, 4i16]`.
32+
/// Only the first 16 logical values of the array: `[0i16, 1i16, 2i16, 3i16, 4i16]`.
3333
///
3434
/// ```
3535
/// # use vortex_array::display::DisplayOptions;
@@ -332,7 +332,7 @@ impl Display for dyn DynArray + '_ {
332332

333333
const DISPLAY_LIMIT: usize = 16;
334334
impl dyn DynArray + '_ {
335-
/// Display logical values of the array
335+
/// Display the first 16 logical values of the array
336336
///
337337
/// For example, an `i16` typed array containing the first five non-negative integers is displayed
338338
/// as: `[0i16, 1i16, 2i16, 3i16, 4i16]`.
@@ -490,7 +490,8 @@ 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 end = if self.len() > limit { ", ...]" } else { "]" };
494+
write!(f, "{}{end}", if f.alternate() { "\n" } else { "" })
494495
}
495496
DisplayOptions::TreeDisplay {
496497
buffers,
@@ -583,6 +584,7 @@ mod test {
583584
use crate::arrays::BoolArray;
584585
use crate::arrays::ListArray;
585586
use crate::arrays::StructArray;
587+
use crate::display::DISPLAY_LIMIT;
586588
use crate::dtype::FieldNames;
587589
use crate::validity::Validity;
588590

@@ -596,6 +598,15 @@ mod test {
596598

597599
let x = buffer![1, 2, 3, 4].into_array();
598600
assert_eq!(x.display_values().to_string(), "[1i32, 2i32, 3i32, 4i32]");
601+
602+
let x = crate::arrays::PrimitiveArray::from_iter(
603+
0i32..i32::try_from(DISPLAY_LIMIT).unwrap() + 1,
604+
)
605+
.into_array();
606+
assert_eq!(
607+
x.display_values().to_string(),
608+
"[0i32, 1i32, 2i32, 3i32, 4i32, 5i32, 6i32, 7i32, 8i32, 9i32, 10i32, 11i32, 12i32, 13i32, 14i32, 15i32, ...]"
609+
);
599610
}
600611

601612
#[test]

0 commit comments

Comments
 (0)