Skip to content

Commit 9dd9c63

Browse files
committed
impl arrow_assoc for postgres for vec<bool>
1 parent e6c8f5d commit 9dd9c63

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

connectorx/src/destinations/arrow2/arrow_assoc.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,57 @@ impl_arrow_assoc_vec!(u64, ArrowDataType::UInt64);
121121
impl_arrow_assoc_vec!(f32, ArrowDataType::Float32);
122122
impl_arrow_assoc_vec!(f64, ArrowDataType::Float64);
123123

124+
impl ArrowAssoc for Vec<bool> {
125+
// type Builder = MutableListArray<i64, MutablePrimitiveArray<i8>>;
126+
type Builder = MutableListArray<i64, MutableBooleanArray>;
127+
128+
fn builder(nrows: usize) -> Self::Builder {
129+
MutableListArray::<i64, MutableBooleanArray>::with_capacity(nrows)
130+
}
131+
132+
#[inline]
133+
fn push(builder: &mut Self::Builder, value: Self) {
134+
// hmm
135+
let val: Vec<Option<bool>> = value.into_iter().map(|v| Some(v)).collect();
136+
builder.try_push(Some(val)).unwrap();
137+
}
138+
139+
fn field(header: &str) -> Field {
140+
Field::new(
141+
header,
142+
ArrowDataType::LargeList(Box::new(Field::new("", ArrowDataType::Boolean, false))),
143+
false,
144+
)
145+
}
146+
}
147+
148+
impl ArrowAssoc for Option<Vec<bool>> {
149+
type Builder = MutableListArray<i64, MutableBooleanArray>;
150+
151+
fn builder(nrows: usize) -> Self::Builder {
152+
MutableListArray::<i64, MutableBooleanArray>::with_capacity(nrows)
153+
}
154+
155+
#[inline]
156+
fn push(builder: &mut Self::Builder, value: Self) {
157+
match value {
158+
Some(values) => {
159+
let val: Vec<Option<bool>> = values.into_iter().map(|v| Some(v)).collect();
160+
builder.try_push(Some(val)).unwrap();
161+
}
162+
None => builder.push_null(),
163+
}
164+
}
165+
166+
fn field(header: &str) -> Field {
167+
Field::new(
168+
header,
169+
ArrowDataType::LargeList(Box::new(Field::new("", ArrowDataType::Boolean, false))),
170+
true,
171+
)
172+
}
173+
}
174+
124175
impl ArrowAssoc for &str {
125176
type Builder = MutableUtf8Array<i64>;
126177

connectorx/src/destinations/arrow2/typesystem.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum Arrow2TypeSystem {
1616
Date64(bool),
1717
Time64(bool),
1818
DateTimeTz(bool),
19+
BoolArray(bool),
1920
Int32Array(bool),
2021
Int64Array(bool),
2122
UInt32Array(bool),
@@ -41,6 +42,7 @@ impl_typesystem! {
4142
{ Date64 => NaiveDateTime }
4243
{ Time64 => NaiveTime }
4344
{ DateTimeTz => DateTime<Utc> }
45+
{ BoolArray => Vec<bool> }
4446
{ Int32Array => Vec<i32> }
4547
{ Int64Array => Vec<i64> }
4648
{ UInt32Array => Vec<u32> }

connectorx/src/transports/postgres_arrow2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ macro_rules! impl_postgres_transport {
6161
{ ByteA[Vec<u8>] => LargeBinary[Vec<u8>] | conversion auto }
6262
{ JSON[Value] => LargeUtf8[String] | conversion option }
6363
{ JSONB[Value] => LargeUtf8[String] | conversion none }
64+
{ BoolArray[Vec<bool>] => BoolArray[Vec<bool>] | conversion auto_vec }
6465
{ Int2Array[Vec<i16>] => Int64Array[Vec<i64>] | conversion auto_vec }
6566
{ Int4Array[Vec<i32>] => Int64Array[Vec<i64>] | conversion auto_vec }
6667
{ Int8Array[Vec<i64>] => Int64Array[Vec<i64>] | conversion auto }

0 commit comments

Comments
 (0)