Skip to content

Commit 9eb4c9d

Browse files
committed
Vector Casting
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 872bb62 commit 9eb4c9d

File tree

7 files changed

+26
-30
lines changed

7 files changed

+26
-30
lines changed

vortex-array/src/expr/exprs/cast/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
use std::fmt::Formatter;
55
use std::ops::Deref;
66

7-
use crate::compute::cast as compute_cast;
8-
use crate::expr::expression::Expression;
9-
use crate::expr::{ChildName, ExprId, ExpressionView, StatsCatalog, VTable, VTableExt};
10-
use crate::stats::Stat;
11-
use crate::ArrayRef;
127
use prost::Message;
138
use vortex_dtype::DType;
149
use vortex_error::{vortex_bail, vortex_err, VortexExpect, VortexResult};
1510
use vortex_proto::expr as pb;
1611
use vortex_vector::Vector;
1712

13+
use crate::compute::cast as compute_cast;
14+
use crate::expr::expression::Expression;
15+
use crate::expr::{ChildName, ExprId, ExpressionView, StatsCatalog, VTable, VTableExt};
16+
use crate::stats::Stat;
17+
use crate::ArrayRef;
18+
1819
/// A cast expression that converts values to a target data type.
1920
pub struct Cast;
2021

@@ -130,15 +131,6 @@ impl VTable for Cast {
130131
}
131132
}
132133

133-
/// A trait that defines the compute function for performing a cast.
134-
///
135-
/// The `try_cast` method attempts to convert the vector to the specified data type,
136-
/// returning a `VortexResult` that contains the casted vector or an error if the
137-
/// cast operation fails.
138-
trait VectorCast {
139-
fn try_cast(self, dtype: &DType) -> VortexResult<Vector>;
140-
}
141-
142134
/// Creates an expression that casts values to a target data type.
143135
///
144136
/// Converts the input expression's values to the specified target type.

vortex-array/src/expr/exprs/select/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ pub mod transform;
55

66
use std::fmt::{Display, Formatter};
77

8-
use crate::expr::expression::Expression;
9-
use crate::expr::field::DisplayFieldNames;
10-
use crate::expr::{ChildName, ExprId, ExpressionView, VTable, VTableExt};
11-
use crate::{ArrayRef, IntoArray, ToCanonical};
128
use itertools::Itertools;
139
use prost::Message;
1410
use vortex_dtype::{DType, FieldNames};
15-
use vortex_error::{vortex_bail, vortex_err, VortexExpect, VortexResult};
11+
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_err};
1612
use vortex_proto::expr::select_opts::Opts;
1713
use vortex_proto::expr::{FieldNames as ProtoFieldNames, SelectOpts};
1814
use vortex_vector::Vector;
1915

16+
use crate::expr::expression::Expression;
17+
use crate::expr::field::DisplayFieldNames;
18+
use crate::expr::{ChildName, ExprId, ExpressionView, VTable, VTableExt};
19+
use crate::{ArrayRef, IntoArray, ToCanonical};
20+
2021
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2122
pub enum FieldSelection {
2223
Include(FieldNames),

vortex-compute/src/cast/bool.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use crate::cast::Cast;
54
use num_traits::{One, Zero};
65
use vortex_buffer::Buffer;
7-
use vortex_dtype::{match_each_native_ptype, DType};
8-
use vortex_error::{vortex_bail, VortexResult};
6+
use vortex_dtype::{DType, match_each_native_ptype};
7+
use vortex_error::{VortexResult, vortex_bail};
98
use vortex_vector::bool::BoolVector;
109
use vortex_vector::null::NullVector;
1110
use vortex_vector::primitive::PVector;
1211
use vortex_vector::{Vector, VectorOps};
1312

13+
use crate::cast::Cast;
14+
1415
impl Cast for BoolVector {
1516
fn cast(&self, dtype: &DType) -> VortexResult<Vector> {
1617
match dtype {

vortex-compute/src/cast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod null;
88
mod pvector;
99

1010
use vortex_dtype::DType;
11-
use vortex_error::{vortex_bail, VortexResult};
11+
use vortex_error::{VortexResult, vortex_bail};
1212
use vortex_vector::Vector;
1313

1414
/// Trait for casting vectors to different data types.

vortex-compute/src/cast/null.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use crate::cast::Cast;
54
use vortex_dtype::DType;
6-
use vortex_error::{vortex_bail, VortexResult};
5+
use vortex_error::{VortexResult, vortex_bail};
76
use vortex_vector::null::NullVector;
87
use vortex_vector::{Vector, VectorMut, VectorMutOps, VectorOps};
98

9+
use crate::cast::Cast;
10+
1011
impl Cast for NullVector {
1112
fn cast(&self, dtype: &DType) -> VortexResult<Vector> {
1213
if dtype.is_nullable() {
1314
// We can create an all-null vector of _any_ type.
1415
let mut vec = VectorMut::with_capacity(dtype, self.len());
1516
vec.append_nulls(self.len());
16-
Ok(vec.freeze().into())
17+
Ok(vec.freeze())
1718
} else {
1819
vortex_bail!("Cannot cast NullVector to non-nullable type {}", dtype);
1920
}

vortex-compute/src/cast/pvector.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4-
use crate::cast::Cast;
54
use vortex_dtype::{DType, NativePType};
6-
use vortex_error::{vortex_bail, VortexResult};
5+
use vortex_error::{VortexResult, vortex_bail};
76
use vortex_vector::null::NullVector;
87
use vortex_vector::primitive::{PVector, PrimitiveVector};
9-
use vortex_vector::{match_each_pvector, Vector, VectorOps};
8+
use vortex_vector::{Vector, VectorOps, match_each_pvector};
9+
10+
use crate::cast::Cast;
1011

1112
impl Cast for PrimitiveVector {
1213
fn cast(&self, dtype: &DType) -> VortexResult<Vector> {

vortex-vector/src/primitive/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::RangeBounds;
88

99
use vortex_buffer::Buffer;
1010
use vortex_dtype::NativePType;
11-
use vortex_error::{vortex_ensure, VortexExpect, VortexResult};
11+
use vortex_error::{VortexExpect, VortexResult, vortex_ensure};
1212
use vortex_mask::Mask;
1313

1414
use crate::primitive::{PScalar, PVectorMut};

0 commit comments

Comments
 (0)