Skip to content

Commit c9ebff3

Browse files
committed
this commit add Debug trait for AggregateMeta, should revert before merge
1 parent 8ff9892 commit c9ebff3

File tree

4 files changed

+439
-12
lines changed

4 files changed

+439
-12
lines changed

src/query/expression/src/aggregate/partitioned_payload.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::fmt;
1516
use std::sync::Arc;
1617

1718
use bumpalo::Bump;
@@ -45,6 +46,29 @@ pub struct PartitionedPayload {
4546
unsafe impl Send for PartitionedPayload {}
4647
unsafe impl Sync for PartitionedPayload {}
4748

49+
struct PartitionDebugSnapshot<'a> {
50+
index: usize,
51+
rows: usize,
52+
pages: usize,
53+
payload: Option<&'a Payload>,
54+
}
55+
56+
impl fmt::Debug for PartitionDebugSnapshot<'_> {
57+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58+
let mut debug = f.debug_struct("Partition");
59+
debug
60+
.field("index", &self.index)
61+
.field("rows", &self.rows)
62+
.field("pages", &self.pages);
63+
64+
if let Some(payload) = self.payload {
65+
debug.field("payload", payload);
66+
}
67+
68+
debug.finish()
69+
}
70+
}
71+
4872
impl PartitionedPayload {
4973
pub fn new(
5074
group_types: Vec<DataType>,
@@ -269,6 +293,47 @@ impl PartitionedPayload {
269293
}
270294
}
271295

296+
impl fmt::Debug for PartitionedPayload {
297+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
298+
let partitions: Vec<PartitionDebugSnapshot<'_>> = self
299+
.payloads
300+
.iter()
301+
.enumerate()
302+
.map(|(index, payload)| PartitionDebugSnapshot {
303+
index,
304+
rows: payload.len(),
305+
pages: payload.pages.len(),
306+
payload: if f.alternate() { Some(payload) } else { None },
307+
})
308+
.collect();
309+
310+
let group_types: Vec<String> = self.group_types.iter().map(|ty| ty.to_string()).collect();
311+
let aggregate_functions: Vec<String> = self
312+
.aggrs
313+
.iter()
314+
.map(|func| func.name().to_string())
315+
.collect();
316+
let arena_strong_counts: Vec<usize> = self
317+
.arenas
318+
.iter()
319+
.map(|arena| Arc::strong_count(arena))
320+
.collect();
321+
322+
let mut debug = f.debug_struct("PartitionedPayload");
323+
debug
324+
.field("partition_count", &self.partition_count)
325+
.field("mask", &self.mask_v)
326+
.field("shift", &self.shift_v)
327+
.field("total_rows", &self.len())
328+
.field("group_types", &group_types)
329+
.field("aggregate_functions", &aggregate_functions)
330+
.field("partitions", &partitions)
331+
.field("arena_strong_counts", &arena_strong_counts);
332+
333+
debug.finish()
334+
}
335+
}
336+
272337
#[inline]
273338
fn shift(radix_bits: u64) -> u64 {
274339
48 - radix_bits

0 commit comments

Comments
 (0)