{"record":{"id":"a7bbc398cee95ecd","repo":"apache/cassandra","slug":"unkown-field-s-in-user-type-s","errorCode":null,"errorMessage":"Unkown field %s in user type %s","messagePattern":"Unkown field (.+?) in user type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java","lineNumber":228,"sourceCode":"                        .map(uda -> uda.name().toString())\n                        .collect(toList());\n\n            if (!dependentAggregates.isEmpty())\n            {\n                throw ire(\"Cannot alter user type %s as it is still used in INITCOND by aggregates %s\",\n                          userType.getCqlTypeName(),\n                          join(\", \", dependentAggregates));\n            }\n\n            List<FieldIdentifier> fieldNames = new ArrayList<>(userType.fieldNames());\n\n            renamedFields.forEach((oldName, newName) ->\n            {\n                int idx = userType.fieldPosition(oldName);\n                if (idx < 0)\n                {\n                    if (!ifFieldExists)\n                        throw ire(\"Unkown field %s in user type %s\", oldName, userType.getCqlTypeName());\n                    return;\n                }\n                fieldNames.set(idx, newName);\n            });\n\n            fieldNames.forEach(name ->\n            {\n                if (fieldNames.stream().filter(isEqual(name)).count() > 1)\n                    throw ire(\"Duplicate field name %s in type %s\", name, keyspaceName, userType.getCqlTypeName());\n            });\n\n            return new UserType(keyspaceName, userType.name, fieldNames, userType.fieldTypes(), true);\n        }\n    }\n\n    private static final class AlterField extends AlterTypeStatement\n    {\n        private AlterField(String keyspaceName, String typeName, boolean ifExists)","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java#L210-L246","documentation":"During ALTER TYPE ... RENAME, each requested old field name is looked up in the UDT; if it is not found and IF EXISTS was not given for the field, the rename fails with an InvalidRequest. Note the message contains a typo ('Unkown') and omits the keyspace argument in the format call relative to its message text — the real message will show only the field and type name plus an extra argument artifact.","triggerScenarios":"`ALTER TYPE myks.addr RENAME city TO town` where no field named `city` exists; misspelled field name; running against a keyspace/environment where the type has a different field set; case mismatch (CQL identifiers are case-sensitive in UDTs unless quoted).","commonSituations":"Typos in field names; quoting/case mistakes (city vs \"City\"); drift between environments (test vs prod schema); stale migration scripts after an earlier rename.","solutions":["Check the current fields with `DESCRIBE TYPE myks.addr` (or system_schema.types) and correct the old field name in the ALTER statement","Use the IF EXISTS clause (`ALTER TYPE ... RENAME city TO town IF EXISTS`) to make a missing field a no-op","Fix case sensitivity by quoting the identifier exactly as it was defined, e.g. RENAME \"City\" TO \"Town\""],"exampleFix":"// before\nALTER TYPE myks.addr RENAME city TO town; -- Unknown field city\n// after\nALTER TYPE myks.addr RENAME town_old TO town; -- use actual field name, or:\nALTER TYPE myks.addr RENAME city TO town IF EXISTS;","handlingStrategy":"validation","validationCode":"// Verify the field exists before renaming:\nRow typeRow = session.execute(\"SELECT field_names FROM system_schema.types WHERE keyspace_name='myks' AND type_name='addr'\").one();\nList<String> fields = typeRow.getList(\"field_names\", String.class);\nif (!fields.contains(\"city\")) throw new IllegalArgumentException(\"field 'city' does not exist on addr\");","typeGuard":null,"tryCatchPattern":"try { session.execute(renameCql); }\ncatch (InvalidQueryException e) {\n    if (e.getMessage().contains(\"Unkown field\")) { /* inspect DESCRIBE TYPE / system_schema.types and fix the name */ }\n    else throw e;\n}","preventionTips":["Run DESCRIBE TYPE (or query system_schema.types) to confirm exact field names before renaming","Remember UDT field identifiers are case-sensitive; quote identifiers to preserve case","Use IF EXISTS on renames when scripts must be idempotent across environments"],"tags":["cassandra","cql","udt","rename","typo"],"backgroundTag":"resource-not-found","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"}