{"record":{"id":"feb4af65044b92e4","repo":"cube-js/cube","slug":"unexpected-value-for-type","errorCode":null,"errorMessage":"unexpected value {:?} for type {:?}","messagePattern":"unexpected value (.+?) for type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cubestore/cubestore/src/table/data.rs","lineNumber":246,"sourceCode":"            $v.as_str()\n        }};\n        (Bytes, $v: expr) => {{\n            $v.as_slice()\n        }};\n        ($tv_enum: tt, $v: expr) => {{\n            *$v\n        }};\n    }\n    macro_rules! append {\n        ($type: tt, $builder: tt, $tv_enum: tt $(, $arg:tt)*) => {{\n            let b = b.as_any_mut().downcast_mut::<$builder>().unwrap();\n            if is_null {\n                b.append_null();\n                return;\n            }\n            let v = match v {\n                TableValue::$tv_enum(v) => convert_value!($tv_enum, v),\n                other => panic!(\"unexpected value {:?} for type {:?}\", other, c),\n            };\n            b.append_value(v);\n        }};\n    }\n    match_column_type!(c, append)\n}\n\npub fn rows_to_columns(cols: &[Column], rows: &[Row]) -> Vec<ArrayRef> {\n    let mut builders = create_array_builders(&cols);\n    for r in rows {\n        append_row(&mut builders, &cols, r);\n    }\n    builders.into_iter().map(|mut b| b.finish()).collect_vec()\n}\n\npub fn to_stream(r: RecordBatch) -> SendableRecordBatchStream {\n    let schema = r.schema();\n    // TaskContext::default is OK here because it's a plain memory exec.","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubestore/cubestore/src/table/data.rs#L228-L264","documentation":"append_value panics when a TableValue handed to a typed column builder is of a different variant than the column's declared type (other than null). The macro-generated match only accepts values matching the column enum; anything else is a programming/data bug.","triggerScenarios":"Writing a result/import row where a value's TableValue variant doesn't match the column type — e.g. append_csv_value importing a string into an Int column, or write_group_result_row emitting an aggregation result of the wrong type.","commonSituations":"CSV import with inconsistent column values; custom ingestion code pushing uncoerced values; aggregation producing a type different from the target column (e.g. Sum of Decimal into Int column).","solutions":["Coerce values to the declared column type before appending (parse strings, cast numbers)","Fix the ingestion/import path so each column receives values of its declared type","Verify pre-aggregation rollup column types match the aggregate function's result type","Re-check source data for malformed rows breaking type inference"],"exampleFix":"// before\nbuilder.append_value(TableValue::String(s)); // column is Int\n// after\nbuilder.append_value(TableValue::Int(s.parse::<i64>().expect(\"invalid int\")));","handlingStrategy":"validation","validationCode":"fn coerce_for_column(v: TableValue, col: ColumnType) -> Result<TableValue, String> {\n    match (&v, col) {\n        (TableValue::String(s), ColumnType::Int) => s.parse::<i64>().map(TableValue::Int).map_err(|e| e.to_string()),\n        (TableValue::Int(_), ColumnType::Int) | (TableValue::String(_), ColumnType::String) => Ok(v),\n        (other, c) => Err(format!(\"value {:?} does not match column type {:?}\", other, c)),\n    }\n}","typeGuard":"fn matches_column(v: &TableValue, col: &ColumnType) -> bool {\n    matches!((v, col), (TableValue::Int(_), ColumnType::Int) | (TableValue::String(_), ColumnType::String))\n}","tryCatchPattern":null,"preventionTips":["Coerce every value to the target column type before appending","Test import pipelines against real messy data","Match aggregate result types to rollup column types"],"tags":["cubestore","panic","type-mismatch","ingestion"],"backgroundTag":"type-mismatch-panic","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}