Skip to content

Commit

Permalink
[CHORE] refactor daft-core with preclude (#2782)
Browse files Browse the repository at this point in the history
* Factors out common imports for daft-core into `daft_core::prelude::*`


This allows downstream crates to just 

```
use daft_core::prelude::*;

impl FunctionUDF {...}

```
  • Loading branch information
samster25 authored Sep 5, 2024
1 parent 7fe3dbc commit 178f5f0
Show file tree
Hide file tree
Showing 181 changed files with 450 additions and 728 deletions.
6 changes: 3 additions & 3 deletions src/daft-core/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::sync::Arc;
use common_error::{DaftError, DaftResult};

use crate::array::growable::{Growable, GrowableArray};
use crate::datatypes::DataType;
use crate::datatypes::{DaftArrayType, Field};
use crate::series::Series;
use crate::DataType;

#[derive(Clone, Debug)]
pub struct FixedSizeListArray {
Expand Down Expand Up @@ -223,8 +223,8 @@ mod tests {
use common_error::DaftResult;

use crate::{
datatypes::{Field, Int32Array},
DataType, IntoSeries,
datatypes::{DataType, Field, Int32Array},
series::IntoSeries,
};

use super::FixedSizeListArray;
Expand Down
31 changes: 13 additions & 18 deletions src/daft-core/src/array/from_iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::datatypes::{
BinaryArray, BooleanArray, DaftNumericType, Field, FixedSizeBinaryArray, Utf8Array,
};
use crate::array::prelude::*;
use crate::datatypes::prelude::*;

use super::DataArray;

Expand All @@ -24,7 +23,11 @@ impl Utf8Array {
iter: impl arrow2::trusted_len::TrustedLen<Item = Option<S>>,
) -> Self {
let arrow_array = Box::new(arrow2::array::Utf8Array::<i64>::from_trusted_len_iter(iter));
DataArray::new(Field::new(name, crate::DataType::Utf8).into(), arrow_array).unwrap()
DataArray::new(
Field::new(name, crate::datatypes::DataType::Utf8).into(),
arrow_array,
)
.unwrap()
}
}

Expand All @@ -37,7 +40,7 @@ impl BinaryArray {
iter,
));
DataArray::new(
Field::new(name, crate::DataType::Binary).into(),
Field::new(name, crate::datatypes::DataType::Binary).into(),
arrow_array,
)
.unwrap()
Expand All @@ -52,7 +55,7 @@ impl FixedSizeBinaryArray {
) -> Self {
let arrow_array = Box::new(arrow2::array::FixedSizeBinaryArray::from_iter(iter, size));
DataArray::new(
Field::new(name, crate::DataType::FixedSizeBinary(size)).into(),
Field::new(name, crate::datatypes::DataType::FixedSizeBinary(size)).into(),
arrow_array,
)
.unwrap()
Expand All @@ -66,7 +69,7 @@ impl BooleanArray {
) -> Self {
let arrow_array = Box::new(arrow2::array::BooleanArray::from_trusted_len_iter(iter));
DataArray::new(
Field::new(name, crate::DataType::Boolean).into(),
Field::new(name, crate::datatypes::DataType::Boolean).into(),
arrow_array,
)
.unwrap()
Expand Down Expand Up @@ -95,7 +98,7 @@ impl Utf8Array {
) -> Self {
let arrow_array =
Box::new(arrow2::array::Utf8Array::<i64>::from_trusted_len_values_iter(iter));
DataArray::new(Field::new(name, crate::DataType::Utf8).into(), arrow_array).unwrap()
DataArray::new(Field::new(name, DataType::Utf8).into(), arrow_array).unwrap()
}
}

Expand All @@ -106,11 +109,7 @@ impl BinaryArray {
) -> Self {
let arrow_array =
Box::new(arrow2::array::BinaryArray::<i64>::from_trusted_len_values_iter(iter));
DataArray::new(
Field::new(name, crate::DataType::Binary).into(),
arrow_array,
)
.unwrap()
DataArray::new(Field::new(name, DataType::Binary).into(), arrow_array).unwrap()
}
}

Expand All @@ -122,10 +121,6 @@ impl BooleanArray {
let arrow_array = Box::new(arrow2::array::BooleanArray::from_trusted_len_values_iter(
iter,
));
DataArray::new(
Field::new(name, crate::DataType::Boolean).into(),
arrow_array,
)
.unwrap()
DataArray::new(Field::new(name, DataType::Boolean).into(), arrow_array).unwrap()
}
}
13 changes: 1 addition & 12 deletions src/daft-core/src/array/growable/arrow_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@ use std::{marker::PhantomData, sync::Arc};

use common_error::DaftResult;

