Skip to content

Commit

Permalink
chore: better list dtype formatting (#1840)
Browse files Browse the repository at this point in the history
closes #1769 
before:
```
> select current_schemas();
┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ current_schemas                                                                                    │
│ ──                                                                                                 │
│ List(Field { name: "item", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, m… │
╞════════════════════════════════════════════════════════════════════════════════════════════════════╡
│ [public]                                                                                           │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘
```

after:
```
> select current_schemas();
┌─────────────────┐
│ current_schemas │
│ ──              │
│ List[Utf8]      │
╞═════════════════╡
│ [public]        │
└─────────────────┘
```
  • Loading branch information
universalmind303 authored Oct 3, 2023
1 parent d810ced commit ea3b2df
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions crates/arrow_util/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ struct ColumnHeader {
alignment: CellAlignment,
}

fn fmt_dtype(dtype: &DataType) -> String {
match dtype {
DataType::Timestamp(tu, tz) => {
format!("Timestamp[{}, {}]", fmt_timeunit(tu), fmt_timezone(tz))
}
DataType::List(fld) | DataType::LargeList(fld) => {
format!("List[{}]", fmt_dtype(fld.data_type()))
}
DataType::Struct(flds) => flds
.iter()
.map(|f| format!("{}: {}", f.name(), fmt_dtype(f.data_type())))
.collect::<Vec<_>>()
.join(", "),
dtype => format!("{}", dtype),
}
}

impl ColumnHeader {
fn from_field(f: &Field) -> Self {
let alignment = if f.data_type().is_numeric() {
Expand All @@ -275,12 +292,7 @@ impl ColumnHeader {

ColumnHeader {
name: f.name().clone(),
data_type: match f.data_type() {
DataType::Timestamp(tu, tz) => {
format!("Timestamp[{}, {}]", fmt_timeunit(tu), fmt_timezone(tz))
}
dtype => format!("{}", dtype),
},
data_type: fmt_dtype(f.data_type()),
alignment,
}
}
Expand Down

0 comments on commit ea3b2df

Please sign in to comment.