Skip to content

Commit 74a31af

Browse files
authored
Type Coercion (#6960)
This allows Vortex expressions to be typed in contexts that currently don't have their own logical planner, for example expressions passed into PyVortex. --------- Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent da4c196 commit 74a31af

18 files changed

Lines changed: 1119 additions & 3 deletions

File tree

vortex-array/public-api.lock

Lines changed: 173 additions & 1 deletion
Large diffs are not rendered by default.

vortex-array/src/aggregate_fn/erased.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ impl AggregateFnRef {
7575
AggregateFnOptions { inner: &*self.0 }
7676
}
7777

78+
/// Coerce the input type for this aggregate function.
79+
pub fn coerce_args(&self, input_dtype: &DType) -> VortexResult<DType> {
80+
self.0.coerce_args(input_dtype)
81+
}
82+
7883
/// Compute the return [`DType`] per group given the input element type.
7984
pub fn return_dtype(&self, input_dtype: &DType) -> VortexResult<DType> {
8085
self.0.return_dtype(input_dtype)

vortex-array/src/aggregate_fn/typed.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub(super) trait DynAggregateFn: 'static + Send + Sync + super::sealed::Sealed {
3939
fn id(&self) -> AggregateFnId;
4040
fn options_any(&self) -> &dyn Any;
4141

42+
fn coerce_args(&self, input_dtype: &DType) -> VortexResult<DType>;
4243
fn return_dtype(&self, input_dtype: &DType) -> VortexResult<DType>;
4344
fn state_dtype(&self, input_dtype: &DType) -> VortexResult<DType>;
4445
fn accumulator(
@@ -84,6 +85,10 @@ impl<V: AggregateFnVTable> DynAggregateFn for AggregateFnInner<V> {
8485
&self.options
8586
}
8687

88+
fn coerce_args(&self, input_dtype: &DType) -> VortexResult<DType> {
89+
V::coerce_args(&self.vtable, &self.options, input_dtype)
90+
}
91+
8792
fn return_dtype(&self, input_dtype: &DType) -> VortexResult<DType> {
8893
V::return_dtype(&self.vtable, &self.options, input_dtype)
8994
}

vortex-array/src/aggregate_fn/vtable.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ pub trait AggregateFnVTable: 'static + Sized + Clone + Send + Sync {
6060
vortex_bail!("Aggregate function {} is not deserializable", self.id());
6161
}
6262

63+
/// Coerce the input type for this aggregate function.
64+
///
65+
/// This is optionally used by Vortex users when performing type coercion over a Vortex
66+
/// expression. The default implementation returns the input type unchanged.
67+
fn coerce_args(&self, options: &Self::Options, input_dtype: &DType) -> VortexResult<DType> {
68+
let _ = options;
69+
Ok(input_dtype.clone())
70+
}
71+
6372
/// The return [`DType`] of the aggregate.
6473
fn return_dtype(&self, options: &Self::Options, input_dtype: &DType) -> VortexResult<DType>;
6574

0 commit comments

Comments
 (0)