Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Moved files
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Feb 18, 2022
1 parent 1251e09 commit 83c47fc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 42 deletions.
1 change: 1 addition & 0 deletions arrow-odbc-integration-testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(test)]

mod read;
//mod write;

use arrow2::io::odbc::api::{Connection, Environment, Error as OdbcError};
use lazy_static::lazy_static;
Expand Down
4 changes: 2 additions & 2 deletions arrow-odbc-integration-testing/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use arrow2::chunk::Chunk;
use arrow2::datatypes::Field;
use arrow2::error::Result;
use arrow2::io::odbc::api::{Connection, Cursor};
use arrow2::io::odbc::{buffer_from_metadata, deserialize, infer_schema};
use arrow2::io::odbc::read::{buffer_from_metadata, deserialize, infer_schema};

use super::{setup_empty_table, ENV, MSSQL};

Expand Down Expand Up @@ -110,7 +110,7 @@ fn test(
Ok(())
}

fn read(
pub fn read(
connection: &Connection<'_>,
query: &str,
) -> Result<(Vec<Field>, Vec<Chunk<Box<dyn Array>>>)> {
Expand Down
38 changes: 3 additions & 35 deletions src/io/odbc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
//! API to connect to ODBC
//! API to serialize and deserialize data from and to ODBC
pub use odbc_api as api;

mod deserialize;
mod schema;

pub use deserialize::deserialize;
pub use schema::infer_schema;

/// Creates a [`api::buffers::ColumnarBuffer`] from the metadata.
/// # Errors
/// Iff the driver provides an incorrect [`ResultSetMetadata`]
pub fn buffer_from_metadata(
resut_set_metadata: &impl api::ResultSetMetadata,
max_batch_size: usize,
) -> std::result::Result<api::buffers::ColumnarBuffer<api::buffers::AnyColumnBuffer>, api::Error> {
let num_cols: u16 = resut_set_metadata.num_result_cols()? as u16;

let descs = (0..num_cols)
.map(|index| {
let mut column_description = api::ColumnDescription::default();

resut_set_metadata.describe_col(index + 1, &mut column_description)?;

Ok(api::buffers::BufferDescription {
nullable: column_description.could_be_nullable(),
kind: api::buffers::BufferKind::from_data_type(column_description.data_type)
.unwrap(),
})
})
.collect::<std::result::Result<Vec<_>, api::Error>>()?;

Ok(api::buffers::buffer_from_description(
max_batch_size,
descs.into_iter(),
))
}
pub mod read;
//pub mod write;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::buffer::Buffer;
use crate::datatypes::DataType;
use crate::types::NativeType;

use super::api::buffers::AnyColumnView;
use super::super::api::buffers::AnyColumnView;

/// Deserializes a [`AnyColumnView`] into an array of [`DataType`].
/// This is CPU-bounded
Expand Down
37 changes: 37 additions & 0 deletions src/io/odbc/read/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! APIs to read from ODBC
mod deserialize;
mod schema;

pub use deserialize::deserialize;
pub use schema::infer_schema;

use super::api;

/// Creates a [`api::buffers::ColumnarBuffer`] from the metadata.
/// # Errors
/// Iff the driver provides an incorrect [`ResultSetMetadata`]
pub fn buffer_from_metadata(
resut_set_metadata: &impl api::ResultSetMetadata,
max_batch_size: usize,
) -> std::result::Result<api::buffers::ColumnarBuffer<api::buffers::AnyColumnBuffer>, api::Error> {
let num_cols: u16 = resut_set_metadata.num_result_cols()? as u16;

let descs = (0..num_cols)
.map(|index| {
let mut column_description = api::ColumnDescription::default();

resut_set_metadata.describe_col(index + 1, &mut column_description)?;

Ok(api::buffers::BufferDescription {
nullable: column_description.could_be_nullable(),
kind: api::buffers::BufferKind::from_data_type(column_description.data_type)
.unwrap(),
})
})
.collect::<std::result::Result<Vec<_>, api::Error>>()?;

Ok(api::buffers::buffer_from_description(
max_batch_size,
descs.into_iter(),
))
}
8 changes: 4 additions & 4 deletions src/io/odbc/schema.rs → src/io/odbc/read/schema.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::api;
use super::api::ResultSetMetadata;

use crate::datatypes::{DataType, Field, TimeUnit};
use crate::error::Result;
use crate::error::{ArrowError, Result};

use super::super::api;
use super::super::api::ResultSetMetadata;

/// Infers the Arrow [`Field`]s from a [`ResultSetMetadata`]
pub fn infer_schema(resut_set_metadata: &impl ResultSetMetadata) -> Result<Vec<Field>> {
Expand Down

0 comments on commit 83c47fc

Please sign in to comment.