Skip to content

Commit

Permalink
[CHORE] Move out datatype and schema from daft-core (#2806)
Browse files Browse the repository at this point in the history
* Factors out DataType, Field, Schema into `daft-schema`
* Factors out our display logic to `common-display`
* Factors out array ffi code into `common-arrow-ffi`
* Create `StrValue` trait that allows us to pass `&dyn StrValue` to the
common-display crate without it knowing what a series is.
* Reexport `daft-schema::{DataType, Schema, Field}` for convenience 

Follow on:
* Factor out daft-scan and daft-plan dependance on daft-core. This will
allow them to directly depend on `daft-schema`
  • Loading branch information
samster25 authored Sep 9, 2024
1 parent f9b7af2 commit 5cf876a
Show file tree
Hide file tree
Showing 123 changed files with 709 additions and 547 deletions.
42 changes: 40 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ common-hashable-float-wrapper = {path = "src/common/hashable-float-wrapper", def
common-resource-request = {path = "src/common/resource-request", default-features = false}
common-system-info = {path = "src/common/system-info", default-features = false}
common-tracing = {path = "src/common/tracing", default-features = false}
common-version = {path = "src/common/version", default-features = false}
daft-compression = {path = "src/daft-compression", default-features = false}
daft-core = {path = "src/daft-core", default-features = false}
daft-csv = {path = "src/daft-csv", default-features = false}
Expand Down
11 changes: 11 additions & 0 deletions src/common/arrow-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[dependencies]
arrow2 = {workspace = true}
pyo3 = {workspace = true, optional = true}

[features]
python = ["dep:pyo3"]

[package]
edition = {workspace = true}
name = "common-arrow-ffi"
version = {workspace = true}
7 changes: 6 additions & 1 deletion src/daft-core/src/ffi.rs → src/common/arrow-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use std::io::Cursor;

use arrow2::{array::Array, datatypes::Field, ffi};

#[cfg(feature = "python")]
use pyo3::ffi::Py_uintptr_t;
#[cfg(feature = "python")]
use pyo3::prelude::*;

pub type ArrayRef = Box<dyn Array>;

#[cfg(feature = "python")]
pub fn array_to_rust(arrow_array: &PyAny) -> PyResult<ArrayRef> {
// prepare a pointer to receive the Array struct
let array = Box::new(ffi::ArrowArray::empty());
Expand All @@ -28,7 +31,7 @@ pub fn array_to_rust(arrow_array: &PyAny) -> PyResult<ArrayRef> {
Ok(array)
}
}

#[cfg(feature = "python")]
pub fn to_py_array(array: ArrayRef, py: Python, pyarrow: &PyModule) -> PyResult<PyObject> {
let schema = Box::new(ffi::export_field_to_c(&Field::new(
"",
Expand All @@ -53,6 +56,7 @@ pub fn to_py_array(array: ArrayRef, py: Python, pyarrow: &PyModule) -> PyResult<
Ok(array.to_object(py))
}

#[cfg(feature = "python")]
pub fn field_to_py(
field: &arrow2::datatypes::Field,
py: Python,
Expand All @@ -69,6 +73,7 @@ pub fn field_to_py(
Ok(field.to_object(py))
}

#[cfg(feature = "python")]
pub fn dtype_to_py(
dtype: &arrow2::datatypes::DataType,
py: Python,
Expand Down
3 changes: 0 additions & 3 deletions src/common/daft-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
use common_io_config::IOConfig;
use serde::{Deserialize, Serialize};

/// Environment variables for Daft to use when formatting displays.
pub const BOLD_TABLE_HEADERS_IN_DISPLAY: &str = "DAFT_BOLD_TABLE_HEADERS";

/// Configurations for Daft to use during the building of a Dataframe's plan.
///
/// 1. Creation of a Dataframe including any file listing and schema inference that needs to happen. Note
Expand Down
1 change: 1 addition & 0 deletions src/common/display/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[dependencies]
comfy-table = {workspace = true}
indexmap = {workspace = true}
pyo3 = {workspace = true, optional = true}
terminal_size = {version = "0.3.0"}
Expand Down
2 changes: 2 additions & 0 deletions src/common/display/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(let_chains)]
pub mod ascii;
pub mod mermaid;
pub mod table_display;
pub mod tree;
pub mod utils;

Expand Down
Loading

0 comments on commit 5cf876a

Please sign in to comment.