Skip to content

Commit

Permalink
feat: expand supported transport types
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Feb 12, 2024
1 parent 72d2afc commit 358cbf3
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 260 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ None of the sources are enabled by default, use features to enable them.

## Types

When converting non-arrow data sources (everything except DuckDB), only a subset of all possible arrows types is produced. Here is a list of what it is currently possible to produce:
When converting from non-arrow data sources (everything except DuckDB), only a subset of all arrows types is produced. Here is a list of supported types:

- [x] Null
- [x] Boolean
Expand All @@ -56,20 +56,20 @@ When converting non-arrow data sources (everything except DuckDB), only a subset
- [x] UInt16
- [x] UInt32
- [x] UInt64
- [ ] Float16
- [x] Float16
- [x] Float32
- [x] Float64
- [ ] Timestamp
- [ ] Date32
- [ ] Date64
- [ ] Time32
- [ ] Time64
- [ ] Duration
- [ ] Interval
- [ ] Binary
- [ ] FixedSizeBinary
- [x] Timestamp
- [x] Date32
- [x] Date64
- [x] Time32
- [x] Time64
- [x] Duration
- [x] Interval
- [x] Binary
- [x] FixedSizeBinary
- [x] LargeBinary
- [ ] Utf8
- [x] Utf8
- [x] LargeUtf8
- [ ] List
- [ ] FixedSizeList
Expand Down
1 change: 1 addition & 0 deletions connector_arrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
pub mod api;
mod errors;
pub mod types;
pub mod util;

#[cfg(feature = "src_duckdb")]
Expand Down
80 changes: 53 additions & 27 deletions connector_arrow/src/postgres/protocol_cursor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use arrow::datatypes::SchemaRef;
use arrow::datatypes::*;
use arrow::record_batch::RecordBatch;
use itertools::Itertools;
use postgres::fallible_iterator::FallibleIterator;
use postgres::{Row, RowIter};

use crate::api::{ResultReader, Statement};
use crate::util::transport::{self, Produce, ProduceTy};
use crate::types::{ArrowType, FixedSizeBinaryType};
use crate::util::transport;
use crate::util::{ArrowRowWriter, CellReader};
use crate::{errors::ConnectorError, util::RowsReader};

Expand Down Expand Up @@ -128,39 +129,64 @@ impl<'row> CellReader<'row> for PostgresCellReader {

type CellRef<'a> = (&'a Row, usize);

impl<'c> Produce<'c> for CellRef<'c> {}
impl<'c> transport::Produce<'c> for CellRef<'c> {}

macro_rules! impl_produce {
($($t: ty,)+) => {
$(
impl<'c> ProduceTy<'c, $t> for CellRef<'c> {
fn produce(self) -> Result<$t, ConnectorError> {
Ok(self.0.get::<usize, $t>(self.1))
impl<'c> transport::ProduceTy<'c, $t> for CellRef<'c> {
fn produce(self) -> Result<<$t as ArrowType>::Native, ConnectorError> {
Ok(self.0.get(self.1))
}

fn produce_opt(self) -> Result<Option<$t>, ConnectorError> {
Ok(self.0.get::<usize, Option<$t>>(self.1))
fn produce_opt(self) -> Result<Option<<$t as ArrowType>::Native>, ConnectorError> {
Ok(self.0.get(self.1))
}
}
)+
};
}

macro_rules! impl_produce_unimplemented {
($($t: ty,)+) => {
$(
impl<'r> ProduceTy<'r, $t> for CellRef<'r> {
fn produce(self) -> Result<$t, ConnectorError> {
unimplemented!();
}

fn produce_opt(self) -> Result<Option<$t>, ConnectorError> {
unimplemented!();
}
}
)+
};
}

impl_produce!(bool, i8, i16, i32, i64, f32, f64, Vec<u8>, String,);
impl_produce_unimplemented!(u8, u16, u32, u64,);
impl_produce!(
BooleanType,
Int8Type,
Int16Type,
Int32Type,
Int64Type,
Float32Type,
Float64Type,
LargeBinaryType,
LargeUtf8Type,
);

crate::impl_produce_unused!(
CellRef<'r>,
(
UInt8Type,
UInt16Type,
UInt32Type,
UInt64Type,
Float16Type,
TimestampSecondType,
TimestampMillisecondType,
TimestampMicrosecondType,
TimestampNanosecondType,
Date32Type,
Date64Type,
Time32SecondType,
Time32MillisecondType,
Time64MicrosecondType,
Time64NanosecondType,
IntervalYearMonthType,
IntervalDayTimeType,
IntervalMonthDayNanoType,
DurationSecondType,
DurationMillisecondType,
DurationMicrosecondType,
DurationNanosecondType,
BinaryType,
FixedSizeBinaryType,
Utf8Type,
Decimal128Type,
Decimal256Type,
)
);
Loading

0 comments on commit 358cbf3

Please sign in to comment.