{"record":{"id":"57873210d60a3651","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-578732","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/query/sql/src/planner/semantic/type_check/variant.rs","lineNumber":519,"sourceCode":"                        if idx as usize > fields_type.len() {\n                            return Err(ErrorCode::SemanticError(format!(\n                                \"tuple index {} is out of bounds for length {}\",\n                                idx,\n                                fields_type.len()\n                            )));\n                        }\n                        (idx - 1) as usize\n                    }\n                    Literal::String(name) => match fields_name.iter().position(|k| k == &name) {\n                        Some(idx) => idx,\n                        None => {\n                            return Err(ErrorCode::SemanticError(format!(\n                                \"tuple name `{}` does not exist, available names are: {:?}\",\n                                name, &fields_name\n                            )));\n                        }\n                    },\n                    _ => unreachable!(),\n                };\n                table_data_type = fields_type.get(idx).unwrap().clone();\n                let return_type =\n                    ScalarExpr::passthrough_nullable_type(DataType::from(&table_data_type), [\n                        &scalar,\n                    ]);\n                scalar = FunctionCall {\n                    span: expr_span,\n                    func_name: \"get\".to_string(),\n                    params: vec![Scalar::Number(NumberScalar::Int64((idx + 1) as i64))],\n                    arguments: vec![scalar.clone()],\n                    return_type: Box::new(return_type),\n                }\n                .into();\n                continue;\n            }\n            let box (path_scalar, _) = self.resolve_literal(span, &path_lit)?;\n            table_data_type = match table_data_type {","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/sql/src/planner/semantic/type_check/variant.rs#L501-L537","documentation":"In resolve_map_access_from_scalar, when accessing a tuple field by name or index on a scalar value, the code matches on the resolved TableDataType and panics with `unreachable!()` for any type that is not a tuple-like structure. It assumes map/tuple access is only routed here for struct (tuple) types; any other type reaching this arm is a type-checking gap.","triggerScenarios":"Bracket access like expr['field'] or expr[0] on a Variant/Object value whose inferred table data type is neither Tuple nor a struct-backed type — e.g. accessing named fields on a Map or Array-typed scalar, or on an object key when the column's schema type drifted from the actual JSON shape.","commonSituations":"Semi-structured (JSON/VARIANT) columns where the inferred object/tuple metadata is stale or wrong after schema inference; queries like col['key'] on columns typed as MAP rather than OBJECT; accessing tuple fields by name on values inferred as arrays.","solutions":["Check the column's declared type with SELECT typeof(col); use the access syntax that matches it (col['k'] for maps, col:k or col['name'] for objects/tuples)","Cast explicitly to the expected type before access: CAST(col AS OBJECT('a' INT)) or CAST(col AS MAP(VARCHAR, VARIANT))","If the column type metadata is wrong, correct the table schema or re-ingest with the proper type","If a genuine Tuple triggers the panic, report a planner bug with the schema and query"],"exampleFix":"// before: name access on a Map-typed column\nSELECT obj['name'] FROM t; -- obj is MAP(VARCHAR, VARIANT)\n// after: cast or use map-appropriate access\nSELECT obj['name']::VARIANT FROM t; -- works for Map; or CAST to OBJECT first","handlingStrategy":"type-guard","validationCode":"SELECT typeof(col) FROM t LIMIT 1; -- confirm OBJECT/TUPLE before name-based access","typeGuard":"fn supports_named_field_access(ty: &str) -> bool {\n    ty.starts_with(\"TUPLE(\") || ty.starts_with(\"OBJECT(\")\n}","tryCatchPattern":null,"preventionTips":["Confirm column types with typeof()/DESCRIBE before using bracket access","Cast VARIANT/OBJECT explicitly with typed casts before field access","Fix schema metadata drift at the table level instead of working around it in queries"],"tags":["internal-invariant","type-checking","variant","tuple-access"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}