Skip to content

CASSANALYTICS-216: CDC Avro schema conversion fails for UDTs with quoted names containing characters invalid in Avro - #255

Merged
bbotella merged 6 commits into
apache:trunkfrom
bbotella:CASSANALYTICS-216-quoted-names
Nov 17, 2026
Merged

bbotella merged 6 commits into
apache:trunkfrom
bbotella:CASSANALYTICS-216-quoted-names

Conversation

@bbotella

@bbotella bbotella commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Patch by Bernardo Botella; Reviewed by Jyothsna Konisa for CASSANALYTICS-216

@bbotella bbotella changed the title Sanitizes udt names CASSANALYTICS-216: CDC Avro schema conversion fails for UDTs with quoted names containing characters invalid in Avro Oct 20, 2026

@shruti-p-s shruti-p-s left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments, looks great otherwise, thank you!

if (totalSize + value.remaining() > truncateThreshold)
{
truncatedFields.add(field.columnName);
truncatedFields.add(column.name());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truncatedFields gets the Avro name here, but updateFields still carries the CQL name. Should updateFields use the Avro name too?

CqlField.CqlType type = typeLookup.apply(KeyspaceTypeKey.of(event.keyspace, field.columnType));
Object javaValue = JavaTypeConverter.deserialize(type, fieldValue);
update.put(field.columnName, AvroDataUtils.toAvro(javaValue, column.schema()));
update.put(column.name(), AvroDataUtils.toAvro(javaValue, column.schema()));

@shruti-p-s shruti-p-s Nov 5, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think field has the same split as the truncatedFields.

map.forEach((key, value) -> {
final String fieldName = key.toString(); // UDT key should always be the fieldName of type String
udtEntry.put(fieldName, toAvro(value, unwrapped.getField(fieldName).schema()));
Schema.Field udtField = AvroSchemas.field(unwrapped, fieldName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the read side has the same split: UdtConversion returns Avro-named keys, but toAvro now expects CQL field names here.

if (column.isPrimaryKeyColumn())
{
primaryKeys.add(column.name.toString());
primaryKeys.add(avroName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building on Shruti's comment on truncatedFields, the key lists have the same split. primary_keys, partition_keys, clustering_keys and static_columns now hold Avro names, while update_fields still holds CQL names. Whichever way we resolve it, could we use one convention across all of these lists and document it?

@jyothsnakonisa

jyothsnakonisa commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Thanks Bernardo, sanitizing at schema-build time and keeping the original in cqlName makes sense, and I like that valid names stay untouched.

My main concern is the a_b2 / a_b3 suffixes. Which suffix a column gets depends on the other columns. If someone drops "a-b", then "a+b" goes from a_b3 to a_b2, even though that column didn't change. Consumers reading a_b3 would break. Keyspaces my-ks and my_ks have a similar problem, because they end up with the same Avro namespace.

Would a reversible escape be simpler? Debezium's avro_unicode mode does this by replacing invalid characters with _uXXXX. Each name maps to exactly one Avro name regardless of the other columns, so we wouldn't need Scope or the fallback scan in AvroSchemas.field, and cqlName could become documentation for consumers instead of something the code relies on. The catch is that valid names containing _ would change. We could escape only the invalid characters to avoid that.

Related to this, the CQL-to-Avro mapping happens in a few places that don't share a call:

  • The converter uses Scope, but AvroGenericRecordTransformer calls AvroNames.sanitize(event.table) directly. With table "my-table" and UDT my_table in one keyspace, the converter would name the table my_table2 but the merged envelope would be my_table.
  • The AvroSchemas.field(...) lookup, the null check and update.put(column.name(), ...) are repeated in four classes. Only CdcEventUtils and AvroBaseRecordTransformer have a checkNotNull message, so the other two would throw a bare NPE.

It might be worth having one place that owns the name mapping, plus a shared putField(...) helper. What do you think?

@jyothsnakonisa

Copy link
Copy Markdown
Contributor

Thanks @bbotella for addressing comments, l reran CI let's merge the PR once the CI is green. Also please post Circle CI link

@bbotella
bbotella force-pushed the CASSANALYTICS-216-quoted-names branch from fa2e44f to 32bd39d Compare November 17, 2026 07:14
@bbotella
bbotella force-pushed the CASSANALYTICS-216-quoted-names branch from 32bd39d to 4dec299 Compare November 17, 2026 07:16
@bbotella
bbotella merged commit 894dcb2 into apache:trunk Nov 17, 2026
69 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants