Skip to content

Commit

Permalink
luau: fix check for excess mapped columns earlier
Browse files Browse the repository at this point in the history
otherwise, we'll get a CSV different field count error
  • Loading branch information
jqnatividad committed Jan 1, 2024
1 parent 3f31d3d commit db15811
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/cmd/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ fn sequential_mode(
.ok_or("Specify new column names")?;

let new_columns_vec: Vec<&str> = new_columns.split(',').collect();
debug!("new_columns_vec: {new_columns_vec:?}");
for new_column in new_columns_vec {
new_column_count += 1;
let new_column = new_column.trim();
Expand Down Expand Up @@ -1311,6 +1312,11 @@ fn map_computedvalue(
let mut ibuffer = itoa::Buffer::new();
let mut nbuffer = ryu::Buffer::new();
table.for_each::<String, Value>(|_k, v| {
if new_column_count > 0 && columns_inserted >= new_column_count {
// we ignore table values more than the number of
// new columns defined, so we return early
return Ok(());
}
match v {
Value::Integer(intval) => record.push_field(ibuffer.format(intval)),
Value::String(strval) => record.push_field(&strval.to_string_lossy()),
Expand All @@ -1326,11 +1332,6 @@ fn map_computedvalue(
},
}
columns_inserted += 1;
if new_column_count > 0 && columns_inserted >= new_column_count {
// we ignore table values more than the number of
// new columns defined, so we return early
return Ok(());
}
Ok(())
})?;

Expand Down

0 comments on commit db15811

Please sign in to comment.