Skip to content

Refactor scalar min/max dispatch into function-based helpers#22062

Open
kosiew wants to merge 3 commits into
apache:mainfrom
kosiew:macro-22061
Open

Refactor scalar min/max dispatch into function-based helpers#22062
kosiew wants to merge 3 commits into
apache:mainfrom
kosiew:macro-22061

Conversation

@kosiew
Copy link
Copy Markdown
Contributor

@kosiew kosiew commented May 7, 2026

Which issue does this PR close?

Rationale for this change

The existing min_max_scalar_impl! macro combined dispatch, validation, recursion, and control flow into a large macro expansion, making the logic difficult to debug, review, and test in isolation.

This change moves scalar min/max dispatch to a function-based implementation while preserving existing behavior, error messages, and dictionary handling semantics.

What changes are included in this PR?

  • Replaced the min_max_scalar_impl! macro with function-based dispatch logic.

  • Added helper functions to separate responsibilities:

    • min_max_option
    • min_max_float_option
    • ensure_decimal_compatibility
    • min_max_generic_scalar
    • min_max_interval_scalar
    • min_max_dictionary_scalar
    • min_max_scalar_same_variant
  • Kept min_max_scalar as the main entry point and delegated behavior through helper functions.

  • Preserved:

    • existing min/max behavior across scalar types
    • dictionary comparison and rewrapping semantics
    • decimal precision/scale validation behavior
    • float NaN handling via total_cmp
    • existing error classifications and messages
    • compacting behavior for generic scalar comparisons
  • Simplified macro usage by retaining only lightweight ordering-selection macros.

Are these changes tested?

Yes.

Added unit tests covering:

  • core scalar min/max parity behavior
  • float NaN handling using total_cmp
  • decimal mismatch error preservation
  • fixed-size binary mismatch error preservation
  • mixed interval comparison error preservation

Existing dictionary comparison tests are also preserved.

Are there any user-facing changes?

No. This PR is intended to be a refactor only and preserves existing externally visible behavior.

LLM-generated code disclosure

This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.

kosiew added 3 commits May 7, 2026 14:28
- Removed `min_max_scalar_impl!`
- Added function dispatch for:
- `min_max_scalar_same_variant`
- `min_max_dictionary_scalar`
- `ensure_decimal_compatibility`
- scalar helper functions
- Preserved dictionary unwrap/rewrap behavior
- Added parity/regression tests for:
- core scalar min/max
- float NaN total comparison
- decimal mismatch error
- fixed-size-binary mismatch error
…d improve error messages

