{"record":{"id":"10624bd4285398f4","repo":"quickwit-oss/quickwit","slug":"utf8-downcast-failed","errorCode":null,"errorMessage":"Utf8 downcast failed","messagePattern":"Utf8 downcast failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-parquet-engine/src/sorted_series/mod.rs","lineNumber":340,"sourceCode":"    match array.data_type() {\n        DataType::Dictionary(_, _) => {\n            let dict = array\n                .as_any()\n                .downcast_ref::<DictionaryArray<Int32Type>>()\n                .ok_or_else(|| anyhow!(\"dictionary downcast failed for {:?}\", array.data_type()))?;\n            let key_idx = dict.keys().value(row) as usize;\n            let values = dict.values();\n            let str_values = values\n                .as_any()\n                .downcast_ref::<StringArray>()\n                .ok_or_else(|| anyhow!(\"dictionary values are not Utf8\"))?;\n            Ok(str_values.value(key_idx))\n        }\n        DataType::Utf8 => {\n            let arr = array\n                .as_any()\n                .downcast_ref::<StringArray>()\n                .ok_or_else(|| anyhow!(\"Utf8 downcast failed\"))?;\n            Ok(arr.value(row))\n        }\n        other => Err(anyhow!(\n            \"unsupported data type {:?} in sort schema tag column — only Dictionary(Int32, Utf8) \\\n             and Utf8 are supported\",\n            other\n        )),\n    }\n}\n\n/// Extract an i64 value from a column at the given row.\n///\n/// Panics (debug_assert) if the row is null — the caller must check first.\nfn extract_i64_value(array: &dyn Array, row: usize) -> i64 {\n    debug_assert!(\n        !array.is_null(row),\n        \"caller must check is_null before extract_i64_value\"\n    );","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-parquet-engine/src/sorted_series/mod.rs#L322-L358","documentation":"For non-dictionary tag columns, extract_string_value expects DataType::Utf8 and downcasts the Arrow array to StringArray. If the downcast fails despite the data type claiming Utf8 (a broken/inconsistent array, or LargeUtf8 that slipped past the match arm), this error is raised.","triggerScenarios":"encode_row_key hits a tag column with DataType::Utf8 whose underlying buffer cannot be downcast to StringArray — practically an internal inconsistency, or a LargeUtf8 array if the match were extended without a matching downcast.","commonSituations":"Arrow arrays constructed manually with mismatched data_type metadata and buffers, or LargeString arrays from other Arrow implementations.","solutions":["Check how the StringArray for this column was built — data_type() must match the actual buffers","Cast to Utf8 (arrow::compute::cast) before calling extract_string_value","Add a LargeUtf8 arm to extract_string_value if large string arrays occur in your pipeline","This is an invariant violation — file a bug with the array construction path if reproducible"],"exampleFix":"// before\nlet arr = array.as_any().downcast_ref::<StringArray>().ok_or_else(|| anyhow!(\"Utf8 downcast failed\"))?;\n// after\nlet arr = array.as_any().downcast_ref::<StringArray>()\n    .ok_or_else(|| anyhow!(\"Utf8 downcast failed: declared {:?} but buffers are not StringArray (len={}, nulls={})\", array.data_type(), array.len(), array.null_count()))?;","handlingStrategy":"type-guard","validationCode":"debug_assert_eq!(array.data_type(), &DataType::Utf8);\ndebug_assert!(array.as_any().downcast_ref::<StringArray>().is_some());","typeGuard":"fn is_string_array(array: &dyn Array) -> bool {\n    array.as_any().downcast_ref::<StringArray>().is_some()\n}","tryCatchPattern":"if let Err(e) = encode_row_key(...) {\n    if e.to_string().contains(\"Utf8 downcast failed\") { /* invariant violation: log array metadata, abort */ }\n}","preventionTips":["Only construct arrays where data_type() matches the concrete buffers","Use typed builders (StringArray::from) to avoid metadata/buffer drift","Cover row-key encoding with tests over every supported column type"],"tags":["arrow","downcast","utf8","row-key"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}