{"record":{"id":"6a306f05a742af10","repo":"xai-org/x-algorithm","slug":"not-listarray","errorCode":null,"errorMessage":"not ListArray","messagePattern":"not ListArray","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"bdsm/rust/abuse-v3-features/src/lib.rs","lineNumber":264,"sourceCode":"    for b in reader {\n        batches.push(b?);\n    }\n    if batches.is_empty() {\n        anyhow::bail!(\"empty\");\n    }\n    let batch = if batches.len() == 1 {\n        batches.into_iter().next().unwrap()\n    } else {\n        arrow::compute::concat_batches(&batches[0].schema(), &batches)?\n    };\n\n    let actions_col = batch\n        .column_by_name(\"user_actions\")\n        .ok_or_else(|| anyhow::anyhow!(\"no user_actions\"))?;\n    let list = actions_col\n        .as_any()\n        .downcast_ref::<ListArray>()\n        .ok_or_else(|| anyhow::anyhow!(\"not ListArray\"))?;\n    if list.is_empty() || list.is_null(0) {\n        anyhow::bail!(\"empty list\");\n    }\n\n    let vals = list.value(0);\n    let sa = vals\n        .as_any()\n        .downcast_ref::<StructArray>()\n        .ok_or_else(|| anyhow::anyhow!(\"not StructArray\"))?;\n    let total = sa.len();\n    if total == 0 {\n        anyhow::bail!(\"zero actions\");\n    }\n\n    let start = if total > seq_len { total - seq_len } else { 0 };\n    let take = total.min(seq_len);\n    let sl = sa.slice(start, take);\n    let sl = sl.as_any().downcast_ref::<StructArray>().unwrap();","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/bdsm/rust/abuse-v3-features/src/lib.rs#L246-L282","documentation":"After locating the 'user_actions' column, the code downcasts it to arrow::array::ListArray. If the column is any other Arrow type (e.g. LargeListArray, StructArray, or a plain non-nested type), the downcast returns None and this error fires. The producer must emit user_actions as a List array.","triggerScenarios":"Calling extract_batch where the user_actions column is typed as LargeList, Struct, or any non-List Arrow type — commonly after a producer migration to LargeListArray for >2B row support or a hand-built test batch using the wrong type.","commonSituations":"Arrow version upgrades where readers/writers default to LargeList, alternate producers writing struct-of-list instead of list-of-struct, or test fixtures constructing batches with mismatched types.","solutions":["Print the column's DataType (actions_col.data_type()) to see the actual type","If it is LargeListArray, either change the producer to emit ListArray or downcast to LargeListArray here","Regenerate/align the Arrow schema between producer and consumer (field type must be List(...))","Add an upfront schema check comparing the expected exact DataType before extraction"],"exampleFix":"// before\nlet list = actions_col\n    .as_any()\n    .downcast_ref::<ListArray>()\n    .ok_or_else(|| anyhow::anyhow!(\"not ListArray\"))?;\n\n// after\nlet list = actions_col\n    .as_any()\n    .downcast_ref::<ListArray>()\n    .ok_or_else(|| anyhow::anyhow!(\n        \"not ListArray: user_actions is {:?}\",\n        actions_col.data_type()\n    ))?;","handlingStrategy":"type-guard","validationCode":"// Check the column type before downcasting\nlet dt = batch.column_by_name(\"user_actions\").map(|c| c.data_type().clone());\nanyhow::ensure!(matches!(dt, Some(DataType::List(_))), \"user_actions must be List, got {dt:?}\");","typeGuard":"fn is_list_array(col: &ArrayRef) -> bool {\n    matches!(col.data_type(), DataType::List(_))\n}\n// or handle LargeList too:\nfn as_list(col: &ArrayRef) -> Option<&ListArray> {\n    col.as_any().downcast_ref::<ListArray>()\n}","tryCatchPattern":"// branch on the actual type instead of failing on downcast\nlet list = match actions_col.data_type() {\n    DataType::List(_) => actions_col.as_any().downcast_ref::<ListArray>().unwrap(),\n    DataType::LargeList(_) => /* convert or handle LargeListArray */,\n    other => anyhow::bail!(\"unsupported user_actions type: {other:?}\"),\n};","preventionTips":["Pin producer/consumer to the same arrow crate version","Centralize the expected Arrow schema in one shared constant/module","In tests, build batches via the shared schema helper rather than hand-rolled types"],"tags":["rust","arrow","downcast","type-mismatch"],"backgroundTag":"type-downcast-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}