- Merged min_max_option and min_max_clone_option
- Replaced clone helper call sites
- Shortened dictionary arms using .map(Some)
- Updated decimal compatibility arguments to (precision, scale) tuples
- Simplified assertions in error test messages
@github-actions github-actions Bot added the functions Changes to functions implementation label May 7, 2026
@kosiew kosiew marked this pull request as ready for review May 7, 2026 06:45
) -> ScalarValue {
if lhs.is_null() {
let mut rhs_copy = rhs.clone();
rhs_copy.compact();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to keep the original comments regarding why only rhs is compacted

@Jefffrey
Copy link
Copy Markdown
Contributor

run benchmark min_max_bytes

@Jefffrey
Copy link
Copy Markdown
Contributor

run benchmark clickbench_extended

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4430401168-18-htr4n 6.12.68+ #1 SMP Wed Apr 1 02:23:28 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing macro-22061 (5b4b4b6) to cae03c9 (merge-base) diff
BENCH_NAME=min_max_bytes
BENCH_COMMAND=cargo bench --features=parquet --bench min_max_bytes
BENCH_FILTER=
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4430414863-19-dqcmt 6.12.68+ #1 SMP Wed Apr 1 02:23:28 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing macro-22061 (5b4b4b6) to cae03c9 (merge-base) diff using: clickbench_extended
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Criterion benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                macro-22061                            main
-----                -----------                            ----
min_max_bytes/10     1.00      3.9±0.02ms 19.8 MElem/sec    1.02      4.0±0.14ms 19.5 MElem/sec
min_max_bytes/100    1.00     76.5±1.09ms 10.2 MElem/sec    1.02     78.4±2.51ms 10.0 MElem/sec
min_max_bytes/150    1.00    123.9±1.20ms  9.5 MElem/sec    1.01    124.5±1.78ms  9.4 MElem/sec
min_max_bytes/20     1.00     13.3±0.83ms 11.8 MElem/sec    1.03     13.7±1.02ms 11.4 MElem/sec
min_max_bytes/200    1.00    159.2±1.24ms  9.8 MElem/sec    1.01    161.5±6.19ms  9.7 MElem/sec
min_max_bytes/300    1.02    240.5±1.66ms  9.7 MElem/sec    1.00    235.0±3.56ms 10.0 MElem/sec
min_max_bytes/400    1.01    319.9±3.22ms  9.8 MElem/sec    1.00    316.3±6.12ms  9.9 MElem/sec
min_max_bytes/50     1.00     34.9±1.12ms 11.2 MElem/sec    1.06     37.0±2.81ms 10.6 MElem/sec
min_max_bytes/500    1.03    403.0±4.20ms  9.7 MElem/sec    1.00    390.9±2.09ms 10.0 MElem/sec

Resource Usage

base (merge-base)

Metric Value
Wall time 195.0s
Peak memory 4.5 GiB
Avg memory 4.4 GiB
CPU user 179.4s
CPU sys 33.5s
Peak spill 0 B

branch

Metric Value
Wall time 195.0s
Peak memory 4.5 GiB
Avg memory 4.4 GiB
CPU user 179.5s
CPU sys 32.6s
Peak spill 0 B

File an issue against this benchmark runner

@adriangbot
Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

Comparing HEAD and macro-22061
--------------------
Benchmark clickbench_extended.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Query     ┃                                     HEAD ┃                               macro-22061 ┃    Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ QQuery 0  │        764.76 / 771.61 ±3.77 / 775.30 ms │        756.26 / 776.94 ±13.56 / 794.59 ms │ no change │
│ QQuery 1  │        182.09 / 182.58 ±0.36 / 182.98 ms │         182.40 / 183.19 ±0.81 / 184.30 ms │ no change │
│ QQuery 2  │        448.75 / 451.35 ±1.73 / 453.77 ms │         455.00 / 456.25 ±0.95 / 457.47 ms │ no change │
│ QQuery 3  │        307.90 / 308.94 ±1.34 / 311.54 ms │         311.14 / 311.90 ±0.73 / 313.05 ms │ no change │
│ QQuery 4  │        658.57 / 665.47 ±6.51 / 676.40 ms │        649.69 / 665.68 ±10.08 / 680.39 ms │ no change │
│ QQuery 5  │ 9900.66 / 10218.13 ±280.50 / 10710.19 ms │ 10005.00 / 10374.39 ±315.34 / 10866.37 ms │ no change │
│ QQuery 6  │      984.82 / 999.23 ±16.06 / 1026.83 ms │     1000.80 / 1017.30 ±13.42 / 1037.35 ms │ no change │
│ QQuery 7  │       737.58 / 759.87 ±16.36 / 781.89 ms │        742.87 / 772.31 ±28.70 / 822.63 ms │ no change │
│ QQuery 8  │       376.68 / 405.01 ±53.65 / 512.28 ms │        375.83 / 389.33 ±10.16 / 407.38 ms │ no change │
│ QQuery 9  │    2837.75 / 2896.91 ±49.52 / 2954.89 ms │     2888.17 / 2977.56 ±64.67 / 3040.33 ms │ no change │
│ QQuery 10 │       631.55 / 655.36 ±29.34 / 710.76 ms │        623.38 / 636.44 ±10.73 / 651.99 ms │ no change │
│ QQuery 11 │    2341.26 / 2354.34 ±11.05 / 2373.99 ms │     2319.43 / 2377.30 ±48.80 / 2447.79 ms │ no change │
│ QQuery 12 │       190.78 / 210.78 ±37.13 / 285.01 ms │        191.70 / 203.94 ±21.85 / 247.60 ms │ no change │
│ QQuery 13 │       557.11 / 570.85 ±13.67 / 595.90 ms │         546.98 / 554.45 ±5.90 / 560.37 ms │ no change │
└───────────┴──────────────────────────────────────────┴───────────────────────────────────────────┴───────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary          ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)          │ 21450.42ms │
│ Total Time (macro-22061)   │ 21696.97ms │
│ Average Time (HEAD)        │  1532.17ms │
│ Average Time (macro-22061) │  1549.78ms │
│ Queries Faster             │          0 │
│ Queries Slower             │          0 │
│ Queries with No Change     │         14 │
│ Queries with Failure       │          0 │
└────────────────────────────┴────────────┘

Resource Usage

clickbench_extended — base (merge-base)

Metric Value
Wall time 110.0s
Peak memory 31.2 GiB
Avg memory 23.9 GiB
CPU user 1026.0s
CPU sys 42.5s
Peak spill 0 B

clickbench_extended — branch

Metric Value
Wall time 110.0s
Peak memory 30.2 GiB
Avg memory 24.1 GiB
CPU user 1029.2s
CPU sys 43.5s
Peak spill 0 B

File an issue against this benchmark runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor scalar min/max dispatch from macro arms to function-based logic

3 participants