Skip to content

Commit 0822652

Browse files
committed
Fix column order of returned tuples in iter_scan
1 parent fc5235c commit 0822652

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(crate) struct EtcdFdw {
1717
client: Client,
1818
rt: Runtime,
1919
fetch_results: Vec<KeyValue>,
20+
tgt_cols: Vec<Column>,
2021
fetch_key: bool,
2122
fetch_value: bool,
2223
}
@@ -231,6 +232,7 @@ impl ForeignDataWrapper<EtcdFdwError> for EtcdFdw {
231232
client,
232233
rt,
233234
fetch_results,
235+
tgt_cols: Vec::new(),
234236
fetch_key: false,
235237
fetch_value: false,
236238
})
@@ -434,6 +436,7 @@ impl ForeignDataWrapper<EtcdFdwError> for EtcdFdw {
434436
};
435437
let result_vec = result_unwrapped.take_kvs();
436438
self.fetch_results = result_vec;
439+
self.tgt_cols = columns.to_vec();
437440
Ok(())
438441
}
439442

@@ -448,11 +451,13 @@ impl ForeignDataWrapper<EtcdFdwError> for EtcdFdw {
448451
let value = x
449452
.value_str()
450453
.expect("Expected a value, but the value was empty");
451-
if self.fetch_key {
452-
row.push("key", Some(Cell::String(key.to_string())));
453-
}
454-
if self.fetch_value {
455-
row.push("value", Some(Cell::String(value.to_string())));
454+
for tgt_col in &self.tgt_cols {
455+
if tgt_col.name == "key" {
456+
row.push(&tgt_col.name, Some(Cell::String(key.to_string())));
457+
}
458+
if tgt_col.name == "value" {
459+
row.push(&tgt_col.name, Some(Cell::String(value.to_string())));
460+
}
456461
}
457462
}))
458463
}

0 commit comments

Comments
 (0)