use crate::{
array::{
ops::{as_arrow::AsArrow, from_arrow::FromArrow},
DataArray,
},
datatypes::{
BinaryType, BooleanType, DaftArrowBackedType, DaftDataType, ExtensionArray, Field,
FixedSizeBinaryType, Float32Type, Float64Type, Int128Type, Int16Type, Int32Type, Int64Type,
Int8Type, NullType, UInt16Type, UInt32Type, UInt64Type, UInt8Type, Utf8Type,
},
DataType, IntoSeries, Series,
};
use crate::{array::prelude::*, datatypes::prelude::*, series::IntoSeries, series::Series};

use super::Growable;

Expand Down
4 changes: 3 additions & 1 deletion src/daft-core/src/array/growable/fixed_size_list_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use common_error::DaftResult;

use crate::{
array::{growable::make_growable, FixedSizeListArray},
datatypes::DataType,
datatypes::Field,
DataType, IntoSeries, Series,
series::IntoSeries,
series::Series,
};

use super::{bitmap_growable::ArrowBitmapGrowable, Growable};
Expand Down
5 changes: 3 additions & 2 deletions src/daft-core/src/array/growable/list_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use common_error::DaftResult;

use crate::{
array::{growable::make_growable, ListArray},
datatypes::Field,
DataType, IntoSeries, Series,
datatypes::{DataType, Field},
series::IntoSeries,
series::Series,
};

use super::{bitmap_growable::ArrowBitmapGrowable, Growable};
Expand Down
9 changes: 1 addition & 8 deletions src/daft-core/src/array/growable/logical_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ use std::marker::PhantomData;

use common_error::DaftResult;

use crate::{
datatypes::{
logical::LogicalArray, DaftDataType, DaftLogicalType, DateType, Decimal128Type,
DurationType, EmbeddingType, Field, FixedShapeImageType, FixedShapeTensorType, ImageType,
MapType, TensorType, TimeType, TimestampType,
},
DataType, IntoSeries, Series,
};
use crate::{array::prelude::*, datatypes::prelude::*, series::IntoSeries, series::Series};

use super::{Growable, GrowableArray};

Expand Down
14 changes: 4 additions & 10 deletions src/daft-core/src/array/growable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use common_error::DaftResult;

use crate::{
array::prelude::*,
array::{FixedSizeListArray, ListArray, StructArray},
datatypes::{
logical::{
DateArray, Decimal128Array, DurationArray, EmbeddingArray, FixedShapeImageArray,
FixedShapeTensorArray, ImageArray, MapArray, TensorArray, TimeArray, TimestampArray,
},
BinaryArray, BooleanArray, ExtensionArray, FixedSizeBinaryArray, Float32Array,
Float64Array, Int128Array, Int16Array, Int32Array, Int64Array, Int8Array, NullArray,
UInt16Array, UInt32Array, UInt64Array, UInt8Array, Utf8Array,
},
with_match_daft_types, DataType, Series,
datatypes::prelude::*,
series::Series,
with_match_daft_types,
};

mod arrow_growable;
Expand Down
5 changes: 3 additions & 2 deletions src/daft-core/src/array/growable/python_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::{mem::swap, sync::Arc};

use crate::{
array::{pseudo_arrow::PseudoArrowArray, DataArray},
datatypes::{Field, PythonArray, PythonType},
DataType, IntoSeries, Series,
datatypes::{DataType, Field, PythonArray, PythonType},
series::IntoSeries,
series::Series,
};

use super::Growable;
Expand Down
4 changes: 3 additions & 1 deletion src/daft-core/src/array/growable/struct_growable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use common_error::DaftResult;

use crate::{
array::{growable::make_growable, StructArray},
datatypes::DataType,
datatypes::Field,
DataType, IntoSeries, Series,
series::IntoSeries,
series::Series,
};

use super::{bitmap_growable::ArrowBitmapGrowable, Growable};
Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::sync::Arc;
use common_error::{DaftError, DaftResult};

use crate::array::growable::{Growable, GrowableArray};
use crate::datatypes::DataType;
use crate::datatypes::{DaftArrayType, Field};
use crate::series::Series;
use crate::DataType;

