diff --git a/.rustfmt.toml b/.rustfmt.toml index 0b7ea326..5baafd61 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,7 @@ max_width = 120 -imports_granularity = "Crate" \ No newline at end of file +imports_granularity = "Crate" +reorder_imports = true +fn_call_width = 72 +# indent_style = "Block" +# tab_spaces = 2 +# group_imports="StdExternalCrate" diff --git a/crates/duckdb/examples/hello-ext/main.rs b/crates/duckdb/examples/hello-ext/main.rs index 5409dff1..74ef02d0 100644 --- a/crates/duckdb/examples/hello-ext/main.rs +++ b/crates/duckdb/examples/hello-ext/main.rs @@ -3,7 +3,8 @@ extern crate duckdb_loadable_macros; extern crate libduckdb_sys; use duckdb::{ - vtab::{BindInfo, DataChunk, Free, FunctionInfo, InitInfo, Inserter, LogicalType, LogicalTypeId, VTab}, + core::{DataChunk, Inserter, LogicalType, LogicalTypeId}, + vtab::{BindInfo, Free, FunctionInfo, InitInfo, VTab}, Connection, Result, }; use duckdb_loadable_macros::duckdb_entrypoint; diff --git a/crates/duckdb/src/appender/arrow.rs b/crates/duckdb/src/appender/arrow.rs index 19d79bb4..187af6f4 100644 --- a/crates/duckdb/src/appender/arrow.rs +++ b/crates/duckdb/src/appender/arrow.rs @@ -1,7 +1,8 @@ use super::{ffi, Appender, Result}; use crate::{ + core::{DataChunk, LogicalType}, error::result_from_duckdb_appender, - vtab::{record_batch_to_duckdb_data_chunk, to_duckdb_logical_type, DataChunk, LogicalType}, + vtab::{record_batch_to_duckdb_data_chunk, to_duckdb_logical_type}, Error, }; use arrow::record_batch::RecordBatch; diff --git a/crates/duckdb/src/vtab/data_chunk.rs b/crates/duckdb/src/core/data_chunk.rs similarity index 100% rename from crates/duckdb/src/vtab/data_chunk.rs rename to crates/duckdb/src/core/data_chunk.rs diff --git a/crates/duckdb/src/vtab/logical_type.rs b/crates/duckdb/src/core/logical_type.rs similarity index 97% rename from crates/duckdb/src/vtab/logical_type.rs rename to crates/duckdb/src/core/logical_type.rs index 1ee2543a..9ea83681 100644 --- a/crates/duckdb/src/vtab/logical_type.rs +++ b/crates/duckdb/src/core/logical_type.rs @@ -293,30 +293,30 @@ impl LogicalType { #[cfg(test)] mod test { - use super::{LogicalType, LogicalTypeId}; + use crate::core::{LogicalType, LogicalTypeId}; #[test] fn test_struct() { - let fields = &[("hello", LogicalType::new(crate::vtab::LogicalTypeId::Boolean))]; + let fields = &[("hello", LogicalType::new(crate::core::LogicalTypeId::Boolean))]; let typ = LogicalType::struct_type(fields); assert_eq!(typ.num_children(), 1); assert_eq!(typ.child_name(0), "hello"); - assert_eq!(typ.child(0).id(), crate::vtab::LogicalTypeId::Boolean); + assert_eq!(typ.child(0).id(), crate::core::LogicalTypeId::Boolean); } #[test] fn test_decimal() { let typ = LogicalType::decimal(10, 2); - assert_eq!(typ.id(), crate::vtab::LogicalTypeId::Decimal); + assert_eq!(typ.id(), crate::core::LogicalTypeId::Decimal); assert_eq!(typ.decimal_width(), 10); assert_eq!(typ.decimal_scale(), 2); } #[test] fn test_decimal_methods() { - let typ = LogicalType::new(crate::vtab::LogicalTypeId::Varchar); + let typ = LogicalType::new(crate::core::LogicalTypeId::Varchar); assert_eq!(typ.decimal_width(), 0); assert_eq!(typ.decimal_scale(), 0); diff --git a/crates/duckdb/src/core/mod.rs b/crates/duckdb/src/core/mod.rs new file mode 100644 index 00000000..1726a35f --- /dev/null +++ b/crates/duckdb/src/core/mod.rs @@ -0,0 +1,7 @@ +mod data_chunk; +mod logical_type; +mod vector; + +pub use data_chunk::DataChunk; +pub use logical_type::{LogicalType, LogicalTypeId}; +pub use vector::*; diff --git a/crates/duckdb/src/vtab/vector.rs b/crates/duckdb/src/core/vector.rs similarity index 99% rename from crates/duckdb/src/vtab/vector.rs rename to crates/duckdb/src/core/vector.rs index 7de18578..54f68607 100644 --- a/crates/duckdb/src/vtab/vector.rs +++ b/crates/duckdb/src/core/vector.rs @@ -206,6 +206,7 @@ impl ArrayVector { LogicalType::from(unsafe { duckdb_vector_get_column_type(self.ptr) }) } + /// Returns the size of the array type. pub fn get_array_size(&self) -> u64 { let ty = self.logical_type(); unsafe { duckdb_array_type_array_size(ty.ptr) as u64 } diff --git a/crates/duckdb/src/lib.rs b/crates/duckdb/src/lib.rs index d18f6daf..49ca966f 100644 --- a/crates/duckdb/src/lib.rs +++ b/crates/duckdb/src/lib.rs @@ -93,6 +93,9 @@ pub use arrow; #[cfg(feature = "polars")] pub use polars::{self, export::arrow as arrow2}; +/// The core module contains the main functionality of the DuckDB crate. +pub mod core; + #[macro_use] mod error; mod appender; diff --git a/crates/duckdb/src/vtab/arrow.rs b/crates/duckdb/src/vtab/arrow.rs index 3bb1693e..8adeec19 100644 --- a/crates/duckdb/src/vtab/arrow.rs +++ b/crates/duckdb/src/vtab/arrow.rs @@ -1,10 +1,7 @@ -use super::{ - vector::{ArrayVector, FlatVector, ListVector, Vector}, - BindInfo, DataChunk, Free, FunctionInfo, InitInfo, LogicalType, LogicalTypeId, StructVector, VTab, -}; +use super::{BindInfo, DataChunk, Free, FunctionInfo, InitInfo, LogicalType, LogicalTypeId, VTab}; use std::ptr::null_mut; -use crate::vtab::vector::Inserter; +use crate::core::{ArrayVector, FlatVector, Inserter, ListVector, StructVector, Vector}; use arrow::array::{ as_boolean_array, as_generic_binary_array, as_large_list_array, as_list_array, as_primitive_array, as_string_array, as_struct_array, Array, ArrayData, AsArray, BinaryArray, BooleanArray, Decimal128Array, FixedSizeListArray, diff --git a/crates/duckdb/src/vtab/excel.rs b/crates/duckdb/src/vtab/excel.rs index 355d9d30..883aa7a9 100644 --- a/crates/duckdb/src/vtab/excel.rs +++ b/crates/duckdb/src/vtab/excel.rs @@ -1,5 +1,5 @@ use super::{BindInfo, DataChunk, Free, FunctionInfo, InitInfo, LogicalType, LogicalTypeId, VTab}; -use crate::vtab::vector::Inserter; +use crate::core::Inserter; use calamine::{open_workbook_auto, DataType, Range, Reader}; #[repr(C)] diff --git a/crates/duckdb/src/vtab/mod.rs b/crates/duckdb/src/vtab/mod.rs index 40717819..d1e843c2 100644 --- a/crates/duckdb/src/vtab/mod.rs +++ b/crates/duckdb/src/vtab/mod.rs @@ -3,11 +3,8 @@ use crate::{error::Error, inner_connection::InnerConnection, Connection, Result} use super::{ffi, ffi::duckdb_free}; use std::ffi::c_void; -mod data_chunk; mod function; -mod logical_type; mod value; -mod vector; /// The duckdb Arrow table function interface #[cfg(feature = "vtab-arrow")] @@ -20,12 +17,10 @@ pub use self::arrow::{ #[cfg(feature = "vtab-excel")] mod excel; -pub use data_chunk::DataChunk; pub use function::{BindInfo, FunctionInfo, InitInfo, TableFunction}; -pub use logical_type::{LogicalType, LogicalTypeId}; pub use value::Value; -pub use vector::{FlatVector, Inserter, ListVector, StructVector, Vector}; +use crate::core::{DataChunk, LogicalType, LogicalTypeId}; use ffi::{duckdb_bind_info, duckdb_data_chunk, duckdb_function_info, duckdb_init_info}; use ffi::duckdb_malloc; @@ -198,6 +193,7 @@ impl InnerConnection { #[cfg(test)] mod test { use super::*; + use crate::core::Inserter; use std::{ error::Error, ffi::{c_char, CString},