apache/cassandra · error · InvalidRequestException

Duplicate field name

Error message

Duplicate field name %s in type %s

What it means

After applying renames, Cassandra verifies that no two fields of the UDT share the same name; if any duplicate exists the rename is rejected. This prevents producing a UDT with ambiguous field names, which would break field lookup and serialization. Note the format string takes two placeholders but three arguments (keyspaceName extra) — the message rendered is 'Duplicate field name <name> in type <keyspaceName>'.

Solutions

  1. Pick a distinct new name that does not already exist on the type; check existing fields via DESCRIBE TYPE first
  2. Rename in two steps via intermediate unique names, e.g. a TO a_tmp, then a_tmp TO b after renaming/removing the conflicting field
  3. Remove or rename the conflicting existing field before reusing its name

Example fix

// before
ALTER TYPE myks.t RENAME a TO b; -- type already has field b
// after
ALTER TYPE myks.t RENAME a TO a2; -- or drop/rename field b first
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the target name is not already a field:
Row typeRow = session.execute("SELECT field_names FROM system_schema.types WHERE keyspace_name='myks' AND type_name='t'").one();
Set<String> names = new HashSet<>(typeRow.getList("field_names", String.class));
if (names.contains("b")) throw new IllegalArgumentException("field 'b' already exists on t");

Try / catch

try { session.execute(renameCql); }
catch (InvalidQueryException e) {
    if (e.getMessage().startsWith("Duplicate field name")) { /* choose a unique target name */ }
    else throw e;
}

Prevention

When it happens

Trigger: `ALTER TYPE myks.t RENAME a TO b` when the type already has a field `b` (the renamed field collides with an existing one); renaming two different fields to the same new name in one statement.

Common situations: Adding a field later with the name a rename will eventually target; bulk rename scripts where target names were not deduplicated; case variants ("b" vs b) overlooked since unquoted identifiers fold to lowercase.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/8db0e284222a4093. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java:237

            List<FieldIdentifier> fieldNames = new ArrayList<>(userType.fieldNames());

            renamedFields.forEach((oldName, newName) ->
            {
                int idx = userType.fieldPosition(oldName);
                if (idx < 0)
                {
                    if (!ifFieldExists)
                        throw ire("Unkown field %s in user type %s", oldName, userType.getCqlTypeName());
                    return;
                }
                fieldNames.set(idx, newName);
            });

            fieldNames.forEach(name ->
            {
                if (fieldNames.stream().filter(isEqual(name)).count() > 1)
                    throw ire("Duplicate field name %s in type %s", name, keyspaceName, userType.getCqlTypeName());
            });

            return new UserType(keyspaceName, userType.name, fieldNames, userType.fieldTypes(), true);
        }
    }

    private static final class AlterField extends AlterTypeStatement
    {
        private AlterField(String keyspaceName, String typeName, boolean ifExists)
        {
            super(keyspaceName, typeName, ifExists);
        }

        @Override
        public boolean compatibleWith(ClusterMetadata metadata)
        {
            return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
        }

View on GitHub (pinned to 88fd0f6a0e)