rluvaton commented on code in PR #22175:
URL: https://github.com/apache/datafusion/pull/22175#discussion_r3242813598
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -3120,4 +3137,60 @@ mod tests {
Arc::new(expected_with_else),
);
}
+
+ /// Reproduces https://github.com/apache/datafusion/issues/22173
+ ///
+ /// Nested self-referential CASE chains (common in rewrite-style
projections)
+ /// should not cause exponential hashing work during physical planning.
+ #[test]
+ fn nested_self_referential_case_hash_stays_bounded() -> Result<()> {
+ use std::hash::Hasher;
+
+ #[derive(Default)]
+ struct CountingHasher {
+ write_calls: usize,
+ bytes_written: usize,
+ }
+
+ impl Hasher for CountingHasher {
+ fn finish(&self) -> u64 {
+ 0
+ }
+
+ fn write(&mut self, bytes: &[u8]) {
+ self.write_calls += 1;
+ self.bytes_written += bytes.len();
+ }
+ }
+
+ let schema =
+ Arc::new(Schema::new(vec![Field::new("kind", DataType::Utf8,
true)]));
+
+ let kind = col("kind", &schema)?;
+ let mut label = Arc::clone(&kind);
+
+ let num_levels = 18;
+ for idx in 0..num_levels {
+ let predicate = Arc::new(BinaryExpr::new(
+ Arc::clone(&kind),
+ Operator::Eq,
+ lit(idx.to_string()),
+ )) as Arc<dyn PhysicalExpr>;
+
+ label = case(None, vec![(predicate, lit("label"))], Some(label))?;
+ }
+
+ let mut hasher = CountingHasher::default();
+ label.hash(&mut hasher);
+
+ println!("{num_levels} level CASE did {} hashes", hasher.write_calls);
Review Comment:
please remove the print
--
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]