Skip to content

Commit a36f976

Browse files
committed
fixups
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 2191aa0 commit a36f976

9 files changed

Lines changed: 62 additions & 58 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn take_datetime_parts(
6565
.seconds()
6666
.statistics()
6767
.get(Stat::Min)
68-
.map(|s| s.into_inner())
68+
.into_inner()
6969
.unwrap_or_else(|| Scalar::primitive(0i64, Nullability::NonNullable))
7070
.cast(array.seconds().dtype())?;
7171
let taken_seconds = taken_seconds.fill_null(seconds_fill)?;
@@ -74,7 +74,7 @@ fn take_datetime_parts(
7474
.subseconds()
7575
.statistics()
7676
.get(Stat::Min)
77-
.map(|s| s.into_inner())
77+
.into_inner()
7878
.unwrap_or_else(|| Scalar::primitive(0i64, Nullability::NonNullable))
7979
.cast(array.subseconds().dtype())?;
8080
let taken_subseconds = taken_subseconds.fill_null(subseconds_fill)?;

vortex-array/src/expr/stats/precision.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ impl<T> Precision<Option<T>> {
5050
}
5151

5252
impl<T, E> Precision<Result<T, E>> {
53+
/// Transpose a `Precision<Result<T, E>>` into a `Result<Precision<T>, E>`.
5354
pub fn transpose(self) -> Result<Precision<T>, E> {
54-
todo!()
55+
match self {
56+
Self::Exact(value) => value.map(Precision::Exact),
57+
Self::Inexact(value) => value.map(Precision::Inexact),
58+
Self::Absent => Ok(Precision::Absent),
59+
}
5560
}
5661
}
5762

vortex-datafusion/src/convert/stats.rs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,52 @@ pub(crate) fn stats_set_to_df(
2727
// TODO(connor): There's a lot that can go wrong here, should probably handle this
2828
// more gracefully...
2929
// Find the min statistic.
30-
let min = stats_set.get(Stat::Min).and_then(|pstat_val| {
31-
pstat_val
32-
.map(|stat_val| {
33-
Scalar::try_new(
34-
Stat::Min
35-
.dtype(dtype)
36-
.vortex_expect("must have a valid dtype"),
37-
Some(stat_val),
38-
)
39-
.vortex_expect("`Stat::Min` somehow had an incompatible `DType`")
40-
.try_to_df()
41-
.ok()
42-
})
43-
.transpose()
44-
});
30+
let min = stats_set
31+
.get(Stat::Min)
32+
.map(|stat_val| {
33+
Scalar::try_new(
34+
Stat::Min
35+
.dtype(dtype)
36+
.vortex_expect("must have a valid dtype"),
37+
Some(stat_val),
38+
)
39+
.vortex_expect("`Stat::Min` somehow had an incompatible `DType`")
40+
.try_to_df()
41+
.ok()
42+
})
43+
.transpose();
4544

4645
// Find the max statistic.
47-
let max = stats_set.get(Stat::Max).and_then(|pstat_val| {
48-
pstat_val
49-
.map(|stat_val| {
50-
Scalar::try_new(
51-
Stat::Max
52-
.dtype(dtype)
53-
.vortex_expect("must have a valid dtype"),
54-
Some(stat_val),
55-
)
56-
.vortex_expect("`Stat::Max` somehow had an incompatible `DType`")
57-
.try_to_df()
58-
.ok()
59-
})
60-
.transpose()
61-
});
46+
let max = stats_set
47+
.get(Stat::Max)
48+
.map(|stat_val| {
49+
Scalar::try_new(
50+
Stat::Max
51+
.dtype(dtype)
52+
.vortex_expect("must have a valid dtype"),
53+
Some(stat_val),
54+
)
55+
.vortex_expect("`Stat::Max` somehow had an incompatible `DType`")
56+
.try_to_df()
57+
.ok()
58+
})
59+
.transpose();
6260

6361
// Find the sum statistic
64-
let sum = stats_set.get(Stat::Sum).and_then(|pstat_val| {
65-
pstat_val
66-
.map(|stat_val| {
67-
Scalar::try_new(
68-
Stat::Sum
69-
.dtype(dtype)
70-
.vortex_expect("must have a valid dtype"),
71-
Some(stat_val),
72-
)
73-
.vortex_expect("`Stat::Sum` somehow had an incompatible `DType`")
74-
.try_to_df()
75-
.ok()
76-
})
77-
.transpose()
78-
});
62+
let sum = stats_set
63+
.get(Stat::Sum)
64+
.map(|stat_val| {
65+
Scalar::try_new(
66+
Stat::Sum
67+
.dtype(dtype)
68+
.vortex_expect("must have a valid dtype"),
69+
Some(stat_val),
70+
)
71+
.vortex_expect("`Stat::Sum` somehow had an incompatible `DType`")
72+
.try_to_df()
73+
.ok()
74+
})
75+
.transpose();
7976

8077
let null_count = stats_set.get_as::<usize>(Stat::NullCount, &PType::U64.into());
8178

@@ -92,9 +89,9 @@ pub(crate) fn stats_set_to_df(
9289
}
9390

9491
pub(crate) fn is_constant_to_distinct_count(
95-
is_constant: Option<VortexPrecision<bool>>,
92+
is_constant: VortexPrecision<bool>,
9693
) -> Precision<usize> {
97-
match is_constant.and_then(VortexPrecision::as_exact) {
94+
match is_constant.as_exact() {
9895
Some(true) => Precision::Exact(1),
9996
Some(false) | None => Precision::Absent,
10097
}

vortex-datafusion/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ where
119119
match self {
120120
Precision::Exact(v) => DFPrecision::Exact(v),
121121
Precision::Inexact(v) => DFPrecision::Inexact(v),
122+
Precision::Absent => DFPrecision::Absent,
122123
}
123124
}
124125
}

vortex-datafusion/src/persistent/format.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,19 @@ impl FileFormat for VortexFormat {
639639

640640
fn scalar_stat_to_df(
641641
stat: Stat,
642-
value: Option<stats::Precision<VortexScalarValue>>,
642+
value: stats::Precision<VortexScalarValue>,
643643
stats_dtype: &DType,
644644
target_dtype: &DType,
645645
) -> Option<stats::Precision<DFScalarValue>> {
646646
let stat_dtype = stat.dtype(stats_dtype)?;
647647

648-
value?
649-
.try_map(|stat_value| {
648+
value
649+
.map(|stat_value| {
650650
Scalar::try_new(stat_dtype, Some(stat_value))?
651651
.cast(target_dtype)?
652652
.try_to_df()
653653
})
654+
.transpose()
654655
.ok()
655656
}
656657

vortex-file/src/pruning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn extract_relevant_file_stats_as_struct_row(
6060
stat,
6161
Stat::Max | Stat::Min | Stat::NaNCount | Stat::NullCount
6262
) {
63-
let Some(stat_value) = typed_stats.get(*stat).and_then(|p| p.as_exact()) else {
63+
let Some(stat_value) = typed_stats.get(*stat).as_exact() else {
6464
vortex_bail!("missing stat {}, {} from stats set", field, stat)
6565
};
6666
columns.push((

vortex-file/src/v2/file_stats_reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl StatsCatalog for FileStatsLayoutReader {
132132
let field_idx = self.struct_fields.find(field_name)?;
133133
let field_stats = self.file_stats.stats_sets().get(field_idx)?;
134134

135-
let stat_value = field_stats.get(stat)?.as_exact()?;
135+
let stat_value = field_stats.get(stat).as_exact()?;
136136
let field_dtype = self.struct_fields.field_by_index(field_idx)?;
137137
let stat_dtype = stat.dtype(&field_dtype)?;
138138
let stat_scalar = Scalar::try_new(stat_dtype, Some(stat_value)).ok()?;

vortex-layout/src/layouts/flat/writer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ fn truncate_scalar_stat<F: Fn(Scalar) -> Option<(Scalar, bool)>>(
8181
stat: Stat,
8282
truncation: F,
8383
) {
84-
if let Some(sv) = statistics.get(stat) {
85-
if let Some((truncated_value, truncated)) = truncation(sv.into_inner()) {
84+
if let Some(sv) = statistics.get(stat).into_inner() {
85+
if let Some((truncated_value, truncated)) = truncation(sv) {
8686
if truncated && let Some(v) = truncated_value.into_value() {
8787
statistics.set(stat, Precision::Inexact(v));
8888
}

vortex-layout/src/layouts/zoned/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl StatsAccumulator {
6969

7070
pub fn push_chunk_without_compute(&mut self, array: &ArrayRef) -> VortexResult<()> {
7171
for builder in &mut self.builders {
72-
if let Some(Precision::Exact(value)) = array.statistics().get(builder.stat()) {
72+
if let Precision::Exact(value) = array.statistics().get(builder.stat()) {
7373
builder.append_scalar(value.cast(&value.dtype().as_nullable())?)?;
7474
} else {
7575
builder.append_null();

0 commit comments

Comments
 (0)