Skip to content

Commit

Permalink
Merge pull request #490 from auyer/fix/array_panic_on_none
Browse files Browse the repository at this point in the history
Push empty vec on ArrowAssoc when Option is None to fix Postgres  _varchar can panic on Option.unwrap
  • Loading branch information
wangxiaoying authored Apr 18, 2023
2 parents c0b18d9 + 385e602 commit 79d6cb7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions connectorx/src/destinations/arrow2/arrow_assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,19 @@ impl ArrowAssoc for Option<Vec<String>> {
}

fn push(builder: &mut Self::Builder, value: Self) {
let value = value.unwrap();
let mut string_array: Vec<Option<String>> = vec![];
for sub_value in value {
string_array.push(Some(sub_value))
}
match value {
Some(value) => {
for sub_value in value {
string_array.push(Some(sub_value))
}

builder.try_push(Some(string_array));
builder.try_push(Some(string_array)).unwrap();
}
None => {
builder.try_push(Some(string_array)).unwrap();
}
};
}

fn field(header: &str) -> Field {
Expand All @@ -474,7 +480,7 @@ impl ArrowAssoc for Vec<String> {
for sub_value in value {
string_array.push(Some(sub_value))
}
builder.try_push(Some(string_array));
builder.try_push(Some(string_array)).unwrap();
}

fn field(header: &str) -> Field {
Expand Down

0 comments on commit 79d6cb7

Please sign in to comment.