killme2008 commented on code in PR #27160:
URL: https://github.com/apache/datafusion/pull/27160#discussion_r4508277612


##########
datafusion/physical-expr/benches/case_when.rs:
##########
@@ -87,6 +89,78 @@ fn criterion_benchmark(c: &mut Criterion) {
 
     benchmark_lookup_table_case_when(c, 8192);
     benchmark_divide_by_zero_protection(c, 8192);
+    benchmark_literal_when_selection(c, 8192);
+}
+
+fn benchmark_literal_when_selection(c: &mut Criterion, row_count: usize) {
+    let mut group = c.benchmark_group("literal_when_selection");
+    for (distribution, branches) in [
+        ("uniform", 1),
+        ("uniform", 4),
+        ("first_only", 4),
+        ("uniform", 16),
+        ("first_only", 16),
+        ("half_match_with_else", 1),
+    ] {
+        let first_only = distribution == "first_only";
+        let with_else = distribution == "half_match_with_else";
+        let partitions = if with_else { 2 } else { branches };
+        let batch = RecordBatch::try_from_iter(vec![
+            (
+                "partition",
+                Arc::new(Int32Array::from_iter_values((0..row_count).map(|i| {
+                    if first_only {
+                        0
+                    } else {
+                        (i % partitions) as i32
+                    }
+                }))) as ArrayRef,
+            ),
+            (
+                "left_key",
+                Arc::new(StringArray::from_iter_values(
+                    (0..row_count).map(|i| format!("{i:032x}")),
+                )) as ArrayRef,
+            ),
+            (
+                "right_key",
+                Arc::new(StringArray::from_iter_values((0..row_count).map(|i| {
+                    let value = if i % 3 == 0 { i } else { i + 1 };
+                    format!("{value:032x}")
+                }))) as ArrayRef,
+            ),
+        ])
+        .unwrap();
+        let schema = batch.schema();
+        let then: Arc<dyn PhysicalExpr> = Arc::new(BinaryExpr::new(
+            col("left_key", &schema).unwrap(),
+            Operator::Eq,
+            col("right_key", &schema).unwrap(),
+        ));
+        let expr = case(
+            Some(col("partition", &schema).unwrap()),
+            (0..branches)
+                .map(|i| (lit(i as i32), Arc::clone(&then)))
+                .collect(),
+            with_else.then(|| Arc::clone(&then)),
+        )
+        .unwrap();

Review Comment:
   Good point. I'll change them.



-- 
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]

Reply via email to