Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move files out of vtab to core module #359

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
max_width = 120
imports_granularity = "Crate"
imports_granularity = "Crate"
reorder_imports = true
fn_call_width = 72
# indent_style = "Block"
# tab_spaces = 2
# group_imports="StdExternalCrate"
3 changes: 2 additions & 1 deletion crates/duckdb/examples/hello-ext/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion crates/duckdb/src/appender/arrow.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions crates/duckdb/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions crates/duckdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions crates/duckdb/src/vtab/arrow.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/duckdb/src/vtab/excel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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)]
struct ExcelBindData {

Check warning on line 6 in crates/duckdb/src/vtab/excel.rs

View workflow job for this annotation

GitHub Actions / Address Sanitizer

struct `ExcelBindData` is never constructed
range: *mut Range<DataType>,
width: usize,
height: usize,
Expand All @@ -21,13 +21,13 @@
}

#[repr(C)]
struct ExcelInitData {

Check warning on line 24 in crates/duckdb/src/vtab/excel.rs

View workflow job for this annotation

GitHub Actions / Address Sanitizer

struct `ExcelInitData` is never constructed
start: usize,
}

impl Free for ExcelInitData {}

struct ExcelVTab;

Check warning on line 30 in crates/duckdb/src/vtab/excel.rs

View workflow job for this annotation

GitHub Actions / Address Sanitizer

struct `ExcelVTab` is never constructed

impl VTab for ExcelVTab {
type BindData = ExcelBindData;
Expand Down
8 changes: 2 additions & 6 deletions crates/duckdb/src/vtab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
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")]
Expand All @@ -20,12 +17,10 @@
#[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};

Check warning on line 23 in crates/duckdb/src/vtab/mod.rs

View workflow job for this annotation

GitHub Actions / Test x86_64-pc-windows-msvc

unused import: `LogicalTypeId`

Check warning on line 23 in crates/duckdb/src/vtab/mod.rs

View workflow job for this annotation

GitHub Actions / Test x86_64-unknown-linux-gnu

unused import: `LogicalTypeId`
use ffi::{duckdb_bind_info, duckdb_data_chunk, duckdb_function_info, duckdb_init_info};

use ffi::duckdb_malloc;
Expand Down Expand Up @@ -198,6 +193,7 @@
#[cfg(test)]
mod test {
use super::*;
use crate::core::Inserter;
use std::{
error::Error,
ffi::{c_char, CString},
Expand Down
Loading