Skip to content

Conversation

@Dekrate
Copy link

@Dekrate Dekrate commented Oct 23, 2025

Restrict BytesType compatibility to scalar types only

BytesType.isValueCompatibleWith() previously accepted all types,
including frozen collections and UDTs. This was incorrect because
converting collections or UDTs to raw bytes is nonsensical - it
allows reading raw serialized bytes which have no meaningful
interpretation.

This patch restricts BytesType to only accept simple scalar types
by checking !isCollection() && !isUDT() in isValueCompatibleWithInternal().

@driftx <- it was your task, I was happy to help!

BytesType.isValueCompatibleWith() previously accepted all types,
including frozen collections and UDTs. This was incorrect because
converting collections or UDTs to raw bytes is nonsensical - it
allows reading raw serialized bytes which have no meaningful
interpretation.

This patch restricts BytesType to only accept simple scalar types
by checking !isCollection() && !isUDT() in isValueCompatibleWithInternal().

patch by Dekrate for CASSANDRA-20982
Replace isCollection() && isUDT() checks with isMultiCell() for cleaner
code. Update error message in AlterTableStatement to more clearly indicate
that we're adding a column of incompatible type with a previously dropped
column, rather than suggesting the dropped column had the new type.

Update tests to match the new error message format.

patch by Dekrate for CASSANDRA-20982
@Dekrate
Copy link
Author

Dekrate commented Oct 27, 2025

@smiklosovic, done

return true;
// BytesType should only be compatible with simple scalar types, not with collections or UDTs
// because converting a collection or UDT to raw bytes is nonsensical
return !otherType.isMultiCell();
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this here will break cql CAST operations, which I think we still might want to allow since they are explicit, and different from finding a column you re-added contains junk bytes.

Also, isMultiCell will return false for frozen collections.

Copy link
Author

Choose a reason for hiding this comment

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

@driftx, should I revert to the first version?

return !otherType.isCollection() && !otherType.isUDT();

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