Skip to content

Commit

Permalink
[datatype] fix equals method for udt datatypes across schema upgrades
Browse files Browse the repository at this point in the history
Cherry-picked from #datastax/a5a34fb7e1bddab1456829acdb58eab4178d2060
  • Loading branch information
jhgg authored and jul-stas committed Jul 12, 2022
1 parent b28cde5 commit 739b87c
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit 739b87c

Please sign in to comment.