cube-js/cube · error

Can't compare {:?} to {:?}

Error message

Can't compare {:?} to {:?}

What it means

CubeStore panics when cmp_same_types is asked to compare two TableValueR values whose variants differ (e.g. Int vs String). The match arms only handle same-type pairs; any mixed-type pair falls to the catch-all arm. It indicates a column-type mismatch, usually corrupt or mislabeled data in a partition/row key.

Source

Thrown at rust/cubestore/cubestore/src/table/data.rs:135

    }
    Ordering::Equal
}

pub fn cmp_same_types(l: &TableValueR, r: &TableValueR) -> Ordering {
    match (l, r) {
        (TableValueR::Null, TableValueR::Null) => Ordering::Equal,
        (TableValueR::Null, _) => Ordering::Less,
        (_, TableValueR::Null) => Ordering::Greater,
        (TableValueR::String(a), TableValueR::String(b)) => a.cmp(b),
        (TableValueR::Int(a), TableValueR::Int(b)) => a.cmp(b),
        (TableValueR::Int96(a), TableValueR::Int96(b)) => a.cmp(b),
        (TableValueR::Decimal(a), TableValueR::Decimal(b)) => a.cmp(b),
        (TableValueR::Decimal96(a), TableValueR::Decimal96(b)) => a.cmp(b),
        (TableValueR::Float(a), TableValueR::Float(b)) => a.cmp(b),
        (TableValueR::Bytes(a), TableValueR::Bytes(b)) => a.cmp(b),
        (TableValueR::Timestamp(a), TableValueR::Timestamp(b)) => a.cmp(b),
        (TableValueR::Boolean(a), TableValueR::Boolean(b)) => a.cmp(b),
        (a, b) => panic!("Can't compare {:?} to {:?}", a, b),
    }
}

#[macro_export]
macro_rules! match_column_type {
    ($t: expr, $matcher: ident) => {{
        use datafusion::arrow::array::*;
        let t = $t;
        match t {
            ColumnType::String => $matcher!(String, StringBuilder, String),
            ColumnType::Int => $matcher!(Int, Int64Builder, Int),
            ColumnType::Int96 => $matcher!(Int96, Decimal128Builder, Int96),
            ColumnType::Bytes => $matcher!(Bytes, BinaryBuilder, Bytes),
            ColumnType::HyperLogLog(_) => $matcher!(HyperLogLog, BinaryBuilder, Bytes),
            ColumnType::Timestamp => $matcher!(Timestamp, TimestampMicrosecondBuilder, Timestamp),
            ColumnType::Boolean => $matcher!(Boolean, BooleanBuilder, Boolean),
            // scale and precision are used when creating but not when appending, hence underscore here.
            ColumnType::Decimal { scale: _scale, precision: _precision } => {

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Verify the column's declared type matches the actual data in the source (e.g. all ints, no strings) and re-import the affected table/partition
  2. Drop and rebuild affected pre-aggregations/partitions after correcting the schema
  3. Check for NaN or unexpected values (e.g. null-ish sentinels) in key columns used for sorting
  4. If reproducible, file a bug with the query and schema — mixed-type comparison should be prevented earlier by planning

Example fix

// before (ingest with mismatched type)
// column 'ts' declared Timestamp, CSV contains '2024-01-01' as quoted string in some rows
// after
// normalize values on import so stored variant matches the column type
Defensive patterns

Strategy: validation

Validate before calling

fn validate_column_types(types: &[ColumnType]) -> Result<(), String> {
    types.iter().try_for_each(|t| match t {
        ColumnType::Int | ColumnType::Float | ColumnType::String | ColumnType::Decimal | ColumnType::Timestamp | ColumnType::Boolean => Ok(()),
        other => Err(format!("unsupported column type {:?}", other)),
    })
}

Type guard

fn same_variant(a: &TableValueR, b: &TableValueR) -> bool {
    std::mem::discriminant(a) == std::mem::discriminant(b)
}

Prevention

When it happens

Trigger: Comparing values from columns with inconsistent logical types, e.g. a sort/partition key column whose stored values don't match the declared column type, or comparing a Decimal against a Timestamp during row-key (cmp_row_key) evaluation.

Common situations: Importing CSV data where a column's inferred/declared type differs from actual values; schema changes on an existing pre-aggregation/partition; bugs in query planning that compare key columns of different tables.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/0bc6858aad85fe50. Report an issue: GitHub.