forked from extern/nushell
Construct Record
s only through checked helpers (#11386)
# Description Constructing the internals of `Record` without checking the lengths is bad. (also incompatible with changes to how we store records) - Use `Record::from_raw_cols_vals` in dataframe code - Use `record!` macro in dataframe test - Use `record!` in `nu-color-config` tests - Stop direct record construction in `nu-command` - Refactor table construction in `from nuon` # User-Facing Changes None # Tests + Formatting No new tests, updated tests in equal fashion
This commit is contained in:
committed by
GitHub
parent
6f384da57e
commit
8cfa96b4c0
@ -258,16 +258,16 @@ fn histogram_impl(
|
||||
result.push((
|
||||
count, // attach count first for easily sorting.
|
||||
Value::record(
|
||||
Record {
|
||||
cols: result_cols.clone(),
|
||||
vals: vec![
|
||||
Record::from_raw_cols_vals(
|
||||
result_cols.clone(),
|
||||
vec![
|
||||
val.into_value(),
|
||||
Value::int(count, span),
|
||||
Value::float(quantile, span),
|
||||
Value::string(percentage, span),
|
||||
Value::string(freq, span),
|
||||
],
|
||||
},
|
||||
),
|
||||
span,
|
||||
),
|
||||
));
|
||||
|
@ -499,13 +499,7 @@ pub fn convert_sqlite_row_to_nu_value(row: &Row, span: Span, column_names: Vec<S
|
||||
vals.push(val);
|
||||
}
|
||||
|
||||
Value::record(
|
||||
Record {
|
||||
cols: column_names,
|
||||
vals,
|
||||
},
|
||||
span,
|
||||
)
|
||||
Value::record(Record::from_raw_cols_vals(column_names, vals), span)
|
||||
}
|
||||
|
||||
pub fn convert_sqlite_value_to_nu_value(value: ValueRef, span: Span) -> Value {
|
||||
|
@ -55,10 +55,7 @@ fn from_delimited_string_to_value(
|
||||
.collect::<Vec<Value>>();
|
||||
|
||||
rows.push(Value::record(
|
||||
Record {
|
||||
cols: headers.clone(),
|
||||
vals: output_row,
|
||||
},
|
||||
Record::from_raw_cols_vals(headers.clone(), output_row),
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
@ -403,13 +403,7 @@ fn convert_to_value(
|
||||
}
|
||||
|
||||
for row in cells {
|
||||
let mut vals = vec![];
|
||||
|
||||
for cell in row {
|
||||
vals.push(convert_to_value(cell, span, original_text)?);
|
||||
}
|
||||
|
||||
if cols.len() != vals.len() {
|
||||
if cols.len() != row.len() {
|
||||
return Err(ShellError::OutsideSpannedLabeledError {
|
||||
src: original_text.to_string(),
|
||||
error: "Error when loading".into(),
|
||||
@ -417,12 +411,13 @@ fn convert_to_value(
|
||||
span: expr.span,
|
||||
});
|
||||
}
|
||||
let vals: Vec<Value> = row
|
||||
.into_iter()
|
||||
.map(|cell| convert_to_value(cell, span, original_text))
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
output.push(Value::record(
|
||||
Record {
|
||||
cols: cols.clone(),
|
||||
vals,
|
||||
},
|
||||
Record::from_raw_cols_vals(cols.clone(), vals),
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
@ -199,7 +199,10 @@ fn detect_columns(
|
||||
};
|
||||
|
||||
if !(l_idx <= r_idx && (r_idx >= 0 || l_idx < (cols.len() as isize))) {
|
||||
return Value::record(Record { cols, vals }, name_span);
|
||||
return Value::record(
|
||||
Record::from_raw_cols_vals(cols, vals),
|
||||
name_span,
|
||||
);
|
||||
}
|
||||
|
||||
(l_idx.max(0) as usize, (r_idx as usize + 1).min(cols.len()))
|
||||
@ -210,7 +213,7 @@ fn detect_columns(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Value::record(Record { cols, vals }, name_span);
|
||||
return Value::record(Record::from_raw_cols_vals(cols, vals), name_span);
|
||||
};
|
||||
|
||||
// Merge Columns
|
||||
@ -232,7 +235,7 @@ fn detect_columns(
|
||||
vals.push(binding);
|
||||
last_seg.into_iter().for_each(|v| vals.push(v));
|
||||
|
||||
Value::record(Record { cols, vals }, name_span)
|
||||
Value::record(Record::from_raw_cols_vals(cols, vals), name_span)
|
||||
})
|
||||
.into_pipeline_data(ctrlc))
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user