Dataframe with real index (#5892)

* remove extra print

* dataframe with real index

* corrected dataframe tests

* clippy error

* clippy error
This commit is contained in:
Fernando Herrera
2022-06-26 17:32:18 -05:00
committed by GitHub
parent d3e84daa49
commit c0901ef707
4 changed files with 43 additions and 7 deletions

View File

@ -17,6 +17,7 @@ use terminal_size::{Height, Width};
const STREAM_PAGE_SIZE: usize = 1000;
const STREAM_TIMEOUT_CHECK_INTERVAL: usize = 100;
const INDEX_COLUMN_NAME: &str = "index";
fn get_width_param(width_param: Option<i64>) -> usize {
if let Some(col) = width_param {
@ -41,6 +42,10 @@ impl Command for Table {
"Render the table."
}
fn extra_usage(&self) -> &str {
"If the table contains a column called 'index', this column is used as the table index instead of the usual continuous index"
}
fn search_terms(&self) -> Vec<&str> {
vec!["display", "render"]
}
@ -374,9 +379,23 @@ fn convert_to_table(
// String1 = datatype, String2 = value as string
let mut row: Vec<(String, String)> = vec![];
if !disable_index {
row = vec![("string".to_string(), (row_num + row_offset).to_string())];
let row_val = match &item {
Value::Record { .. } => item
.get_data_by_key(INDEX_COLUMN_NAME)
.map(|value| value.into_string("", config)),
_ => None,
}
.unwrap_or_else(|| (row_num + row_offset).to_string());
row = vec![("string".to_string(), (row_val).to_string())];
}
// The header with the INDEX is removed from the table headers since
// it is added to the natural table index
headers = headers
.into_iter()
.filter(|header| header != INDEX_COLUMN_NAME)
.collect();
if headers.is_empty() {
row.push((
item.get_type().to_string(),