{"record":{"id":"55dd64012a558ff5","repo":"apache/cassandra","slug":"s-is-not-a-valid-field-identifier-of-type-s","errorCode":null,"errorMessage":"%s is not a valid field identifier of type %s ","messagePattern":"(.+?) is not a valid field identifier of type (.+?) ","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":1162,"sourceCode":"\n            return MapSelector.newFactory(type, getMapEntries(cfm).stream()\n                                                                  .map(p -> Pair.create(p.left.newSelectorFactory(cfm, mapType.getKeysType(), defs, boundNames),\n                                                                                        p.right.newSelectorFactory(cfm, mapType.getValuesType(), defs, boundNames)))\n                                                                  .collect(Collectors.toList()));\n        }\n\n        private Factory newUdtSelectorFactory(TableMetadata cfm,\n                                              AbstractType<?> expectedType,\n                                              List<ColumnMetadata> defs,\n                                              VariableSpecifications boundNames)\n        {\n            UserType ut = (UserType) expectedType;\n            Map<FieldIdentifier, Factory> factories = new LinkedHashMap<>(ut.size());\n\n            for (Pair<Selectable.Raw, Selectable.Raw> raw : raws)\n            {\n                if (!(raw.left instanceof RawIdentifier))\n                    throw invalidRequest(\"%s is not a valid field identifier of type %s \",\n                                         raw.left,\n                                         ut.getNameAsString());\n\n                FieldIdentifier fieldName = ((RawIdentifier) raw.left).toFieldIdentifier();\n                int fieldPosition = ut.fieldPosition(fieldName);\n\n                if (fieldPosition == -1)\n                    throw invalidRequest(\"Unknown field '%s' in value of user defined type %s\",\n                                         fieldName,\n                                         ut.getNameAsString());\n\n                AbstractType<?> fieldType = ut.fieldType(fieldPosition);\n                factories.put(fieldName,\n                              raw.right.prepare(cfm).newSelectorFactory(cfm, fieldType, defs, boundNames));\n            }\n\n            return UserTypeSelector.newFactory(expectedType, factories);\n        }","sourceCodeStart":1144,"sourceCodeEnd":1180,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L1144-L1180","documentation":"When building a UDT selector from a UDT literal in the selection clause, the left side of a `{field: value}` pair is not a plain identifier, so it cannot be resolved to a field of the user type. Only RawIdentifier keys are valid field names. The request is rejected at prepare time.","triggerScenarios":"`SELECT (udt_type) {f(x):1} FROM t` or a computed/function-call expression used as the field key of a UDT literal; a quoted or nested expression where a simple field identifier is expected.","commonSituations":"Copy-paste typos in UDT literals; programmatically generated literals where keys are expressions rather than names; confused tuple syntax `{1,2}` vs UDT syntax `{field:val}`.","solutions":["Use a plain (possibly quoted) field name as the key: {street:'x'} instead of an expression key.","Check that the literal is a UDT literal and not intended as a tuple literal (tuples use (v1, v2) syntax).","Validate programmatically generated UDT literal keys are FieldIdentifier-compatible names."],"exampleFix":"// before\nSELECT (address) {street(x):'Main'} FROM t;\n// after\nSELECT (address) {street:'Main'} FROM t;","handlingStrategy":"validation","validationCode":"for (String key : literalKeys) if (!key.matches(\"[a-zA-Z_][a-zA-Z0-9_]*\") && !key.startsWith(\"\\\"\")) throw new IllegalArgumentException(\"UDT literal key must be a plain identifier: \" + key);","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"not a valid field identifier\")) { /* fix the UDT literal key to a plain identifier */ } else throw e; }","preventionTips":["Generate UDT literal keys from schema field names only.","Never interpolate expressions into the key position of UDT literals.","Distinguish tuple literal syntax from UDT literal syntax in query builders."],"tags":["cql","udt","literal","field-identifier"],"backgroundTag":"invalid-argument-format","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"}