databendlabs/databend · error

_ => unreachable!()

Error message

_ => unreachable!()

What it means

`AggregatedScatter::scatter_by_rows` panics on any `AggregateMeta` variant other than Serialized, AggregateFunctionArgument (if handled), or AggregatePayload. Row-based scatter expects only the metadata variants that carry per-partition data it can redistribute; encountering another variant (e.g. BucketSpilled or an empty/legacy variant) breaks the scatter invariant.

Solutions

  1. Check whether the failing query uses row-based aggregate shuffle with spilling; try bucket-based shuffle mode or disable spilling to avoid the unsupported variant
  2. Log the offending `AggregateMeta` variant to identify which path produced it
  3. Match the variant explicitly and return an `ErrorCode::Internal` describing it instead of a bare panic
  4. Upgrade Databend — scatter handling for spilled/mixed partitions is an area of active fixes

Example fix

// before
_ => unreachable!(),
// after
other => Err(ErrorCode::Internal(format!(
    "scatter_by_rows does not support AggregateMeta variant: {:?}", other))),
Defensive patterns

Strategy: type-guard

Validate before calling

if matches!(meta, AggregateMeta::BucketSpilled(_) | AggregateMeta::Serialized(_)) && scatter_mode == Row { return Err(ErrorCode::Internal("unsupported AggregateMeta variant for row scatter")); }

Type guard

fn scatters_by_rows(m: &AggregateMeta) -> bool { matches!(m, AggregateMeta::AggregatePayload(_) | AggregateMeta::Serialized(_)) }

Prevention

When it happens

Trigger: Calling `scatter` (which routes to `scatter_by_rows` in row shuffle mode) with an `AggregateMeta` fragment whose variant is not supported by row-based scattering — typically fragments containing spilled-bucket state or unexpected metadata during distributed row-mode aggregation.

Common situations: Distributed aggregation with row-based shuffle combined with spilling or mixed partition states; planner/executor combinations that deliver unsupported AggregateMeta variants to the scatter stage.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/9bcbe0fef4920d39. Report an issue: GitHub.

Appendix: source

Thrown at src/query/service/src/pipelines/processors/transforms/aggregator/serde/aggregate_scatter.rs:238

                            }
                        }
                    }

                    Ok(partitions
                        .into_iter()
                        .map(|data| AggregateMeta::Partitioned {
                            bucket,
                            data: PartitionedData::Mixed(data),
                        })
                        .collect())
                }
            },
            AggregateMeta::AggregatePayload(p) => Ok(self
                .scatter_payload(p.bucket, p.payload, p.max_partition_count)
                .into_iter()
                .map(AggregateMeta::AggregatePayload)
                .collect()),
            _ => unreachable!(),
        }
    }

    fn scatter_payload(
        &self,
        bucket: isize,
        payload: Payload,
        max_partition_count: usize,
    ) -> Vec<AggregatePayload> {
        payload
            .scatter_into_buckets(self.buckets)
            .into_iter()
            .map(|payload| AggregatePayload {
                bucket,
                payload,
                max_partition_count,
            })
            .collect()

View on GitHub (pinned to 288d84d76e)