Skip to content

Commit 7f84503

Browse files
compheadalamb
andauthored
revert accidently deleted size code in count_distinct (#5533)
* revert accidently deleted size code in count_distinct * fix clippy --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 6a8c4a6 commit 7f84503

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎datafusion/physical-expr/src/aggregate/count_distinct.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ impl DistinctCountAccumulator {
114114
.next()
115115
.map(|vals| ScalarValue::size(vals) - std::mem::size_of_val(vals))
116116
.unwrap_or(0)
117+
+ std::mem::size_of::<DataType>()
118+
}
119+
120+
// calculates the size as accurate as possible, call to this method is expensive
121+
fn full_size(&self) -> usize {
122+
std::mem::size_of_val(self)
123+
+ (std::mem::size_of::<DistinctScalarValues>() * self.values.capacity())
124+
+ self
125+
.values
126+
.iter()
127+
.map(|vals| ScalarValue::size(vals) - std::mem::size_of_val(vals))
128+
.sum::<usize>()
129+
+ std::mem::size_of::<DataType>()
117130
}
118131
}
119132

@@ -172,7 +185,11 @@ impl Accumulator for DistinctCountAccumulator {
172185
}
173186

174187
fn size(&self) -> usize {
175-
self.fixed_size()
188+
match &self.state_data_type {
189+
DataType::Boolean | DataType::Null => self.fixed_size(),
190+
d if d.is_primitive() => self.fixed_size(),
191+
_ => self.full_size(),
192+
}
176193
}
177194
}
178195

0 commit comments

Comments
 (0)