Skip to content

Commit

Permalink
[CHORE] Split resource-request and hashable-float-wrapper into utilit…
Browse files Browse the repository at this point in the history
…y crates (#2630)

Pulls our `common/resource-request` and `common/hashable-float-wrapper`
into utility crates

This is in preparation for some work I want to do in `daft-dsl` to use
ResourceRequest, but I didn't want to introduce a ` daft-dsl <--
daft-plan` dependency!

---------

Co-authored-by: Jay Chia <[email protected]@users.noreply.github.com>
  • Loading branch information
jaychia and Jay Chia authored Aug 8, 2024
1 parent 877efe2 commit 8f954e8
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 28 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[dependencies]
common-daft-config = {path = "src/common/daft-config", default-features = false}
common-display = {path = "src/common/display", default-features = false}
common-hashable-float-wrapper = {path = "src/common/hashable-float-wrapper", default-features = false}
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}
daft-compression = {path = "src/daft-compression", default-features = false}
Expand Down Expand Up @@ -49,7 +51,8 @@ python = [
"daft-functions/python",
"common-daft-config/python",
"common-system-info/python",
"common-display/python"
"common-display/python",
"common-resource-request/python"
]

[lib]
Expand Down
7 changes: 7 additions & 0 deletions src/common/hashable-float-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[dependencies]
serde = {workspace = true}

[package]
edition = {workspace = true}
name = "common-hashable-float-wrapper"
version = {workspace = true}
12 changes: 12 additions & 0 deletions src/common/resource-request/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[dependencies]
common-hashable-float-wrapper = {path = "../hashable-float-wrapper"}
pyo3 = {workspace = true, optional = true}
serde = {workspace = true}

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

[package]
edition = {workspace = true}
name = "common-resource-request"
version = {workspace = true}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use daft_core::{impl_bincode_py_state_serialization, utils::hashable_float_wrapper::FloatWrapper};
use common_hashable_float_wrapper::FloatWrapper;
#[cfg(feature = "python")]
use pyo3::{
pyclass, pyclass::CompareOp, pymethods, types::PyBytes, PyObject, PyResult, PyTypeInfo, Python,
ToPyObject,
};
use pyo3::{pyclass, pyclass::CompareOp, pymethods, types::PyModule, PyResult, Python};
use std::hash::{Hash, Hasher};
use std::ops::Add;

Expand Down Expand Up @@ -215,4 +212,8 @@ impl ResourceRequest {
}
}

impl_bincode_py_state_serialization!(ResourceRequest);
#[cfg(feature = "python")]
pub fn register_modules(_py: Python, parent: &PyModule) -> PyResult<()> {
parent.add_class::<ResourceRequest>()?;
Ok(())
}
1 change: 1 addition & 0 deletions src/daft-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ chrono-tz = {workspace = true}
comfy-table = {workspace = true}
common-daft-config = {path = "../common/daft-config", default-features = false}
common-error = {path = "../common/error", default-features = false}
common-hashable-float-wrapper = {path = "../common/hashable-float-wrapper"}
daft-minhash = {path = "../daft-minhash", default-features = false}
daft-sketch = {path = "../daft-sketch", default-features = false}
fastrand = "2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/ops/is_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{

use super::as_arrow::AsArrow;
use super::{full::FullNull, DaftIsIn};
use crate::utils::hashable_float_wrapper::FloatWrapper;
use common_error::DaftResult;
use common_hashable_float_wrapper::FloatWrapper;
use std::collections::{BTreeSet, HashSet};

macro_rules! collect_to_set_and_check_membership {
Expand Down
1 change: 0 additions & 1 deletion src/daft-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod arrow;
pub mod display_table;
pub mod dyn_compare;
pub mod hashable_float_wrapper;
pub mod supertype;

pub use bincode;
Expand Down
1 change: 1 addition & 0 deletions src/daft-dsl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[dependencies]
common-error = {path = "../common/error", default-features = false}
common-hashable-float-wrapper = {path = "../common/hashable-float-wrapper"}
common-py-serde = {path = "../common/py-serde", default-features = false}
common-treenode = {path = "../common/treenode", default-features = false}
daft-core = {path = "../daft-core", default-features = false}
Expand Down
8 changes: 3 additions & 5 deletions src/daft-dsl/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common_hashable_float_wrapper::FloatWrapper;
use daft_core::{
count_mode::CountMode,
datatypes::{try_mean_supertype, try_sum_supertype, DataType, Field, FieldID},
Expand Down Expand Up @@ -65,7 +66,7 @@ pub enum Expr {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Hash, Eq)]
pub struct ApproxPercentileParams {
pub child: ExprRef,
pub percentiles: Vec<daft_core::utils::hashable_float_wrapper::FloatWrapper<f64>>,
pub percentiles: Vec<FloatWrapper<f64>>,
pub force_list_output: bool,
}

Expand Down Expand Up @@ -402,10 +403,7 @@ impl Expr {
) -> ExprRef {
Expr::Agg(AggExpr::ApproxPercentile(ApproxPercentileParams {
child: self,
percentiles: percentiles
.iter()
.map(|f| daft_core::utils::hashable_float_wrapper::FloatWrapper(*f))
.collect(),
percentiles: percentiles.iter().map(|f| FloatWrapper(*f)).collect(),
force_list_output,
}))
.into()
Expand Down
2 changes: 1 addition & 1 deletion src/daft-dsl/src/functions/numeric/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod trigonometry;

use abs::AbsEvaluator;
use ceil::CeilEvaluator;
use common_hashable_float_wrapper::FloatWrapper;
use floor::FloorEvaluator;
use log::LogEvaluator;
use round::RoundEvaluator;
Expand All @@ -22,7 +23,6 @@ use trigonometry::Atan2Evaluator;
use crate::functions::numeric::exp::ExpEvaluator;
use crate::functions::numeric::trigonometry::{TrigonometricFunction, TrigonometryEvaluator};
use crate::{Expr, ExprRef};
use daft_core::utils::hashable_float_wrapper::FloatWrapper;

use super::FunctionEvaluator;

Expand Down
2 changes: 1 addition & 1 deletion src/daft-dsl/src/lit.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::expr::Expr;
use crate::ExprRef;

use common_hashable_float_wrapper::FloatWrapper;
use daft_core::datatypes::logical::{Decimal128Array, TimeArray};
use daft_core::utils::display_table::{display_decimal128, display_time64};
use daft_core::utils::hashable_float_wrapper::FloatWrapper;
use daft_core::{array::ops::full::FullNull, datatypes::DataType};
use daft_core::{
datatypes::{
Expand Down
1 change: 1 addition & 0 deletions src/daft-physical-plan/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[dependencies]
common-error = {path = "../common/error", default-features = false}
common-resource-request = {path = "../common/resource-request", default-features = false}
daft-core = {path = "../daft-core", default-features = false}
daft-dsl = {path = "../daft-dsl", default-features = false}
daft-plan = {path = "../daft-plan", default-features = false}
Expand Down
3 changes: 2 additions & 1 deletion src/daft-physical-plan/src/local_plan.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::sync::Arc;

use common_resource_request::ResourceRequest;
use daft_core::{schema::SchemaRef, JoinType};
use daft_dsl::{AggExpr, ExprRef};
use daft_plan::{InMemoryInfo, ResourceRequest};
use daft_plan::InMemoryInfo;
use daft_scan::{ScanTask, ScanTaskRef};

pub type LocalPhysicalPlanRef = Arc<LocalPhysicalPlan>;
Expand Down
2 changes: 2 additions & 0 deletions src/daft-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ common-display = {path = "../common/display", default-features = false}
common-error = {path = "../common/error", default-features = false}
common-io-config = {path = "../common/io-config", default-features = false}
common-py-serde = {path = "../common/py-serde", default-features = false}
common-resource-request = {path = "../common/resource-request", default-features = false}
common-treenode = {path = "../common/treenode", default-features = false}
daft-core = {path = "../daft-core", default-features = false}
daft-dsl = {path = "../daft-dsl", default-features = false}
Expand All @@ -41,6 +42,7 @@ python = [
"common-error/python",
"common-io-config/python",
"common-daft-config/python",
"common-resource-request/python",
"daft-core/python",
"daft-dsl/python",
"daft-functions/python",
Expand Down
3 changes: 2 additions & 1 deletion src/daft-plan/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use crate::{
},
sink_info::{OutputFileInfo, SinkInfo},
source_info::SourceInfo,
LogicalPlanRef, ResourceRequest,
LogicalPlanRef,
};
use common_display::DisplayFormat;
use common_error::DaftResult;
use common_io_config::IOConfig;
use common_resource_request::ResourceRequest;
use daft_core::{
join::{JoinStrategy, JoinType},
schema::{Schema, SchemaRef},
Expand Down
3 changes: 0 additions & 3 deletions src/daft-plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod physical_ops;
mod physical_optimization;
mod physical_plan;
mod physical_planner;
mod resource_request;
mod sink_info;
pub mod source_info;
#[cfg(test)]
Expand All @@ -30,7 +29,6 @@ pub use physical_planner::{
logical_to_physical, populate_aggregation_stages, AdaptivePlanner, MaterializedResults,
QueryStageOutput,
};
pub use resource_request::ResourceRequest;
pub use sink_info::{OutputFileInfo, SinkInfo};
pub use source_info::{FileInfo, FileInfos, InMemoryInfo, SourceInfo};

Expand All @@ -57,7 +55,6 @@ pub fn register_modules(_py: Python, parent: &PyModule) -> PyResult<()> {
parent.add_class::<JsonSourceConfig>()?;
parent.add_class::<CsvSourceConfig>()?;
parent.add_class::<DatabaseSourceConfig>()?;
parent.add_class::<ResourceRequest>()?;
parent.add_class::<FileInfos>()?;
parent.add_class::<FileInfo>()?;
parent.add_class::<PyStorageConfig>()?;
Expand Down
3 changes: 2 additions & 1 deletion src/daft-plan/src/logical_ops/actor_pool_project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use common_resource_request::ResourceRequest;
use common_treenode::TreeNode;
use daft_core::schema::{Schema, SchemaRef};
use daft_dsl::{
Expand All @@ -14,7 +15,7 @@ use snafu::ResultExt;

use crate::{
logical_plan::{CreationSnafu, Result},
LogicalPlan, ResourceRequest,
LogicalPlan,
};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Expand Down
3 changes: 2 additions & 1 deletion src/daft-plan/src/logical_ops/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use common_resource_request::ResourceRequest;
use daft_core::datatypes::FieldID;
use daft_core::schema::{Schema, SchemaRef};
use daft_dsl::{optimization, resolve_exprs, AggExpr, ApproxPercentileParams, Expr, ExprRef};
Expand All @@ -9,7 +10,7 @@ use snafu::ResultExt;

use crate::logical_optimization::Transformed;
use crate::logical_plan::{CreationSnafu, Result};
use crate::{LogicalPlan, ResourceRequest};
use crate::LogicalPlan;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Project {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::HashMap, sync::Arc};

use common_error::DaftResult;

use common_resource_request::ResourceRequest;
use common_treenode::TreeNode;
use daft_core::{schema::Schema, JoinType};
use daft_dsl::{col, optimization::replace_columns_with_expressions, Expr, ExprRef};
Expand All @@ -10,7 +11,7 @@ use indexmap::IndexSet;
use crate::{
logical_ops::{ActorPoolProject, Aggregate, Join, Pivot, Project, Source},
source_info::SourceInfo,
LogicalPlan, ResourceRequest,
LogicalPlan,
};

use super::{ApplyOrder, OptimizerRule, Transformed};
Expand Down
5 changes: 2 additions & 3 deletions src/daft-plan/src/physical_ops/actor_pool_project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use common_error::{DaftError, DaftResult};
use common_resource_request::ResourceRequest;
use common_treenode::TreeNode;
use daft_dsl::{
functions::{
Expand All @@ -12,9 +13,7 @@ use daft_dsl::{
use itertools::Itertools;
use serde::{Deserialize, Serialize};

use crate::{
partitioning::translate_clustering_spec, ClusteringSpec, PhysicalPlanRef, ResourceRequest,
};
use crate::{partitioning::translate_clustering_spec, ClusteringSpec, PhysicalPlanRef};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ActorPoolProject {
Expand Down
2 changes: 1 addition & 1 deletion src/daft-plan/src/physical_ops/project.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::Arc;

use common_error::DaftResult;
use common_resource_request::ResourceRequest;
use daft_dsl::ExprRef;
use itertools::Itertools;

use crate::{
partitioning::translate_clustering_spec, physical_plan::PhysicalPlanRef, ClusteringSpec,
ResourceRequest,
};
use serde::{Deserialize, Serialize};

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub mod pylib {

common_daft_config::register_modules(_py, m)?;
common_system_info::register_modules(_py, m)?;
common_resource_request::register_modules(_py, m)?;
daft_core::register_modules(_py, m)?;
daft_core::python::register_modules(_py, m)?;
daft_local_execution::register_modules(_py, m)?;
Expand Down

0 comments on commit 8f954e8

Please sign in to comment.