Skip to content

Commit

Permalink
Fix on review
Browse files Browse the repository at this point in the history
  • Loading branch information
manh9203 committed Apr 1, 2024
1 parent c908d5d commit 6e00d12
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
53 changes: 30 additions & 23 deletions src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ uint32_t PhysicalTypeUtils::getFixedTypeSize(PhysicalTypeID physicalType) {
}
}

bool ListTypeInfo::operator==(const ListTypeInfo& other) const {
return *childType == *other.childType;
bool ListTypeInfo::operator==(const ExtraTypeInfo& other) const {
const ListTypeInfo* otherListTypeInfo =
ku_dynamic_cast<const ExtraTypeInfo*, const ListTypeInfo*>(&other);
if (otherListTypeInfo) {
return *childType == *otherListTypeInfo->childType;
}
return false;
}

std::unique_ptr<ExtraTypeInfo> ListTypeInfo::copy() const {
Expand All @@ -114,8 +119,14 @@ void ListTypeInfo::serializeInternal(Serializer& serializer) const {
childType->serialize(serializer);
}

bool ArrayTypeInfo::operator==(const ArrayTypeInfo& other) const {
return *childType == *other.childType && numElements == other.numElements;
bool ArrayTypeInfo::operator==(const ExtraTypeInfo& other) const {
const ArrayTypeInfo* otherArrayTypeInfo =
ku_dynamic_cast<const ExtraTypeInfo*, const ArrayTypeInfo*>(&other);
if (otherArrayTypeInfo) {
return *childType == *otherArrayTypeInfo->childType &&
numElements == otherArrayTypeInfo->numElements;
}
return false;
}

std::unique_ptr<ExtraTypeInfo> ArrayTypeInfo::deserialize(Deserializer& deserializer) {
Expand Down Expand Up @@ -225,16 +236,21 @@ std::vector<const StructField*> StructTypeInfo::getStructFields() const {
return structFields;
}

bool StructTypeInfo::operator==(const StructTypeInfo& other) const {
if (fields.size() != other.fields.size()) {
return false;
}
for (auto i = 0u; i < fields.size(); ++i) {
if (fields[i] != other.fields[i]) {
bool StructTypeInfo::operator==(const ExtraTypeInfo& other) const {
const StructTypeInfo* otherStructTypeInfo =
ku_dynamic_cast<const ExtraTypeInfo*, const StructTypeInfo*>(&other);
if (otherStructTypeInfo) {
if (fields.size() != otherStructTypeInfo->fields.size()) {
return false;
}
for (auto i = 0u; i < fields.size(); ++i) {
if (fields[i] != otherStructTypeInfo->fields[i]) {
return false;
}
}
return true;
}
return true;
return false;
}

std::unique_ptr<ExtraTypeInfo> StructTypeInfo::deserialize(Deserializer& deserializer) {
Expand Down Expand Up @@ -288,19 +304,10 @@ bool LogicalType::operator==(const LogicalType& other) const {
if (typeID != other.typeID) {
return false;
}
switch (other.getPhysicalType()) {
case PhysicalTypeID::LIST:
return *ku_dynamic_cast<ExtraTypeInfo*, ListTypeInfo*>(extraTypeInfo.get()) ==
*ku_dynamic_cast<ExtraTypeInfo*, ListTypeInfo*>(other.extraTypeInfo.get());
case PhysicalTypeID::ARRAY:
return *ku_dynamic_cast<ExtraTypeInfo*, ArrayTypeInfo*>(extraTypeInfo.get()) ==
*ku_dynamic_cast<ExtraTypeInfo*, ArrayTypeInfo*>(other.extraTypeInfo.get());
case PhysicalTypeID::STRUCT:
return *ku_dynamic_cast<ExtraTypeInfo*, StructTypeInfo*>(extraTypeInfo.get()) ==
*ku_dynamic_cast<ExtraTypeInfo*, StructTypeInfo*>(other.extraTypeInfo.get());
default:
return true;
if (extraTypeInfo) {
return *extraTypeInfo == *other.extraTypeInfo;
}
return true;
}

bool LogicalType::operator!=(const LogicalType& other) const {
Expand Down
8 changes: 5 additions & 3 deletions src/include/common/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class ExtraTypeInfo {

inline void serialize(Serializer& serializer) const { serializeInternal(serializer); }

virtual bool operator==(const ExtraTypeInfo& other) const = 0;

virtual std::unique_ptr<ExtraTypeInfo> copy() const = 0;

protected:
Expand All @@ -187,7 +189,7 @@ class ListTypeInfo : public ExtraTypeInfo {
explicit ListTypeInfo(std::unique_ptr<LogicalType> childType)
: childType{std::move(childType)} {}
inline LogicalType* getChildType() const { return childType.get(); }
bool operator==(const ListTypeInfo& other) const;
bool operator==(const ExtraTypeInfo& other) const override;
std::unique_ptr<ExtraTypeInfo> copy() const override;

static std::unique_ptr<ExtraTypeInfo> deserialize(Deserializer& deserializer);
Expand All @@ -205,7 +207,7 @@ class ArrayTypeInfo : public ListTypeInfo {
explicit ArrayTypeInfo(std::unique_ptr<LogicalType> childType, uint64_t numElements)
: ListTypeInfo{std::move(childType)}, numElements{numElements} {}
inline uint64_t getNumElements() const { return numElements; }
bool operator==(const ArrayTypeInfo& other) const;
bool operator==(const ExtraTypeInfo& other) const override;
static std::unique_ptr<ExtraTypeInfo> deserialize(Deserializer& deserializer);
std::unique_ptr<ExtraTypeInfo> copy() const override;

Expand Down Expand Up @@ -254,7 +256,7 @@ class StructTypeInfo : public ExtraTypeInfo {
std::vector<LogicalType*> getChildrenTypes() const;
std::vector<std::string> getChildrenNames() const;
std::vector<const StructField*> getStructFields() const;
bool operator==(const kuzu::common::StructTypeInfo& other) const;
bool operator==(const ExtraTypeInfo& other) const override;

static std::unique_ptr<ExtraTypeInfo> deserialize(Deserializer& deserializer);
std::unique_ptr<ExtraTypeInfo> copy() const override;
Expand Down
1 change: 1 addition & 0 deletions src/include/common/vector/value_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct KUZU_API BlobVector {
}
};

// Currently, ListVector is used for both VAR_LIST and ARRAY physical type
class KUZU_API ListVector {
public:
static void setDataVector(const ValueVector* vector, std::shared_ptr<ValueVector> dataVector) {
Expand Down

0 comments on commit 6e00d12

Please sign in to comment.