Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datatype] fix equals method for udt datatypes across schema upgrades #531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "types.hpp"
#include "vector.hpp"

#include <algorithm>

namespace datastax { namespace internal { namespace core {

class Collection;
Expand Down Expand Up @@ -365,11 +367,15 @@ class UserType : public DataType {
return false;
}

if (fields_.size() != user_type->fields_.size()) {
return false;
}

for (size_t i = 0; i < fields_.size(); ++i) {
// UDT's can be considered equal as long as the mutual first fields shared
// between them are equal. UDT's are append only as far as fields go, so a
// newer 'version' of the UDT data type after a schema change event should be
// treated as equivalent in this scenario, by simply looking at the first N
// mutual fields they should share.
size_t min_fields_size = std::min(fields_.size(), user_type->fields_.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems reasonable to me. It does seem that after creating a type that a type can only be altered in the following ways:

  • Rename field: ALTER TYPE address RENAME zip TO zipcode AND street_name TO street
  • Add a field: ALTER TYPE address ADD country text

It'd be nice to have some tests that verify this is a correct assumption.

Copy link
Author

Choose a reason for hiding this comment

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

It'd be nice to have some tests that verify this is a correct assumption.

I'm not entirely sure how we would test that? Are you suggesting we try to test that the database rejects invalid DDL?

There is a third way, you can change the type of a field ALTER field_name TYPE new_cql_datatype - however, I think if you're doing this, you probably need to redeploy your application anyways since the types are changing.


for (size_t i = 0; i < min_fields_size; ++i) {
if (fields_[i].name != user_type->fields_[i].name ||
!fields_[i].type->equals(user_type->fields_[i].type)) {
return false;
Expand Down