Skip to content

Commit cc442d0

Browse files
fix: copy table with only null uuids (#144)
1 parent b533b24 commit cc442d0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/arrow_parquet/pg_to_arrow/uuid.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ impl PgTypeToArrowArray<Uuid> for Vec<Option<Uuid>> {
1414
.iter()
1515
.map(|uuid| uuid.as_ref().map(|uuid| uuid.as_bytes().as_slice()))
1616
.collect::<Vec<_>>();
17-
let uuid_array = FixedSizeBinaryArray::from(uuids);
17+
let uuid_array =
18+
FixedSizeBinaryArray::try_from_sparse_iter_with_size(uuids.into_iter(), 16)
19+
.expect("Failed to create FixedSizeBinaryArray from Uuid");
1820
Arc::new(uuid_array)
1921
}
2022
}
@@ -32,7 +34,9 @@ impl PgTypeToArrowArray<Uuid> for Vec<Option<Vec<Option<Uuid>>>> {
3234
.map(|uuid| uuid.as_ref().map(|uuid| uuid.as_bytes().as_slice()))
3335
.collect::<Vec<_>>();
3436

35-
let uuid_array = FixedSizeBinaryArray::from(pg_array);
37+
let uuid_array =
38+
FixedSizeBinaryArray::try_from_sparse_iter_with_size(pg_array.into_iter(), 16)
39+
.expect("Failed to create FixedSizeBinaryArray from Uuid");
3640

3741
let list_array = ListArray::new(
3842
element_context.field(),

src/pgrx_tests/copy_type_roundtrip.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,20 @@ mod tests {
699699
test_table.assert_expected_and_result_rows();
700700
}
701701

702+
#[pg_test]
703+
fn test_all_null_uuid() {
704+
let test_table = TestTable::<Uuid>::new("uuid".into());
705+
test_table.insert("INSERT INTO test_expected (a) VALUES (null), (null);");
706+
test_table.assert_expected_and_result_rows();
707+
}
708+
709+
#[pg_test]
710+
fn test_all_null_uuid_array() {
711+
let test_table = TestTable::<Vec<Option<Uuid>>>::new("uuid[]".into());
712+
test_table.insert("INSERT INTO test_expected (a) VALUES (array[null]::uuid[]);");
713+
test_table.assert_expected_and_result_rows();
714+
}
715+
702716
#[pg_test]
703717
fn test_json() {
704718
let test_table = TestTable::<Json>::new("json".into()).with_order_by_col("a->>'a'".into());

0 commit comments

Comments
 (0)