kosiew commented on code in PR #26286:
URL: https://github.com/apache/datafusion/pull/26286#discussion_r4280777973
##########
datafusion/physical-plan/src/topk/mod.rs:
##########
@@ -3157,6 +3161,53 @@ mod tests {
)
}
+ #[test]
+ fn test_topk_size_common_sort_prefix_converter() -> Result<()> {
+ let schema = make_ab_schema();
+ let sort_expr = PhysicalSortExpr {
+ expr: col("a", schema.as_ref())?,
+ options: SortOptions::default(),
+ };
+ let make_topk = |common_sort_prefix| {
+ TopK::try_new(
+ 0,
+ Arc::clone(&schema),
+ common_sort_prefix,
+ LexOrdering::from([sort_expr.clone()]),
+ 3,
+ 2,
+ Arc::new(RuntimeEnv::default()),
+ &ExecutionPlanMetricsSet::new(),
+ make_topk_filter(),
+ )
+ };
+ let without_prefix = make_topk(vec![])?;
+ let mut with_prefix = make_topk(vec![sort_expr.clone()])?;
+ let converter_size = with_prefix
+ .common_sort_prefix_converter
+ .as_ref()
+ .expect("common sort prefix converter")
+ .size();
+ assert!(converter_size > 0);
+ assert!(without_prefix.common_sort_prefix_converter.is_none());
+ assert_eq!(
+ without_prefix.size(),
+ size_of::<TopK>()
+ + without_prefix.row_converter.size()
+ + without_prefix.scratch_rows.size()
+ + without_prefix.heap.size()
+ );
+ assert_eq!(with_prefix.size(), without_prefix.size() + converter_size);
+
+ with_prefix.insert_batch(make_ab_batch(
+ Arc::clone(&schema),
+ &[Some(1), Some(2)],
+ &[1.0, 2.0],
+ )?)?;
+ assert_eq!(with_prefix.reservation.size(), with_prefix.size());
Review Comment:
It’s not necessary for this regression. I added it to check memory-pool
charging, but `insert_batch()` already resizes the reservation using
`self.size()`, so this equality also passes with the converter omitted.
The preceding size-delta assertion catches the bug. I’ll remove the
insertion and reservation assertion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]