Skip to content

Commit 6ecf76c

Browse files
authored
bench: create benchmark for lookup table like CASE WHEN (#18203)
## Which issue does this PR close? N/A But extracted from: - #18183 ## Rationale for this change I want to add optimization for lookup based `CASE WHEN` like: ```sql CASE company WHEN 1 THEN 'Apple' WHEN 5 THEN 'Samsung' WHEN 2 THEN 'Motorola' WHEN 3 THEN 'LG' ELSE 'Other' END ``` ## What changes are included in this PR? Added multiple benchmarks for testing lookup table from int to string and vice verca with different size of lookup table (5, 10, 20), different probabilities for having values generated to exist in the lookup map, and probabilities for the number of nulls ## Are these changes tested? N/A ## Are there any user-facing changes? nope <details> <summary>Current results</summary> ``` lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [572.27 µs 572.51 µs 572.78 µs] change: [-0.4311% -0.1953% +0.0524%] (p = 0.09 > 0.05) No change in performance detected. Found 6 outliers among 100 measurements (6.00%) 3 (3.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [808.11 µs 808.63 µs 809.30 µs] change: [+0.2857% +0.4440% +0.6288%] (p = 0.00 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [341.97 µs 342.52 µs 343.21 µs] change: [-0.0740% +0.1913% +0.4541%] (p = 0.13 > 0.05) No change in performance detected. Found 9 outliers among 100 measurements (9.00%) 3 (3.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [446.34 µs 446.58 µs 446.83 µs] change: [-0.0381% +0.1947% +0.3941%] (p = 0.08 > 0.05) No change in performance detected. Found 12 outliers among 100 measurements (12.00%) 8 (8.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [804.30 µs 804.79 µs 805.33 µs] change: [+0.7523% +0.9613% +1.1731%] (p = 0.00 < 0.05) Change within noise threshold. Found 6 outliers among 100 measurements (6.00%) 4 (4.00%) high mild 2 (2.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [1.3972 ms 1.3979 ms 1.3987 ms] change: [-0.4150% -0.2455% -0.0613%] (p = 0.00 < 0.05) Change within noise threshold. Found 10 outliers among 100 measurements (10.00%) 7 (7.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [342.75 µs 342.96 µs 343.22 µs] change: [+0.0122% +0.2433% +0.4781%] (p = 0.02 < 0.05) Change within noise threshold. Found 10 outliers among 100 measurements (10.00%) 1 (1.00%) low mild 2 (2.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [445.39 µs 445.56 µs 445.75 µs] change: [-0.4254% -0.2538% -0.0547%] (p = 0.00 < 0.05) Change within noise threshold. Found 8 outliers among 100 measurements (8.00%) 5 (5.00%) high mild 3 (3.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.9s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [1.1731 ms 1.1738 ms 1.1746 ms] change: [+0.3589% +0.5605% +0.7873%] (p = 0.00 < 0.05) Change within noise threshold. Found 11 outliers among 100 measurements (11.00%) 1 (1.00%) low mild 5 (5.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [2.3819 ms 2.3832 ms 2.3845 ms] change: [+0.0355% +0.1016% +0.1663%] (p = 0.00 < 0.05) Change within noise threshold. Found 5 outliers among 100 measurements (5.00%) 5 (5.00%) high mild lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [341.53 µs 341.68 µs 341.85 µs] change: [-0.4361% -0.2031% +0.0398%] (p = 0.08 > 0.05) No change in performance detected. Found 9 outliers among 100 measurements (9.00%) 2 (2.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0 time: [444.97 µs 445.12 µs 445.30 µs] change: [-0.3776% -0.2148% -0.0460%] (p = 0.00 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 2 (2.00%) high mild 10 (10.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [728.94 µs 729.23 µs 729.58 µs] change: [+0.2335% +0.4019% +0.5791%] (p = 0.00 < 0.05) Change within noise threshold. Found 14 outliers among 100 measurements (14.00%) 1 (1.00%) low mild 8 (8.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [966.21 µs 967.02 µs 968.03 µs] change: [+0.2251% +0.3997% +0.6015%] (p = 0.00 < 0.05) Change within noise threshold. Found 11 outliers among 100 measurements (11.00%) 2 (2.00%) high mild 9 (9.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [485.63 µs 485.86 µs 486.11 µs] change: [+0.0990% +0.2832% +0.4909%] (p = 0.00 < 0.05) Change within noise threshold. Found 6 outliers among 100 measurements (6.00%) 4 (4.00%) high mild 2 (2.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [565.86 µs 566.24 µs 566.70 µs] change: [+0.1038% +0.2811% +0.4814%] (p = 0.00 < 0.05) Change within noise threshold. Found 14 outliers among 100 measurements (14.00%) 5 (5.00%) high mild 9 (9.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.2s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [1.0237 ms 1.0243 ms 1.0250 ms] change: [+0.3817% +0.6095% +0.8366%] (p = 0.00 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 4 (4.00%) high mild 8 (8.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.2s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [1.6139 ms 1.6145 ms 1.6151 ms] change: [-0.3413% -0.1799% -0.0094%] (p = 0.03 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 4 (4.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [485.50 µs 485.75 µs 486.07 µs] change: [+0.0362% +0.2597% +0.4990%] (p = 0.02 < 0.05) Change within noise threshold. Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [564.83 µs 565.13 µs 565.49 µs] change: [-0.2292% -0.0443% +0.1429%] (p = 0.68 > 0.05) No change in performance detected. Found 13 outliers among 100 measurements (13.00%) 5 (5.00%) high mild 8 (8.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.7s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [1.5206 ms 1.5214 ms 1.5223 ms] change: [+0.1219% +0.2845% +0.4382%] (p = 0.00 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [2.7355 ms 2.7372 ms 2.7392 ms] change: [+0.1862% +0.2633% +0.3492%] (p = 0.00 < 0.05) Change within noise threshold. Found 16 outliers among 100 measurements (16.00%) 6 (6.00%) high mild 10 (10.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [485.64 µs 485.87 µs 486.12 µs] change: [-0.1317% +0.0342% +0.1974%] (p = 0.72 > 0.05) No change in performance detected. Found 17 outliers among 100 measurements (17.00%) 10 (10.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.1 time: [564.95 µs 565.22 µs 565.52 µs] change: [-0.2459% -0.0804% +0.1093%] (p = 0.42 > 0.05) No change in performance detected. Found 11 outliers among 100 measurements (11.00%) 5 (5.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [613.55 µs 613.90 µs 614.30 µs] change: [-0.1978% +0.0206% +0.2512%] (p = 0.88 > 0.05) No change in performance detected. Found 13 outliers among 100 measurements (13.00%) 2 (2.00%) high mild 11 (11.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [804.94 µs 805.27 µs 805.64 µs] change: [-0.3371% -0.2017% -0.0566%] (p = 0.00 < 0.05) Change within noise threshold. Found 7 outliers among 100 measurements (7.00%) 6 (6.00%) high mild 1 (1.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [451.36 µs 451.55 µs 451.75 µs] change: [-0.1076% +0.0692% +0.2464%] (p = 0.48 > 0.05) No change in performance detected. Found 10 outliers among 100 measurements (10.00%) 6 (6.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [516.12 µs 516.36 µs 516.64 µs] change: [-0.2179% +0.0030% +0.2181%] (p = 0.96 > 0.05) No change in performance detected. Found 15 outliers among 100 measurements (15.00%) 5 (5.00%) high mild 10 (10.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [831.48 µs 831.89 µs 832.37 µs] change: [+0.2730% +0.4416% +0.6047%] (p = 0.00 < 0.05) Change within noise threshold. Found 9 outliers among 100 measurements (9.00%) 7 (7.00%) high mild 2 (2.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.6s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [1.2999 ms 1.3006 ms 1.3014 ms] change: [+0.1551% +0.3508% +0.5933%] (p = 0.00 < 0.05) Change within noise threshold. Found 10 outliers among 100 measurements (10.00%) 7 (7.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [451.54 µs 451.76 µs 452.00 µs] change: [-0.0486% +0.1303% +0.3100%] (p = 0.17 > 0.05) No change in performance detected. Found 8 outliers among 100 measurements (8.00%) 6 (6.00%) high mild 2 (2.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [516.47 µs 516.73 µs 517.04 µs] change: [-0.2732% -0.0578% +0.1455%] (p = 0.66 > 0.05) No change in performance detected. Found 14 outliers among 100 measurements (14.00%) 4 (4.00%) high mild 10 (10.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.2s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [1.2276 ms 1.2283 ms 1.2290 ms] change: [+0.3032% +0.4998% +0.6974%] (p = 0.00 < 0.05) Change within noise threshold. Found 6 outliers among 100 measurements (6.00%) 3 (3.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [2.1643 ms 2.1656 ms 2.1671 ms] change: [-0.2215% -0.1512% -0.0757%] (p = 0.00 < 0.05) Change within noise threshold. Found 16 outliers among 100 measurements (16.00%) 7 (7.00%) high mild 9 (9.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [451.48 µs 451.71 µs 451.96 µs] change: [-0.4533% -0.2697% -0.0701%] (p = 0.00 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 7 (7.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.1, nulls: 0.5 time: [516.17 µs 516.42 µs 516.71 µs] change: [-0.3951% -0.1759% +0.0285%] (p = 0.10 > 0.05) No change in performance detected. Found 10 outliers among 100 measurements (10.00%) 3 (3.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [581.53 µs 581.85 µs 582.22 µs] change: [-0.4681% -0.2375% +0.0205%] (p = 0.03 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 6 (6.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [806.04 µs 806.40 µs 806.83 µs] change: [-0.3328% -0.1863% -0.0288%] (p = 0.00 < 0.05) Change within noise threshold. Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [341.42 µs 341.59 µs 341.78 µs] change: [-0.5843% -0.3707% -0.1573%] (p = 0.00 < 0.05) Change within noise threshold. Found 11 outliers among 100 measurements (11.00%) 6 (6.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [445.02 µs 445.20 µs 445.42 µs] change: [-0.3079% -0.1435% +0.0361%] (p = 0.10 > 0.05) No change in performance detected. Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [804.03 µs 804.52 µs 805.10 µs] change: [+0.0833% +0.2480% +0.4237%] (p = 0.00 < 0.05) Change within noise threshold. Found 10 outliers among 100 measurements (10.00%) 3 (3.00%) high mild 7 (7.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [1.3958 ms 1.3964 ms 1.3970 ms] change: [-0.3882% -0.2616% -0.1751%] (p = 0.00 < 0.05) Change within noise threshold. Found 8 outliers among 100 measurements (8.00%) 5 (5.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [341.66 µs 341.85 µs 342.06 µs] change: [-0.5154% -0.3585% -0.2438%] (p = 0.00 < 0.05) Change within noise threshold. Found 6 outliers among 100 measurements (6.00%) 5 (5.00%) high mild 1 (1.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [445.08 µs 445.29 µs 445.53 µs] change: [-0.1558% +0.0148% +0.1858%] (p = 0.88 > 0.05) No change in performance detected. Found 13 outliers among 100 measurements (13.00%) 7 (7.00%) high mild 6 (6.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.9s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [1.1700 ms 1.1709 ms 1.1719 ms] change: [+0.0124% +0.2123% +0.4009%] (p = 0.02 < 0.05) Change within noise threshold. Found 9 outliers among 100 measurements (9.00%) 4 (4.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [2.3757 ms 2.3775 ms 2.3800 ms] change: [+0.0656% +0.1579% +0.2573%] (p = 0.00 < 0.05) Change within noise threshold. Found 12 outliers among 100 measurements (12.00%) 6 (6.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [341.47 µs 341.77 µs 342.10 µs] change: [-0.2178% +0.0125% +0.2362%] (p = 0.92 > 0.05) No change in performance detected. Found 10 outliers among 100 measurements (10.00%) 5 (5.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0 time: [445.57 µs 445.82 µs 446.09 µs] change: [-0.0565% +0.1035% +0.2671%] (p = 0.23 > 0.05) No change in performance detected. Found 9 outliers among 100 measurements (9.00%) 5 (5.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [728.22 µs 728.56 µs 728.96 µs] change: [-0.3534% -0.1796% +0.0062%] (p = 0.03 < 0.05) Change within noise threshold. Found 13 outliers among 100 measurements (13.00%) 4 (4.00%) high mild 9 (9.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [965.27 µs 965.67 µs 966.17 µs] change: [-0.2803% -0.1597% -0.0369%] (p = 0.00 < 0.05) Change within noise threshold. Found 9 outliers among 100 measurements (9.00%) 5 (5.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [485.15 µs 485.40 µs 485.69 µs] change: [-0.1787% +0.0020% +0.1849%] (p = 0.98 > 0.05) No change in performance detected. Found 8 outliers among 100 measurements (8.00%) 1 (1.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [566.91 µs 567.13 µs 567.37 µs] change: [-0.1075% +0.0721% +0.2537%] (p = 0.47 > 0.05) No change in performance detected. Found 11 outliers among 100 measurements (11.00%) 3 (3.00%) high mild 8 (8.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.2s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [1.0272 ms 1.0278 ms 1.0286 ms] Found 10 outliers among 100 measurements (10.00%) 3 (3.00%) high mild 7 (7.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.2s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [1.6216 ms 1.6224 ms 1.6232 ms] Found 8 outliers among 100 measurements (8.00%) 2 (2.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [485.95 µs 486.18 µs 486.46 µs] Found 13 outliers among 100 measurements (13.00%) 5 (5.00%) high mild 8 (8.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [566.82 µs 567.07 µs 567.34 µs] Found 15 outliers among 100 measurements (15.00%) 7 (7.00%) high mild 8 (8.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.7s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [1.5252 ms 1.5263 ms 1.5276 ms] Found 10 outliers among 100 measurements (10.00%) 7 (7.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [2.7479 ms 2.7492 ms 2.7507 ms] Found 15 outliers among 100 measurements (15.00%) 8 (8.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [485.18 µs 485.54 µs 486.05 µs] Found 13 outliers among 100 measurements (13.00%) 4 (4.00%) high mild 9 (9.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.1 time: [566.81 µs 567.09 µs 567.43 µs] Found 15 outliers among 100 measurements (15.00%) 7 (7.00%) high mild 8 (8.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [614.34 µs 614.75 µs 615.29 µs] Found 10 outliers among 100 measurements (10.00%) 3 (3.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [808.13 µs 808.56 µs 809.05 µs] Found 11 outliers among 100 measurements (11.00%) 7 (7.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [452.21 µs 452.46 µs 452.79 µs] Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [518.11 µs 518.36 µs 518.62 µs] Found 13 outliers among 100 measurements (13.00%) 7 (7.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [834.45 µs 834.88 µs 835.36 µs] Found 9 outliers among 100 measurements (9.00%) 6 (6.00%) high mild 3 (3.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.6s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [1.3037 ms 1.3045 ms 1.3053 ms] Found 8 outliers among 100 measurements (8.00%) 7 (7.00%) high mild 1 (1.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [451.25 µs 451.57 µs 451.99 µs] Found 11 outliers among 100 measurements (11.00%) 5 (5.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [517.62 µs 517.86 µs 518.12 µs] Found 11 outliers among 100 measurements (11.00%) 5 (5.00%) high mild 6 (6.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.2s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [1.2297 ms 1.2310 ms 1.2328 ms] Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [2.1666 ms 2.1676 ms 2.1686 ms] Found 8 outliers among 100 measurements (8.00%) 7 (7.00%) high mild 1 (1.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [452.46 µs 452.66 µs 452.88 µs] Found 8 outliers among 100 measurements (8.00%) 5 (5.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.5, nulls: 0.5 time: [517.20 µs 517.44 µs 517.72 µs] Found 17 outliers among 100 measurements (17.00%) 6 (6.00%) high mild 11 (11.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [582.53 µs 583.31 µs 584.58 µs] Found 6 outliers among 100 measurements (6.00%) 1 (1.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [807.24 µs 807.65 µs 808.09 µs] Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [341.89 µs 342.06 µs 342.25 µs] Found 7 outliers among 100 measurements (7.00%) 3 (3.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [445.32 µs 445.54 µs 445.80 µs] Found 9 outliers among 100 measurements (9.00%) 3 (3.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [804.09 µs 804.53 µs 805.00 µs] Found 6 outliers among 100 measurements (6.00%) 5 (5.00%) high mild 1 (1.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [1.3968 ms 1.3975 ms 1.3983 ms] Found 11 outliers among 100 measurements (11.00%) 4 (4.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [341.27 µs 341.43 µs 341.60 µs] Found 9 outliers among 100 measurements (9.00%) 7 (7.00%) high mild 2 (2.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [445.54 µs 445.86 µs 446.24 µs] Found 14 outliers among 100 measurements (14.00%) 6 (6.00%) high mild 8 (8.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.9s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [1.1703 ms 1.1710 ms 1.1717 ms] Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [2.3708 ms 2.3724 ms 2.3743 ms] Found 11 outliers among 100 measurements (11.00%) 8 (8.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [341.94 µs 342.15 µs 342.41 µs] Found 9 outliers among 100 measurements (9.00%) 5 (5.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0 time: [445.15 µs 445.42 µs 445.74 µs] Found 11 outliers among 100 measurements (11.00%) 4 (4.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [729.65 µs 729.94 µs 730.26 µs] Found 11 outliers among 100 measurements (11.00%) 6 (6.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [966.46 µs 966.97 µs 967.58 µs] Found 7 outliers among 100 measurements (7.00%) 2 (2.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [486.14 µs 486.36 µs 486.61 µs] Found 9 outliers among 100 measurements (9.00%) 4 (4.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [566.81 µs 567.07 µs 567.34 µs] Found 13 outliers among 100 measurements (13.00%) 6 (6.00%) high mild 7 (7.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.2s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [1.0273 ms 1.0278 ms 1.0283 ms] Found 9 outliers among 100 measurements (9.00%) 4 (4.00%) high mild 5 (5.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.2s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [1.6239 ms 1.6248 ms 1.6258 ms] Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [485.73 µs 486.04 µs 486.43 µs] Found 14 outliers among 100 measurements (14.00%) 6 (6.00%) high mild 8 (8.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [567.22 µs 567.54 µs 567.93 µs] Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) high mild 6 (6.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.7s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [1.5275 ms 1.5282 ms 1.5290 ms] Found 6 outliers among 100 measurements (6.00%) 3 (3.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [2.7513 ms 2.7532 ms 2.7553 ms] Found 10 outliers among 100 measurements (10.00%) 4 (4.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [486.38 µs 486.58 µs 486.78 µs] Found 5 outliers among 100 measurements (5.00%) 3 (3.00%) high mild 2 (2.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 0.9, nulls: 0.1 time: [566.15 µs 566.42 µs 566.75 µs] Found 13 outliers among 100 measurements (13.00%) 7 (7.00%) high mild 6 (6.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [582.47 µs 582.74 µs 583.04 µs] Found 14 outliers among 100 measurements (14.00%) 9 (9.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [807.70 µs 808.17 µs 808.74 µs] Found 11 outliers among 100 measurements (11.00%) 2 (2.00%) high mild 9 (9.00%) high severe lookup_table_case_when/case when i32 -> utf8, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [341.62 µs 341.80 µs 342.03 µs] Found 6 outliers among 100 measurements (6.00%) 2 (2.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when utf8 -> i32, 5 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [445.48 µs 445.87 µs 446.40 µs] Found 13 outliers among 100 measurements (13.00%) 6 (6.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [804.56 µs 805.03 µs 805.52 µs] Found 6 outliers among 100 measurements (6.00%) 5 (5.00%) high mild 1 (1.00%) high severe Benchmarking lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50. lookup_table_case_when/case when utf8 -> i32, 10 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [1.3995 ms 1.4004 ms 1.4015 ms] Found 8 outliers among 100 measurements (8.00%) 4 (4.00%) high mild 4 (4.00%) high severe lookup_table_case_when/case when i32 -> utf8, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [341.46 µs 341.64 µs 341.85 µs] Found 9 outliers among 100 measurements (9.00%) 6 (6.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 10 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [445.91 µs 446.16 µs 446.47 µs] Found 9 outliers among 100 measurements (9.00%) 3 (3.00%) high mild 6 (6.00%) high severe Benchmarking lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0: Warming up for 3.0000 s Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 5.9s, enable flat sampling, or reduce sample count to 60. lookup_table_case_when/case when i32 -> utf8, 20 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [1.1708 ms 1.1716 ms 1.1725 ms] Found 5 outliers among 100 measurements (5.00%) 2 (2.00%) high mild 3 (3.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, all equally true/case_when 8192 rows: in_range: 1, nulls: 0 time: [2.3735 ms 2.3748 ms 2.3763 ms] Found 12 outliers among 100 measurements (12.00%) 5 (5.00%) high mild 7 (7.00%) high severe lookup_table_case_when/case when i32 -> utf8, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [342.14 µs 342.31 µs 342.53 µs] Found 8 outliers among 100 measurements (8.00%) 3 (3.00%) high mild 5 (5.00%) high severe lookup_table_case_when/case when utf8 -> i32, 20 entries, only first 2 are true/case_when 8192 rows: in_range: 1, nulls: 0 time: [444.92 µs 445.09 µs 445.29 µs] Found 15 outliers among 100 measurements (15.00%) 6 (6.00%) high mild 9 (9.00%) high severe ``` </details>
1 parent 4aceda0 commit 6ecf76c

File tree

1 file changed

+289
-3
lines changed

1 file changed

+289
-3
lines changed

datafusion/physical-expr/benches/case_when.rs

Lines changed: 289 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use arrow::array::{Array, ArrayRef, Int32Array, Int32Builder};
19-
use arrow::datatypes::{Field, Schema};
18+
use arrow::array::{Array, ArrayRef, Int32Array, Int32Builder, StringArray};
19+
use arrow::datatypes::{ArrowNativeTypeOp, Field, Schema};
2020
use arrow::record_batch::RecordBatch;
21-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
21+
use arrow::util::test_util::seedable_rng;
22+
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
2223
use datafusion_expr::Operator;
2324
use datafusion_physical_expr::expressions::{case, col, lit, BinaryExpr};
2425
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
26+
use itertools::Itertools;
27+
use rand::distr::uniform::SampleUniform;
28+
use rand::distr::Alphanumeric;
29+
use rand::rngs::StdRng;
30+
use rand::{Rng, RngCore};
31+
use std::fmt::{Display, Formatter};
32+
use std::ops::Range;
2533
use std::sync::Arc;
2634

2735
fn make_x_cmp_y(
@@ -82,6 +90,8 @@ fn criterion_benchmark(c: &mut Criterion) {
8290
run_benchmarks(c, &make_batch(8192, 3));
8391
run_benchmarks(c, &make_batch(8192, 50));
8492
run_benchmarks(c, &make_batch(8192, 100));
93+
94+
benchmark_lookup_table_case_when(c, 8192);
8595
}
8696

8797
fn run_benchmarks(c: &mut Criterion, batch: &RecordBatch) {
@@ -230,5 +240,281 @@ fn run_benchmarks(c: &mut Criterion, batch: &RecordBatch) {
230240
});
231241
}
232242

243+
struct Options<T> {
244+
number_of_rows: usize,
245+
range_of_values: Vec<T>,
246+
in_range_probability: f32,
247+
null_probability: f32,
248+
}
249+
250+
fn generate_other_primitive_value<T: ArrowNativeTypeOp + SampleUniform>(
251+
rng: &mut impl RngCore,
252+
exclude: &[T],
253+
) -> T {
254+
let mut value;
255+
let retry_limit = 100;
256+
for _ in 0..retry_limit {
257+
value = rng.random_range(T::MIN_TOTAL_ORDER..=T::MAX_TOTAL_ORDER);
258+
if !exclude.contains(&value) {
259+
return value;
260+
}
261+
}
262+
263+
panic!("Could not generate out of range value after {retry_limit} attempts");
264+
}
265+
266+
fn create_random_string_generator(
267+
length: Range<usize>,
268+
) -> impl Fn(&mut dyn RngCore, &[String]) -> String {
269+
assert!(length.end > length.start);
270+
271+
move |rng, exclude| {
272+
let retry_limit = 100;
273+
for _ in 0..retry_limit {
274+
let length = rng.random_range(length.clone());
275+
let value: String = rng
276+
.sample_iter(Alphanumeric)
277+
.take(length)
278+
.map(char::from)
279+
.collect();
280+
281+
if !exclude.contains(&value) {
282+
return value;
283+
}
284+
}
285+
286+
panic!("Could not generate out of range value after {retry_limit} attempts");
287+
}
288+
}
289+
290+
/// Create column with the provided number of rows
291+
/// `in_range_percentage` is the percentage of values that should be inside the specified range
292+
/// `null_percentage` is the percentage of null values
293+
/// The rest of the values will be outside the specified range
294+
fn generate_values_for_lookup<T, A>(
295+
options: Options<T>,
296+
generate_other_value: impl Fn(&mut StdRng, &[T]) -> T,
297+
) -> A
298+
where
299+
T: Clone,
300+
A: FromIterator<Option<T>>,
301+
{
302+
// Create a value with specified range most of the time, but also some nulls and the rest is generic
303+
304+
assert!(
305+
options.in_range_probability + options.null_probability <= 1.0,
306+
"Percentages must sum to 1.0 or less"
307+
);
308+
309+
let rng = &mut seedable_rng();
310+
311+
let in_range_probability = 0.0..options.in_range_probability;
312+
let null_range_probability =
313+
in_range_probability.start..in_range_probability.start + options.null_probability;
314+
let out_range_probability = null_range_probability.end..1.0;
315+
316+
(0..options.number_of_rows)
317+
.map(|_| {
318+
let roll: f32 = rng.random();
319+
320+
match roll {
321+
v if out_range_probability.contains(&v) => {
322+
let index = rng.random_range(0..options.range_of_values.len());
323+
// Generate value in range
324+
Some(options.range_of_values[index].clone())
325+
}
326+
v if null_range_probability.contains(&v) => None,
327+
_ => {
328+
// Generate value out of range
329+
Some(generate_other_value(rng, &options.range_of_values))
330+
}
331+
}
332+
})
333+
.collect::<A>()
334+
}
335+
336+
fn benchmark_lookup_table_case_when(c: &mut Criterion, batch_size: usize) {
337+
#[derive(Clone, Copy, Debug)]
338+
struct CaseWhenLookupInput {
339+
batch_size: usize,
340+
341+
in_range_probability: f32,
342+
null_probability: f32,
343+
}
344+
345+
impl Display for CaseWhenLookupInput {
346+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
347+
write!(
348+
f,
349+
"case_when {} rows: in_range: {}, nulls: {}",
350+
self.batch_size, self.in_range_probability, self.null_probability,
351+
)
352+
}
353+
}
354+
355+
let mut case_when_lookup = c.benchmark_group("lookup_table_case_when");
356+
357+
for in_range_probability in [0.1, 0.5, 0.9, 1.0] {
358+
for null_probability in [0.0, 0.1, 0.5] {
359+
if in_range_probability + null_probability > 1.0 {
360+
continue;
361+
}
362+
363+
let input = CaseWhenLookupInput {
364+
batch_size,
365+
in_range_probability,
366+
null_probability,
367+
};
368+
369+
let when_thens_primitive_to_string = vec![
370+
(1, "something"),
371+
(2, "very"),
372+
(3, "interesting"),
373+
(4, "is"),
374+
(5, "going"),
375+
(6, "to"),
376+
(7, "happen"),
377+
(30, "in"),
378+
(31, "datafusion"),
379+
(90, "when"),
380+
(91, "you"),
381+
(92, "find"),
382+
(93, "it"),
383+
(120, "let"),
384+
(240, "me"),
385+
(241, "know"),
386+
(244, "please"),
387+
(246, "thank"),
388+
(250, "you"),
389+
(252, "!"),
390+
];
391+
let when_thens_string_to_primitive = when_thens_primitive_to_string
392+
.iter()
393+
.map(|&(key, value)| (value, key))
394+
.collect_vec();
395+
396+
for num_entries in [5, 10, 20] {
397+
for (name, values_range) in [
398+
("all equally true", 0..num_entries),
399+
// Test when early termination is beneficial
400+
("only first 2 are true", 0..2),
401+
] {
402+
let when_thens_primitive_to_string =
403+
when_thens_primitive_to_string[values_range.clone()].to_vec();
404+
405+
let when_thens_string_to_primitive =
406+
when_thens_string_to_primitive[values_range].to_vec();
407+
408+
case_when_lookup.bench_with_input(
409+
BenchmarkId::new(
410+
format!(
411+
"case when i32 -> utf8, {num_entries} entries, {name}"
412+
),
413+
input,
414+
),
415+
&input,
416+
|b, input| {
417+
let array: Int32Array = generate_values_for_lookup(
418+
Options::<i32> {
419+
number_of_rows: batch_size,
420+
range_of_values: when_thens_primitive_to_string
421+
.iter()
422+
.map(|(key, _)| *key)
423+
.collect(),
424+
in_range_probability: input.in_range_probability,
425+
null_probability: input.null_probability,
426+
},
427+
|rng, exclude| {
428+
generate_other_primitive_value::<i32>(rng, exclude)
429+
},
430+
);
431+
let batch = RecordBatch::try_new(
432+
Arc::new(Schema::new(vec![Field::new(
433+
"col1",
434+
array.data_type().clone(),
435+
true,
436+
)])),
437+
vec![Arc::new(array)],
438+
)
439+
.unwrap();
440+
441+
let when_thens = when_thens_primitive_to_string
442+
.iter()
443+
.map(|&(key, value)| (lit(key), lit(value)))
444+
.collect();
445+
446+
let expr = Arc::new(
447+
case(
448+
Some(col("col1", batch.schema_ref()).unwrap()),
449+
when_thens,
450+
Some(lit("whatever")),
451+
)
452+
.unwrap(),
453+
);
454+
455+
b.iter(|| {
456+
black_box(expr.evaluate(black_box(&batch)).unwrap())
457+
})
458+
},
459+
);
460+
461+
case_when_lookup.bench_with_input(
462+
BenchmarkId::new(
463+
format!(
464+
"case when utf8 -> i32, {num_entries} entries, {name}"
465+
),
466+
input,
467+
),
468+
&input,
469+
|b, input| {
470+
let array: StringArray = generate_values_for_lookup(
471+
Options::<String> {
472+
number_of_rows: batch_size,
473+
range_of_values: when_thens_string_to_primitive
474+
.iter()
475+
.map(|(key, _)| (*key).to_string())
476+
.collect(),
477+
in_range_probability: input.in_range_probability,
478+
null_probability: input.null_probability,
479+
},
480+
|rng, exclude| {
481+
create_random_string_generator(3..10)(rng, exclude)
482+
},
483+
);
484+
let batch = RecordBatch::try_new(
485+
Arc::new(Schema::new(vec![Field::new(
486+
"col1",
487+
array.data_type().clone(),
488+
true,
489+
)])),
490+
vec![Arc::new(array)],
491+
)
492+
.unwrap();
493+
494+
let when_thens = when_thens_string_to_primitive
495+
.iter()
496+
.map(|&(key, value)| (lit(key), lit(value)))
497+
.collect();
498+
499+
let expr = Arc::new(
500+
case(
501+
Some(col("col1", batch.schema_ref()).unwrap()),
502+
when_thens,
503+
Some(lit(1000)),
504+
)
505+
.unwrap(),
506+
);
507+
508+
b.iter(|| {
509+
black_box(expr.evaluate(black_box(&batch)).unwrap())
510+
})
511+
},
512+
);
513+
}
514+
}
515+
}
516+
}
517+
}
518+
233519
criterion_group!(benches, criterion_benchmark);
234520
criterion_main!(benches);

0 commit comments

Comments
 (0)