Skip to content

Commit 51cba1a

Browse files
committed
CastFn
Signed-off-by: Nicholas Gates <[email protected]>
1 parent d7c6afa commit 51cba1a

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

vortex-array/src/expr/expression.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,6 @@ impl Expression {
9191
Ok(this)
9292
}
9393

94-
/// Creates a new expression with the given encoding, metadata, and children.
95-
///
96-
/// # Safety
97-
///
98-
/// The caller must ensure that the provided `encoding` is compatible with the
99-
/// `metadata` and `children`. Failure to do so may lead to undefined behavior
100-
/// when the expression is used.
101-
pub(super) unsafe fn new_unchecked_erased(
102-
vtable: ExprVTable,
103-
data: Arc<dyn Any + Send + Sync>,
104-
children: Arc<[Expression]>,
105-
) -> Self {
106-
Self {
107-
vtable,
108-
data,
109-
children,
110-
}
111-
}
112-
11394
/// Returns if the expression is an instance of the given vtable.
11495
pub fn is<V: VTable>(&self) -> bool {
11596
self.vtable.is::<V>()

vortex-array/src/expr/functions/vtable.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,16 @@ impl fmt::Display for EmptyOptions {
331331
Ok(())
332332
}
333333
}
334+
335+
pub trait ScalarFnVTableExt: VTable {
336+
/// Creates a new ScalarFn instance with the given options.
337+
fn new(self, options: Self::Options) -> ScalarFn {
338+
ScalarFn::new(self, options)
339+
}
340+
341+
/// Creates a new ScalarFn instance with the given options from a 'static vtable.
342+
fn new_static(&'static self, options: Self::Options) -> ScalarFn {
343+
ScalarFn::new_static(self, options)
344+
}
345+
}
346+
impl<V: VTable> ScalarFnVTableExt for V {}

vortex-array/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub mod optimizer;
4040
mod partial_ord;
4141
pub mod patches;
4242
pub mod pipeline;
43-
mod scalar_fns;
43+
pub mod scalar_fns;
4444
pub mod search_sorted;
4545
pub mod serde;
4646
pub mod session;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use crate::optimizer::rules::ArrayReduceRule;
5+
6+
pub struct CastReduce;
7+
impl ArrayReduceRule {}

vortex-array/src/scalar_fns/cast/mod.rs

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

4+
mod array;
5+
46
use crate::expr::functions::{ArgName, Arity, ExecutionCtx, FunctionId, NullHandling, VTable};
57
use crate::expr::stats::Stat;
68
use crate::expr::{Expression, StatsCatalog};
7-
use crate::scalar_fns::BuiltinFunctions;
9+
use crate::scalar_fns::BuiltinScalarFns;
810
use prost::Message;
911
use vortex_dtype::DType;
1012
use vortex_error::{vortex_err, vortex_panic, VortexExpect, VortexResult};
1113
use vortex_proto::expr as pb;
1214
use vortex_vector::Datum;
1315

1416
pub struct CastFn;
15-
1617
impl VTable for CastFn {
1718
type Options = DType;
1819

vortex-array/src/scalar_fns/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ use vortex_error::VortexResult;
1919
mod cast;
2020

2121
/// A collection of built-in scalar functions that can be applied to expressions or arrays.
22-
pub trait BuiltinFunctions: Sized {
22+
pub trait BuiltinScalarFns: Sized {
2323
/// Cast to the given data type.
2424
fn cast(&self, dtype: DType) -> VortexResult<Self>;
2525
}
2626

27-
impl BuiltinFunctions for Expression {
27+
impl BuiltinScalarFns for Expression {
2828
fn cast(&self, dtype: DType) -> VortexResult<Expression> {
2929
CastFn.try_new_expr(dtype, [self.clone()])
3030
}
3131
}
3232

33-
impl BuiltinFunctions for ArrayRef {
33+
impl BuiltinScalarFns for ArrayRef {
3434
fn cast(&self, dtype: DType) -> VortexResult<Self> {
3535
CastFn.try_new_array(self.len(), dtype, [self.clone()])
3636
}

0 commit comments

Comments
 (0)