Skip to content

Commit 7d1091c

Browse files
committed
CR comments
1 parent 71bbc82 commit 7d1091c

File tree

11 files changed

+82
-53
lines changed

11 files changed

+82
-53
lines changed

encodings/datetime-parts/src/compute/cast.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ use vortex_error::{VortexResult, vortex_bail};
99
use crate::{DateTimePartsArray, DateTimePartsVTable};
1010

1111
impl CastKernel for DateTimePartsVTable {
12-
fn cast(&self, array: &DateTimePartsArray, dtype: &DType) -> VortexResult<ArrayRef> {
12+
fn cast(&self, array: &DateTimePartsArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1313
if !array.dtype().eq_ignore_nullability(dtype) {
1414
vortex_bail!("cannot cast from {} to {}", array.dtype(), dtype);
1515
};
1616

17-
Ok(DateTimePartsArray::try_new(
18-
dtype.clone(),
19-
cast(
20-
array.days().as_ref(),
21-
&array.days().dtype().with_nullability(dtype.nullability()),
22-
)?,
23-
array.seconds().clone(),
24-
array.subseconds().clone(),
25-
)?
26-
.into_array())
17+
Ok(Some(
18+
DateTimePartsArray::try_new(
19+
dtype.clone(),
20+
cast(
21+
array.days().as_ref(),
22+
&array.days().dtype().with_nullability(dtype.nullability()),
23+
)?,
24+
array.seconds().clone(),
25+
array.subseconds().clone(),
26+
)?
27+
.into_array(),
28+
))
2729
}
2830
}
2931

vortex-array/src/arrays/bool/compute/cast.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use vortex_dtype::DType;
5-
use vortex_error::{VortexResult, vortex_bail};
5+
use vortex_error::VortexResult;
66

77
use crate::array::ArrayRef;
88
use crate::arrays::{BoolArray, BoolVTable};
@@ -11,14 +11,16 @@ use crate::register_kernel;
1111
use crate::vtable::ValidityHelper;
1212

1313
impl CastKernel for BoolVTable {
14-
fn cast(&self, array: &BoolArray, dtype: &DType) -> VortexResult<ArrayRef> {
14+
fn cast(&self, array: &BoolArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1515
if !matches!(dtype, DType::Bool(_)) {
16-
vortex_bail!("Cannot cast {} to {}", array.dtype(), dtype);
16+
return Ok(None);
1717
}
1818

1919
let new_nullability = dtype.nullability();
2020
let new_validity = array.validity().clone().cast_nullability(new_nullability)?;
21-
Ok(BoolArray::new(array.boolean_buffer().clone(), new_validity).to_array())
21+
Ok(Some(
22+
BoolArray::new(array.boolean_buffer().clone(), new_validity).to_array(),
23+
))
2224
}
2325
}
2426

vortex-array/src/arrays/chunked/compute/cast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use crate::compute::{CastKernel, CastKernelAdapter, cast};
99
use crate::{ArrayRef, IntoArray, register_kernel};
1010

1111
impl CastKernel for ChunkedVTable {
12-
fn cast(&self, array: &ChunkedArray, dtype: &DType) -> VortexResult<ArrayRef> {
12+
fn cast(&self, array: &ChunkedArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1313
let mut cast_chunks = Vec::new();
1414
for chunk in array.chunks() {
1515
cast_chunks.push(cast(chunk, dtype)?);
1616
}
1717

18-
Ok(ChunkedArray::new_unchecked(cast_chunks, dtype.clone()).into_array())
18+
Ok(Some(
19+
ChunkedArray::new_unchecked(cast_chunks, dtype.clone()).into_array(),
20+
))
1921
}
2022
}
2123

vortex-array/src/arrays/constant/compute/cast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ use crate::compute::{CastKernel, CastKernelAdapter};
99
use crate::{ArrayRef, IntoArray, register_kernel};
1010

1111
impl CastKernel for ConstantVTable {
12-
fn cast(&self, array: &ConstantArray, dtype: &DType) -> VortexResult<ArrayRef> {
13-
Ok(ConstantArray::new(array.scalar().cast(dtype)?, array.len()).into_array())
12+
fn cast(&self, array: &ConstantArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
13+
Ok(Some(
14+
ConstantArray::new(array.scalar().cast(dtype)?, array.len()).into_array(),
15+
))
1416
}
1517
}
1618

vortex-array/src/arrays/extension/compute/cast.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use crate::compute::{CastKernel, CastKernelAdapter, cast};
1111
use crate::{ArrayRef, IntoArray, register_kernel};
1212

1313
impl CastKernel for ExtensionVTable {
14-
fn cast(&self, array: &ExtensionArray, dtype: &DType) -> vortex_error::VortexResult<ArrayRef> {
14+
fn cast(
15+
&self,
16+
array: &ExtensionArray,
17+
dtype: &DType,
18+
) -> vortex_error::VortexResult<Option<ArrayRef>> {
1519
if !array.dtype().eq_ignore_nullability(dtype) {
1620
vortex_bail!("Cannot cast {} to {}", array.dtype(), dtype);
1721
}
@@ -39,15 +43,23 @@ impl CastKernel for ExtensionVTable {
3943
"invalid cast from nullable to non-nullable, since source array actually contains nulls"
4044
);
4145
};
42-
let new_storage = cast(storage_array.as_ref(), &new_storage_dtype)?;
46+
let new_storage = match cast(storage_array.as_ref(), &new_storage_dtype) {
47+
Ok(arr) => arr,
48+
Err(e) => {
49+
log::warn!("Failed to cast storage array: {e}");
50+
return Ok(None);
51+
}
52+
};
4353

4454
let new_ext_dtype = ExtDType::new(
4555
ext_dtype.id().clone(),
4656
Arc::new(new_storage_dtype.clone()),
4757
ext_dtype.metadata().cloned(),
4858
);
4959

50-
Ok(ExtensionArray::new(new_ext_dtype.into(), new_storage).into_array())
60+
Ok(Some(
61+
ExtensionArray::new(new_ext_dtype.into(), new_storage).into_array(),
62+
))
5163
}
5264
}
5365

vortex-array/src/arrays/list/compute/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::vtable::ValidityHelper;
1010
use crate::{ArrayRef, register_kernel};
1111

1212
impl CastKernel for ListVTable {
13-
fn cast(&self, array: &Self::Array, dtype: &DType) -> VortexResult<ArrayRef> {
13+
fn cast(&self, array: &Self::Array, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1414
let Some(target_element_type) = dtype.as_list_element() else {
1515
vortex_bail!("cannot cast {} to {}", array.dtype(), dtype);
1616
};
@@ -25,7 +25,7 @@ impl CastKernel for ListVTable {
2525
array.offsets().clone(),
2626
validity,
2727
)
28-
.map(|a| a.to_array())
28+
.map(|a| Some(a.to_array()))
2929
}
3030
}
3131

vortex-array/src/arrays/primitive/compute/cast.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::vtable::ValidityHelper;
1313
use crate::{ArrayRef, IntoArray, register_kernel};
1414

1515
impl CastKernel for PrimitiveVTable {
16-
fn cast(&self, array: &PrimitiveArray, dtype: &DType) -> VortexResult<ArrayRef> {
16+
fn cast(&self, array: &PrimitiveArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1717
let DType::Primitive(new_ptype, new_nullability) = dtype else {
1818
vortex_bail!(MismatchedTypes: "primitive type", dtype);
1919
};
@@ -36,17 +36,21 @@ impl CastKernel for PrimitiveVTable {
3636

3737
// If the bit width is the same, we can short-circuit and simply update the validity
3838
if array.ptype() == new_ptype {
39-
return Ok(PrimitiveArray::from_byte_buffer(
40-
array.byte_buffer().clone(),
41-
array.ptype(),
42-
new_validity,
43-
)
44-
.into_array());
39+
return Ok(Some(
40+
PrimitiveArray::from_byte_buffer(
41+
array.byte_buffer().clone(),
42+
array.ptype(),
43+
new_validity,
44+
)
45+
.into_array(),
46+
));
4547
}
4648

4749
// Otherwise, we need to cast the values one-by-one
4850
match_each_native_ptype!(new_ptype, |T| {
49-
Ok(PrimitiveArray::new(cast::<T>(array)?, new_validity).into_array())
51+
Ok(Some(
52+
PrimitiveArray::new(cast::<T>(array)?, new_validity).into_array(),
53+
))
5054
})
5155
}
5256
}

vortex-array/src/arrays/struct_/compute/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use crate::vtable::ValidityHelper;
1111
use crate::{ArrayRef, IntoArray, register_kernel};
1212

1313
impl CastKernel for StructVTable {
14-
fn cast(&self, array: &StructArray, dtype: &DType) -> VortexResult<ArrayRef> {
14+
fn cast(&self, array: &StructArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1515
let Some(target_sdtype) = dtype.as_struct() else {
16-
vortex_bail!("cannot cast {} to {}", array.dtype(), dtype);
16+
return Ok(None);
1717
};
1818

1919
let source_sdtype = array
@@ -41,7 +41,7 @@ impl CastKernel for StructVTable {
4141
array.len(),
4242
validity,
4343
)
44-
.map(|a| a.into_array())
44+
.map(|a| Some(a.into_array()))
4545
}
4646
}
4747

vortex-array/src/arrays/varbin/compute/cast.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ use crate::vtable::ValidityHelper;
1010
use crate::{ArrayRef, IntoArray, register_kernel};
1111

1212
impl CastKernel for VarBinVTable {
13-
fn cast(&self, array: &VarBinArray, dtype: &DType) -> VortexResult<ArrayRef> {
13+
fn cast(&self, array: &VarBinArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1414
if !array.dtype().eq_ignore_nullability(dtype) {
1515
vortex_bail!("Cannot cast {} to {}", array.dtype(), dtype);
1616
}
1717

1818
let new_nullability = dtype.nullability();
1919
let new_validity = array.validity().clone().cast_nullability(new_nullability)?;
2020
let new_dtype = array.dtype().with_nullability(new_nullability);
21-
Ok(VarBinArray::try_new(
22-
array.offsets().clone(),
23-
array.bytes().clone(),
24-
new_dtype,
25-
new_validity,
26-
)?
27-
.into_array())
21+
Ok(Some(
22+
VarBinArray::try_new(
23+
array.offsets().clone(),
24+
array.bytes().clone(),
25+
new_dtype,
26+
new_validity,
27+
)?
28+
.into_array(),
29+
))
2830
}
2931
}
3032

vortex-array/src/arrays/varbinview/compute/cast.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ use crate::vtable::ValidityHelper;
1010
use crate::{ArrayRef, IntoArray, register_kernel};
1111

1212
impl CastKernel for VarBinViewVTable {
13-
fn cast(&self, array: &VarBinViewArray, dtype: &DType) -> VortexResult<ArrayRef> {
13+
fn cast(&self, array: &VarBinViewArray, dtype: &DType) -> VortexResult<Option<ArrayRef>> {
1414
if !array.dtype().eq_ignore_nullability(dtype) {
1515
vortex_bail!("Cannot cast {} to {}", array.dtype(), dtype);
1616
}
1717

1818
let new_nullability = dtype.nullability();
1919
let new_validity = array.validity().clone().cast_nullability(new_nullability)?;
2020
let new_dtype = array.dtype().with_nullability(new_nullability);
21-
Ok(VarBinViewArray::try_new(
22-
array.views().clone(),
23-
array.buffers().to_vec(),
24-
new_dtype,
25-
new_validity,
26-
)?
27-
.into_array())
21+
Ok(Some(
22+
VarBinViewArray::try_new(
23+
array.views().clone(),
24+
array.buffers().to_vec(),
25+
new_dtype,
26+
new_validity,
27+
)?
28+
.into_array(),
29+
))
2830
}
2931
}
3032

0 commit comments

Comments
 (0)