Skip to content

Commit ec1d423

Browse files
committed
Address
Signed-off-by: Nicholas Gates <[email protected]>
1 parent d99cb3a commit ec1d423

4 files changed

Lines changed: 78 additions & 16 deletions

File tree

‎vortex-array/src/aggregate_fn/fns/bounded_max/mod.rs‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,17 @@ impl AggregateFnVTable for BoundedMax {
126126
options: &Self::Options,
127127
requested: &AggregateFnRef,
128128
) -> AggregateFnSatisfaction {
129-
if requested
130-
.as_opt::<Self>()
131-
.is_some_and(|other| other == options)
132-
{
133-
return AggregateFnSatisfaction::Exact;
129+
if let Some(other) = requested.as_opt::<Self>() {
130+
return if other == options {
131+
AggregateFnSatisfaction::Exact
132+
} else if options.max_bytes >= other.max_bytes {
133+
AggregateFnSatisfaction::Approximate
134+
} else {
135+
AggregateFnSatisfaction::No
136+
};
134137
}
135138

136-
if requested.is::<Self>() || requested.is::<Max>() {
139+
if requested.is::<Max>() {
137140
AggregateFnSatisfaction::Approximate
138141
} else {
139142
AggregateFnSatisfaction::No
@@ -397,19 +400,30 @@ mod tests {
397400
let same = BoundedMax.bind(BoundedMaxOptions {
398401
max_bytes: max_bytes(5),
399402
});
400-
let other_bounded = BoundedMax.bind(BoundedMaxOptions {
403+
let looser_bounded = BoundedMax.bind(BoundedMaxOptions {
404+
max_bytes: max_bytes(4),
405+
});
406+
let tighter_bounded = BoundedMax.bind(BoundedMaxOptions {
401407
max_bytes: max_bytes(6),
402408
});
403409

404410
assert_eq!(stored.can_satisfy(&same), AggregateFnSatisfaction::Exact);
405411
assert_eq!(
406-
stored.can_satisfy(&other_bounded),
412+
stored.can_satisfy(&looser_bounded),
407413
AggregateFnSatisfaction::Approximate
408414
);
415+
assert_eq!(
416+
stored.can_satisfy(&tighter_bounded),
417+
AggregateFnSatisfaction::No
418+
);
409419
assert_eq!(
410420
stored.can_satisfy(&Max.bind(EmptyOptions)),
411421
AggregateFnSatisfaction::Approximate
412422
);
423+
assert_eq!(
424+
Max.bind(EmptyOptions).can_satisfy(&stored),
425+
AggregateFnSatisfaction::Approximate
426+
);
413427
assert_eq!(
414428
stored.can_satisfy(&Min.bind(EmptyOptions)),
415429
AggregateFnSatisfaction::No

‎vortex-array/src/aggregate_fn/fns/bounded_min/mod.rs‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,17 @@ impl AggregateFnVTable for BoundedMin {
116116
options: &Self::Options,
117117
requested: &AggregateFnRef,
118118
) -> AggregateFnSatisfaction {
119-
if requested
120-
.as_opt::<Self>()
121-
.is_some_and(|other| other == options)
122-
{
123-
return AggregateFnSatisfaction::Exact;
119+
if let Some(other) = requested.as_opt::<Self>() {
120+
return if other == options {
121+
AggregateFnSatisfaction::Exact
122+
} else if options.max_bytes >= other.max_bytes {
123+
AggregateFnSatisfaction::Approximate
124+
} else {
125+
AggregateFnSatisfaction::No
126+
};
124127
}
125128

126-
if requested.is::<Self>() || requested.is::<Min>() {
129+
if requested.is::<Min>() {
127130
AggregateFnSatisfaction::Approximate
128131
} else {
129132
AggregateFnSatisfaction::No
@@ -331,19 +334,30 @@ mod tests {
331334
let same = BoundedMin.bind(BoundedMinOptions {
332335
max_bytes: max_bytes(5),
333336
});
334-
let other_bounded = BoundedMin.bind(BoundedMinOptions {
337+
let looser_bounded = BoundedMin.bind(BoundedMinOptions {
338+
max_bytes: max_bytes(4),
339+
});
340+
let tighter_bounded = BoundedMin.bind(BoundedMinOptions {
335341
max_bytes: max_bytes(6),
336342
});
337343

338344
assert_eq!(stored.can_satisfy(&same), AggregateFnSatisfaction::Exact);
339345
assert_eq!(
340-
stored.can_satisfy(&other_bounded),
346+
stored.can_satisfy(&looser_bounded),
341347
AggregateFnSatisfaction::Approximate
342348
);
349+
assert_eq!(
350+
stored.can_satisfy(&tighter_bounded),
351+
AggregateFnSatisfaction::No
352+
);
343353
assert_eq!(
344354
stored.can_satisfy(&Min.bind(EmptyOptions)),
345355
AggregateFnSatisfaction::Approximate
346356
);
357+
assert_eq!(
358+
Min.bind(EmptyOptions).can_satisfy(&stored),
359+
AggregateFnSatisfaction::Approximate
360+
);
347361
assert_eq!(
348362
stored.can_satisfy(&Max.bind(EmptyOptions)),
349363
AggregateFnSatisfaction::No

‎vortex-array/src/aggregate_fn/fns/max/mod.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use crate::Columnar;
99
use crate::ExecutionCtx;
1010
use crate::IntoArray;
1111
use crate::aggregate_fn::AggregateFnId;
12+
use crate::aggregate_fn::AggregateFnRef;
13+
use crate::aggregate_fn::AggregateFnSatisfaction;
1214
use crate::aggregate_fn::AggregateFnVTable;
1315
use crate::aggregate_fn::EmptyOptions;
16+
use crate::aggregate_fn::fns::bounded_max::BoundedMax;
1417
use crate::aggregate_fn::fns::min_max::MinMax;
1518
use crate::aggregate_fn::fns::min_max::min_max;
1619
use crate::dtype::DType;
@@ -58,6 +61,20 @@ impl AggregateFnVTable for Max {
5861
.map(|_| input_dtype.as_nullable())
5962
}
6063

64+
fn can_satisfy(
65+
&self,
66+
_options: &Self::Options,
67+
requested: &AggregateFnRef,
68+
) -> AggregateFnSatisfaction {
69+
if requested.is::<Self>() {
70+
AggregateFnSatisfaction::Exact
71+
} else if requested.is::<BoundedMax>() {
72+
AggregateFnSatisfaction::Approximate
73+
} else {
74+
AggregateFnSatisfaction::No
75+
}
76+
}
77+
6178
fn partial_dtype(&self, options: &Self::Options, input_dtype: &DType) -> Option<DType> {
6279
self.return_dtype(options, input_dtype)
6380
}

‎vortex-array/src/aggregate_fn/fns/min/mod.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use crate::Columnar;
99
use crate::ExecutionCtx;
1010
use crate::IntoArray;
1111
use crate::aggregate_fn::AggregateFnId;
12+
use crate::aggregate_fn::AggregateFnRef;
13+
use crate::aggregate_fn::AggregateFnSatisfaction;
1214
use crate::aggregate_fn::AggregateFnVTable;
1315
use crate::aggregate_fn::EmptyOptions;
16+
use crate::aggregate_fn::fns::bounded_min::BoundedMin;
1417
use crate::aggregate_fn::fns::min_max::MinMax;
1518
use crate::aggregate_fn::fns::min_max::min_max;
1619
use crate::dtype::DType;
@@ -58,6 +61,20 @@ impl AggregateFnVTable for Min {
5861
.map(|_| input_dtype.as_nullable())
5962
}
6063

64+
fn can_satisfy(
65+
&self,
66+
_options: &Self::Options,
67+
requested: &AggregateFnRef,
68+
) -> AggregateFnSatisfaction {
69+
if requested.is::<Self>() {
70+
AggregateFnSatisfaction::Exact
71+
} else if requested.is::<BoundedMin>() {
72+
AggregateFnSatisfaction::Approximate
73+
} else {
74+
AggregateFnSatisfaction::No
75+
}
76+
}
77+
6178
fn partial_dtype(&self, options: &Self::Options, input_dtype: &DType) -> Option<DType> {
6279
self.return_dtype(options, input_dtype)
6380
}

0 commit comments

Comments
 (0)