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 #63

Merged
merged 1 commit into from
Jul 12, 2022
Merged
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());

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