Skip to content

Commit 739b87c

Browse files
jhggjul-stas
authored andcommitted
[datatype] fix equals method for udt datatypes across schema upgrades
Cherry-picked from #datastax/a5a34fb7e1bddab1456829acdb58eab4178d2060
1 parent b28cde5 commit 739b87c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/data_type.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "types.hpp"
2929
#include "vector.hpp"
3030

31+
#include <algorithm>
32+
3133
namespace datastax { namespace internal { namespace core {
3234

3335
class Collection;
@@ -365,11 +367,15 @@ class UserType : public DataType {
365367
return false;
366368
}
367369

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

372-
for (size_t i = 0; i < fields_.size(); ++i) {
371+
// UDT's can be considered equal as long as the mutual first fields shared
372+
// between them are equal. UDT's are append only as far as fields go, so a
373+
// newer 'version' of the UDT data type after a schema change event should be
374+
// treated as equivalent in this scenario, by simply looking at the first N
375+
// mutual fields they should share.
376+
size_t min_fields_size = std::min(fields_.size(), user_type->fields_.size());
377+
378+
for (size_t i = 0; i < min_fields_size; ++i) {
373379
if (fields_[i].name != user_type->fields_[i].name ||
374380
!fields_[i].type->equals(user_type->fields_[i].type)) {
375381
return false;

0 commit comments

Comments
 (0)