From fc41a0f96bf7bff2178507da511fd303b1d88a0c Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Mon, 16 May 2022 19:29:40 +0800 Subject: [PATCH] use reverse iter on value search (#5553) --- crates/nu-command/tests/commands/merge.rs | 2 -- crates/nu-protocol/src/value/mod.rs | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/tests/commands/merge.rs b/crates/nu-command/tests/commands/merge.rs index 384a1d1c8d..92ec3fe5da 100644 --- a/crates/nu-command/tests/commands/merge.rs +++ b/crates/nu-command/tests/commands/merge.rs @@ -2,8 +2,6 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; -// FIXME: jt: needs more work -#[ignore] #[test] fn row() { Playground::setup("merge_test_1", |dirs, sandbox| { diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index b0aa0baea6..f36815d149 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -660,8 +660,12 @@ impl Value { let cols = cols.clone(); let span = *span; - if let Some(found) = - cols.iter().zip(vals.iter()).find(|x| x.0 == column_name) + // Make reverse iterate to avoid duplicate column leads to first value, actuall last value is expected. + if let Some(found) = cols + .iter() + .zip(vals.iter()) + .rev() + .find(|x| x.0 == column_name) { current = found.1.clone(); } else if let Some(suggestion) = did_you_mean(&cols, column_name) {