#[derive(Clone, Debug)]
pub struct ListArray {
Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use list_array::ListArray;
pub use struct_array::StructArray;
mod boolean;
mod from_iter;

pub mod prelude;
use std::{marker::PhantomData, sync::Arc};

use crate::datatypes::{DaftArrayType, DaftPhysicalType, DataType, Field};
Expand Down
3 changes: 2 additions & 1 deletion src/daft-core/src/array/ops/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use arrow2::{array::PrimitiveArray, compute::arithmetics::basic};

use crate::{
array::{DataArray, FixedSizeListArray},
datatypes::DataType,
datatypes::{DaftNumericType, Field, Float64Array, Int64Array, Utf8Array},
kernels::utf8::add_utf8_arrays,
DataType, Series,
series::Series,
};

use common_error::{DaftError, DaftResult};
Expand Down
4 changes: 2 additions & 2 deletions src/daft-core/src/array/ops/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ where
));
DataArray::new(field.clone(), cat_array)
}
crate::DataType::Utf8 => {
crate::datatypes::DataType::Utf8 => {
let cat_array = utf8_concat(arrow_arrays.as_slice())?;
DataArray::new(field.clone(), cat_array)
}
crate::DataType::Binary => {
crate::datatypes::DataType::Binary => {
let cat_array = binary_concat(arrow_arrays.as_slice())?;
DataArray::new(field.clone(), cat_array)
}
Expand Down
3 changes: 2 additions & 1 deletion src/daft-core/src/array/ops/concat_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ mod test {

use crate::{
array::{ops::DaftConcatAggable, ListArray},
datatypes::DataType,
datatypes::{Field, Int64Array},
DataType, IntoSeries,
series::IntoSeries,
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/ops/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
growable::{Growable, GrowableArray},
DataArray, FixedSizeListArray, ListArray, StructArray,
},
datatypes::DataType,
datatypes::{BooleanArray, DaftArrayType, DaftArrowBackedType},
DataType,
};
use arrow2::bitmap::utils::SlicesIterator;
use common_error::DaftResult;
Expand Down
3 changes: 2 additions & 1 deletion src/daft-core/src/array/ops/from_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use common_error::{DaftError, DaftResult};

use crate::{
array::{DataArray, FixedSizeListArray, ListArray, StructArray},
datatypes::DataType,
datatypes::{
logical::LogicalArray, DaftDataType, DaftLogicalType, DaftPhysicalType, Field, FieldRef,
},
DataType, Series,
series::Series,
};

/// Arrays that implement [`FromArrow`] can be instantiated from a Box<dyn arrow2::array::Array>
Expand Down
5 changes: 2 additions & 3 deletions src/daft-core/src/array/ops/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
datatypes::{
logical::LogicalArray, DaftDataType, DaftLogicalType, DaftPhysicalType, DataType, Field,
},
Series,
series::Series,
};

pub trait FullNull {
Expand Down Expand Up @@ -200,8 +200,7 @@ mod tests {

use crate::{
array::{ops::full::FullNull, FixedSizeListArray, StructArray},
datatypes::Field,
DataType,
datatypes::{DataType, Field},
};

#[test]
Expand Down
5 changes: 3 additions & 2 deletions src/daft-core/src/array/ops/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
BinaryArray, BooleanArray, DaftLogicalType, DaftNumericType, ExtensionArray,
FixedSizeBinaryArray, NullArray, Utf8Array,
},
Series,
series::Series,
};

use super::as_arrow::AsArrow;
Expand Down Expand Up @@ -174,8 +174,9 @@ mod tests {

use crate::{
array::FixedSizeListArray,
datatypes::DataType,
datatypes::{Field, Int32Array},
DataType, IntoSeries,
series::IntoSeries,
};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/daft-core/src/array/ops/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
Utf8Array,
},
kernels,
series::Series,
utils::arrow::arrow_bitmap_and_helper,
Series,
};

use arrow2::types::Index;
Expand Down Expand Up @@ -301,7 +301,7 @@ impl DateArray {

impl TimeArray {
pub fn murmur3_32(&self) -> DaftResult<Int32Array> {
let us = self.cast(&crate::DataType::Time(
let us = self.cast(&crate::datatypes::DataType::Time(
crate::datatypes::TimeUnit::Microseconds,
))?;
us.time()?.physical.murmur3_32()
Expand All @@ -310,7 +310,7 @@ impl TimeArray {

impl TimestampArray {
pub fn murmur3_32(&self) -> DaftResult<Int32Array> {
let us = self.cast(&crate::DataType::Timestamp(
let us = self.cast(&crate::datatypes::DataType::Timestamp(
crate::datatypes::TimeUnit::Microseconds,
None,
))?;
Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/ops/hll_sketch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
array::ops::as_arrow::AsArrow,
datatypes::DataType,
datatypes::{FixedSizeBinaryArray, UInt64Array},
DataType,
};
use hyperloglog::{HyperLogLog, NUM_REGISTERS};

Expand Down
2 changes: 1 addition & 1 deletion src/daft-core/src/array/ops/if_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::array::growable::{Growable, GrowableArray};
use crate::array::ops::full::FullNull;
use crate::array::{DataArray, FixedSizeListArray, ListArray, StructArray};
use crate::datatypes::{BooleanArray, DaftPhysicalType};
use crate::{DataType, IntoSeries, Series};
use crate::{datatypes::DataType, series::IntoSeries, series::Series};
use arrow2::array::Array;
use common_error::DaftResult;

Expand Down
Loading

0 comments on commit 178f5f0

Please sign in to comment.