Skip to content

Commit

Permalink
feat: sqlite proper schema inference
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Feb 5, 2024
1 parent 8c6df6a commit c12cea4
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 136 deletions.
1 change: 0 additions & 1 deletion connector_arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ features = ["with-chrono-0_4", "with-uuid-0_8", "with-serde_json-1"]
version = "0.30.0"
default-features = false
optional = true
features = ["column_decltype"]

[dependencies.duckdb]
version = "0.9"
Expand Down
10 changes: 5 additions & 5 deletions connector_arrow/src/postgres/protocol_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> PostgresBatchStream<'a> {
for field in &self.schema.fields {
let cell_ref = cell_reader.next_cell();

transport::transport(field, &cell_ref.unwrap(), &mut writer)?;
transport::transport(field, cell_ref.unwrap(), &mut writer)?;
}
} else {
self.is_finished = true;
Expand Down Expand Up @@ -141,12 +141,12 @@ macro_rules! impl_produce {
$(
impl<'c> ProduceTy<'c, $t> for CellRef<'c> {
#[throws(ConnectorError)]
fn produce(&self) -> $t {
fn produce(self) -> $t {
self.0.get::<usize, $t>(self.1)
}

#[throws(ConnectorError)]
fn produce_opt(&self) -> Option<$t> {
fn produce_opt(self) -> Option<$t> {
self.0.get::<usize, Option<$t>>(self.1)
}
}
Expand All @@ -158,11 +158,11 @@ macro_rules! impl_produce_unimplemented {
($($t: ty,)+) => {
$(
impl<'r> ProduceTy<'r, $t> for CellRef<'r> {
fn produce(&self) -> Result<$t, ConnectorError> {
fn produce(self) -> Result<$t, ConnectorError> {
unimplemented!();
}

fn produce_opt(&self) -> Result<Option<$t>, ConnectorError> {
fn produce_opt(self) -> Result<Option<$t>, ConnectorError> {
unimplemented!();
}
}
Expand Down
44 changes: 22 additions & 22 deletions connector_arrow/src/postgres/protocol_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ macro_rules! impl_simple_produce_unimplemented {
($($t: ty,)+) => {
$(
impl<'r> ProduceTy<'r, $t> for CellRef<'r> {
fn produce(&self) -> Result<$t, ConnectorError> {
fn produce(self) -> Result<$t, ConnectorError> {
unimplemented!();
}

fn produce_opt(&self) -> Result<Option<$t>, ConnectorError> {
fn produce_opt(self) -> Result<Option<$t>, ConnectorError> {
unimplemented!();
}
}
Expand All @@ -101,11 +101,11 @@ macro_rules! impl_simple_produce {
($($t: ty,)+) => {
$(
impl<'r> ProduceTy<'r, $t> for CellRef<'r> {
fn produce(&self) -> Result<$t, ConnectorError> {
fn produce(self) -> Result<$t, ConnectorError> {
self.produce_opt()?.ok_or_else(err_null)
}

fn produce_opt(&self) -> Result<Option<$t>, ConnectorError> {
fn produce_opt(self) -> Result<Option<$t>, ConnectorError> {
let s = self.0.get(self.1);

Ok(match s {
Expand All @@ -127,13 +127,13 @@ impl_simple_produce_unimplemented!(

impl<'r> ProduceTy<'r, String> for CellRef<'r> {
#[throws(ConnectorError)]
fn produce(&self) -> String {
fn produce(self) -> String {
let val = self.0.get(self.1).unwrap().to_string();
val
}

#[throws(ConnectorError)]
fn produce_opt(&self) -> Option<String> {
fn produce_opt(self) -> Option<String> {
self.0.get(self.1).map(|x| x.to_string())
}
}
Expand All @@ -149,23 +149,23 @@ fn parse_bool(token: &str) -> Result<bool, ConnectorError> {
}

impl<'r> ProduceTy<'r, bool> for CellRef<'r> {
fn produce(&self) -> Result<bool, ConnectorError> {
fn produce(self) -> Result<bool, ConnectorError> {
self.produce_opt()?.ok_or_else(err_null)
}

fn produce_opt(&self) -> Result<Option<bool>, ConnectorError> {
fn produce_opt(self) -> Result<Option<bool>, ConnectorError> {
let s = self.0.get(self.1);
s.map(parse_bool).transpose()
}
}

impl<'r> ProduceTy<'r, Vec<u8>> for CellRef<'r> {
fn produce(&self) -> Result<Vec<u8>, ConnectorError> {
fn produce(self) -> Result<Vec<u8>, ConnectorError> {
self.produce_opt()?.ok_or_else(err_null)
}

#[throws(ConnectorError)]
fn produce_opt(&self) -> Option<Vec<u8>> {
fn produce_opt(self) -> Option<Vec<u8>> {
let s = self.0.get(self.1);

match s {
Expand Down Expand Up @@ -213,11 +213,11 @@ macro_rules! impl_simple_vec_produce {
($($t: ty,)+) => {
$(
impl<'r> ProduceTy<'r, Vec<$t>> for CellRef<'r> {
fn produce(&self) -> Result<Vec<$t>, ConnectorError> {
fn produce(self) -> Result<Vec<$t>, ConnectorError> {
self.produce_opt()?.ok_or_else(err_null)
}

fn produce_opt(&self) -> Result<Option<Vec<$t>>, ConnectorError> {
fn produce_opt(self) -> Result<Option<Vec<$t>>, ConnectorError> {
let s = self.0.get(self.1);

parse_array(
Expand All @@ -232,19 +232,19 @@ macro_rules! impl_simple_vec_produce {
impl_simple_vec_produce!(i16, i32, i64, f32, f64, Decimal, String,);

impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
fn produce(&self) -> Result<Vec<bool>, ConnectorError> {
fn produce(self) -> Result<Vec<bool>, ConnectorError> {
self.produce_opt()?.ok_or_else(err_null)
}

fn produce_opt(&self) -> Result<Option<Vec<bool>>, ConnectorError> {
fn produce_opt(self) -> Result<Option<Vec<bool>>, ConnectorError> {
let s = self.0.get(self.1);

parse_array(s, parse_bool)
}
}

// impl<'r> ProduceTy<'r, NaiveDate> for CellRef<'r> {
// fn produce(&self) -> NaiveDate {
// fn produce(self) -> NaiveDate {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -264,7 +264,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, Option<NaiveDate>> for CellRef<'r> {
// fn produce(&self) -> Option<NaiveDate> {
// fn produce(self) -> Option<NaiveDate> {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -285,7 +285,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, NaiveTime> for CellRef<'r> {
// fn produce(&self) -> NaiveTime {
// fn produce(self) -> NaiveTime {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -305,7 +305,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, Option<NaiveTime>> for CellRef<'r> {
// fn produce(&self) -> Option<NaiveTime> {
// fn produce(self) -> Option<NaiveTime> {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -326,7 +326,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, NaiveDateTime> for CellRef<'r> {
// fn produce(&self) -> NaiveDateTime {
// fn produce(self) -> NaiveDateTime {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -347,7 +347,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, Option<NaiveDateTime>> for CellRef<'r> {
// fn produce(&self) -> Option<NaiveDateTime> {
// fn produce(self) -> Option<NaiveDateTime> {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -370,7 +370,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, DateTime<Utc>> for CellRef<'r> {
// fn produce(&self) -> DateTime<Utc> {
// fn produce(self) -> DateTime<Utc> {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand All @@ -396,7 +396,7 @@ impl<'r> ProduceTy<'r, Vec<bool>> for CellRef<'r> {
// }

// impl<'r> ProduceTy<'r, Option<DateTime<Utc>>> for CellRef<'r> {
// fn produce(&self) -> Option<DateTime<Utc>> {
// fn produce(self) -> Option<DateTime<Utc>> {
// let (ridx, cidx) = self.next_cell();
// let val = match &self.rows[ridx] {
// SimpleQueryMessage::Row(row) => match row.try_get(cidx)? {
Expand Down
Loading

0 comments on commit c12cea4

Please sign in to comment.