{"record":{"id":"fad70ed620251271","repo":"apache/cassandra","slug":"invalid-field-selection-s-of-type-s-is-not-a-us","errorCode":null,"errorMessage":"Invalid field selection: %s of type %s is not a user type","messagePattern":"Invalid field selection: (.+?) of type (.+?) is not a user type","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":567,"sourceCode":"            return String.format(\"%s.%s\", selected, field);\n        }\n\n        public Selector.Factory newSelectorFactory(TableMetadata table, AbstractType<?> expectedType, List<ColumnMetadata> defs, VariableSpecifications boundNames)\n        {\n            AbstractType<?> expectedUdtType = null;\n\n            // If the UDT is between parentheses, we know that it is not a tuple with a single element.\n            if (selected instanceof BetweenParenthesesOrWithTuple)\n            {\n                BetweenParenthesesOrWithTuple betweenParentheses = (BetweenParenthesesOrWithTuple) selected;\n                expectedUdtType = betweenParentheses.selectables.get(0).getExactTypeIfKnown(table.keyspace);\n            }\n\n            Selector.Factory factory = selected.newSelectorFactory(table, expectedUdtType, defs, boundNames);\n            AbstractType<?> type = factory.getReturnType().unwrap();\n            if (!type.isUDT())\n            {\n                throw new InvalidRequestException(\n                        String.format(\"Invalid field selection: %s of type %s is not a user type\",\n                                selected,\n                                type.asCQL3Type()));\n            }\n\n            UserType ut = (UserType) type;\n            int fieldIndex = ut.fieldPosition(field);\n            if (fieldIndex == -1)\n            {\n                throw new InvalidRequestException(String.format(\"%s of type %s has no field %s\",\n                        selected, type.asCQL3Type(), field));\n            }\n\n            return FieldSelector.newFactory(ut, fieldIndex, factory);\n        }\n\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L549-L585","documentation":"Field selection (col.field for user-defined types) requires the selected expression to have a UDT type. If the underlying selector's return type, unwrapped, is not a UserType, the field access is meaningless and the query is rejected.","triggerScenarios":"SELECT c.field FROM t where c is a plain column (e.g. text/int/collection) rather than a UDT, or where a wrapping function changed the return type away from the UDT.","commonSituations":"Copy-pasting field-selection syntax onto non-UDT columns, or forgetting that an intermediate function/cast changed the type so .field no longer applies.","solutions":["Verify the column type in DESCRIBE TABLE is a user-defined type","Apply field selection directly to the UDT column, not to a function result that returns a non-UDT","Use dot notation only for UDTs; index collections with [] instead"],"exampleFix":"// before\nSELECT address.city FROM t WHERE address IS text;\n// after\nALTER TABLE t ALTER ... / use a UDT: SELECT addr.city FROM t; // addr is an address UDT","handlingStrategy":"type-guard","validationCode":"AbstractType<?> t = col.getType().unwrap();\nif (!(t instanceof UserType)) throw new IllegalArgumentException(col + \" is not a UDT\");","typeGuard":"boolean isUdt(ColumnMetadata c) { return c.getType().unwrap() instanceof UserType; }","tryCatchPattern":null,"preventionTips":["Check the column type with DESCRIBE TABLE before field selection","Apply .field only to UDT columns","Beware function wrappers changing the receiver type"],"tags":["cql","udt","field-selection"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}