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

Splitup value.h #2025

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/c_api/connection.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include "binder/bound_statement_result.h"
#include "c_api/kuzu.h"
#include "common/exception/exception.h"
#include "common/types/value.h"
#include "main/kuzu.h"
#include "planner/logical_plan/logical_plan.h"

namespace kuzu {
namespace common {
class Value;
}
} // namespace kuzu

using namespace kuzu::common;
using namespace kuzu::main;

Expand Down
1 change: 1 addition & 0 deletions src/c_api/flat_tuple.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "processor/result/flat_tuple.h"

#include "c_api/kuzu.h"
#include "common/exception/exception.h"

using namespace kuzu::common;
using namespace kuzu::processor;
Expand Down
2 changes: 1 addition & 1 deletion src/c_api/prepared_statement.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "binder/bound_statement.h"
#include "c_api/kuzu.h"
#include "common/types/value.h"
#include "common/types/value/value.h"
#include "main/kuzu.h"
#include "planner/logical_plan/logical_plan.h"

Expand Down
6 changes: 5 additions & 1 deletion src/c_api/value.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include "common/types/value.h"
#include "common/types/value/value.h"

#include "c_api/kuzu.h"
#include "common/types/internal_id_t.h"
#include "common/types/types.h"
#include "common/types/value/nested.h"
#include "common/types/value/node.h"
#include "common/types/value/recursive_rel.h"
#include "common/types/value/rel.h"
#include "main/kuzu.h"

using namespace kuzu::common;
Expand Down
4 changes: 3 additions & 1 deletion src/common/arrow/arrow_row_batch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "common/arrow/arrow_row_batch.h"

#include "common/types/value.h"
#include "common/types/value/node.h"
#include "common/types/value/rel.h"
#include "common/types/value/value.h"
#include "storage/storage_utils.h"

namespace kuzu {
Expand Down
7 changes: 4 additions & 3 deletions src/common/types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
add_subdirectory(value)

add_library(kuzu_common_types
OBJECT
blob.cpp
date_t.cpp
dtime_t.cpp
internal_id_t.cpp
interval_t.cpp
ku_list.cpp
ku_string.cpp
value.cpp
timestamp_t.cpp
types.cpp
blob.cpp)
types.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_common_types>
Expand Down
11 changes: 11 additions & 0 deletions src/common/types/value/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(kuzu_common_types_value
OBJECT
nested.cpp
node.cpp
recursive_rel.cpp
rel.cpp
value.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_common_types_value>
PARENT_SCOPE)
21 changes: 21 additions & 0 deletions src/common/types/value/nested.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "common/types/value/nested.h"

#include "common/exception/runtime.h"
#include "common/types/value/value.h"

namespace kuzu {
namespace common {

uint32_t NestedVal::getChildrenSize(const Value* val) {
return val->childrenSize;
}

Value* NestedVal::getChildVal(const Value* val, uint32_t idx) {
if (idx > val->childrenSize) {
throw RuntimeException("NestedVal::getChildPointer index out of bound.");

Check warning on line 15 in src/common/types/value/nested.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/nested.cpp#L15

Added line #L15 was not covered by tests
}
return val->children[idx].get();
}

} // namespace common
} // namespace kuzu
87 changes: 87 additions & 0 deletions src/common/types/value/node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "common/types/value/node.h"

#include "common/constants.h"
#include "common/types/types.h"
#include "common/types/value/value.h"
#include "spdlog/fmt/fmt.h"

namespace kuzu {
namespace common {

std::vector<std::pair<std::string, std::unique_ptr<Value>>> NodeVal::getProperties(

Check warning on line 11 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L11

Added line #L11 was not covered by tests
const Value* val) {
throwIfNotNode(val);

Check warning on line 13 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L13

Added line #L13 was not covered by tests
std::vector<std::pair<std::string, std::unique_ptr<Value>>> properties;
auto fieldNames = StructType::getFieldNames(val->dataType.get());
for (auto i = 0u; i < val->childrenSize; ++i) {
auto currKey = fieldNames[i];
if (currKey == InternalKeyword::ID || currKey == InternalKeyword::LABEL) {

Check warning on line 18 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L16-L18

Added lines #L16 - L18 were not covered by tests
continue;
}
properties.emplace_back(currKey, val->children[i]->copy());

Check warning on line 21 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L21

Added line #L21 was not covered by tests
}
return properties;
}

Check warning on line 24 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L23-L24

Added lines #L23 - L24 were not covered by tests

uint64_t NodeVal::getNumProperties(const Value* val) {
throwIfNotNode(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
return fieldNames.size() - OFFSET;
}

std::string NodeVal::getPropertyName(const Value* val, uint64_t index) {
throwIfNotNode(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
if (index >= fieldNames.size() - OFFSET) {
return "";

Check warning on line 36 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L36

Added line #L36 was not covered by tests
}
return fieldNames[index + OFFSET];
}

Value* NodeVal::getPropertyVal(const Value* val, uint64_t index) {
throwIfNotNode(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
if (index >= fieldNames.size() - OFFSET) {
return nullptr;
}
return val->children[index + OFFSET].get();
}

Value* NodeVal::getNodeIDVal(const Value* val) {
throwIfNotNode(val);
auto fieldIdx = StructType::getFieldIdx(val->dataType.get(), InternalKeyword::ID);
return val->children[fieldIdx].get();
}

Value* NodeVal::getLabelVal(const Value* val) {
throwIfNotNode(val);
auto fieldIdx = StructType::getFieldIdx(val->dataType.get(), InternalKeyword::LABEL);
return val->children[fieldIdx].get();
}

nodeID_t NodeVal::getNodeID(const Value* val) {
throwIfNotNode(val);
auto nodeIDVal = getNodeIDVal(val);
return nodeIDVal->getValue<nodeID_t>();
}

std::string NodeVal::getLabelName(const Value* val) {
throwIfNotNode(val);
auto labelVal = getLabelVal(val);
return labelVal->getValue<std::string>();
}

std::string NodeVal::toString(const Value* val) {
throwIfNotNode(val);
return val->toString();
}

void NodeVal::throwIfNotNode(const Value* val) {
if (val->dataType->getLogicalTypeID() != LogicalTypeID::NODE) {
auto actualType = LogicalTypeUtils::dataTypeToString(val->dataType->getLogicalTypeID());
throw Exception(fmt::format("Expected NODE type, but got {} type", actualType));

Check warning on line 82 in src/common/types/value/node.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/node.cpp#L81-L82

Added lines #L81 - L82 were not covered by tests
}
}

} // namespace common
} // namespace kuzu
29 changes: 29 additions & 0 deletions src/common/types/value/recursive_rel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "common/types/value/recursive_rel.h"

#include "common/exception/exception.h"
#include "common/types/types.h"
#include "common/types/value/value.h"
#include "spdlog/fmt/fmt.h"

namespace kuzu {
namespace common {

Value* RecursiveRelVal::getNodes(const Value* val) {
throwIfNotRecursiveRel(val);
return val->children[0].get();
}

Value* RecursiveRelVal::getRels(const Value* val) {
throwIfNotRecursiveRel(val);
return val->children[1].get();
}

void RecursiveRelVal::throwIfNotRecursiveRel(const Value* val) {
if (val->dataType->getLogicalTypeID() != LogicalTypeID::RECURSIVE_REL) {
auto actualType = LogicalTypeUtils::dataTypeToString(val->dataType->getLogicalTypeID());
throw Exception(fmt::format("Expected RECURSIVE_REL type, but got {} type", actualType));

Check warning on line 24 in src/common/types/value/recursive_rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/recursive_rel.cpp#L23-L24

Added lines #L23 - L24 were not covered by tests
}
}

} // namespace common
} // namespace kuzu
91 changes: 91 additions & 0 deletions src/common/types/value/rel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "common/types/value/rel.h"

#include "common/constants.h"
#include "common/types/value/value.h"
#include "spdlog/fmt/fmt.h"

namespace kuzu {
namespace common {

std::vector<std::pair<std::string, std::unique_ptr<Value>>> RelVal::getProperties(

Check warning on line 10 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L10

Added line #L10 was not covered by tests
const Value* val) {
throwIfNotRel(val);

Check warning on line 12 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L12

Added line #L12 was not covered by tests
std::vector<std::pair<std::string, std::unique_ptr<Value>>> properties;
auto fieldNames = StructType::getFieldNames(val->dataType.get());
for (auto i = 0u; i < val->childrenSize; ++i) {
auto currKey = fieldNames[i];
if (currKey == InternalKeyword::ID || currKey == InternalKeyword::LABEL ||
currKey == InternalKeyword::SRC || currKey == InternalKeyword::DST) {

Check warning on line 18 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L15-L18

Added lines #L15 - L18 were not covered by tests
continue;
}
auto currVal = val->children[i]->copy();
properties.emplace_back(currKey, std::move(currVal));
}
return properties;
}

Check warning on line 25 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L21-L25

Added lines #L21 - L25 were not covered by tests

uint64_t RelVal::getNumProperties(const Value* val) {
throwIfNotRel(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
return fieldNames.size() - OFFSET;
}

std::string RelVal::getPropertyName(const Value* val, uint64_t index) {
throwIfNotRel(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
if (index >= fieldNames.size() - OFFSET) {
return "";

Check warning on line 37 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L37

Added line #L37 was not covered by tests
}
return fieldNames[index + OFFSET];
}

Value* RelVal::getPropertyVal(const Value* val, uint64_t index) {
throwIfNotRel(val);
auto fieldNames = StructType::getFieldNames(val->dataType.get());
if (index >= fieldNames.size() - OFFSET) {
return nullptr;
}
return val->children[index + OFFSET].get();
}

Value* RelVal::getSrcNodeIDVal(const Value* val) {
auto fieldIdx = StructType::getFieldIdx(val->dataType.get(), InternalKeyword::SRC);
return val->children[fieldIdx].get();
}

Value* RelVal::getDstNodeIDVal(const Value* val) {
auto fieldIdx = StructType::getFieldIdx(val->dataType.get(), InternalKeyword::DST);
return val->children[fieldIdx].get();
}

nodeID_t RelVal::getSrcNodeID(const Value* val) {
throwIfNotRel(val);
auto srcNodeIDVal = getSrcNodeIDVal(val);
return srcNodeIDVal->getValue<nodeID_t>();
}

nodeID_t RelVal::getDstNodeID(const Value* val) {
throwIfNotRel(val);
auto dstNodeIDVal = getDstNodeIDVal(val);
return dstNodeIDVal->getValue<nodeID_t>();
}

std::string RelVal::getLabelName(const Value* val) {
auto fieldIdx = StructType::getFieldIdx(val->dataType.get(), InternalKeyword::LABEL);
return val->children[fieldIdx]->getValue<std::string>();
}

std::string RelVal::toString(const Value* val) {
throwIfNotRel(val);
return val->toString();
}

void RelVal::throwIfNotRel(const Value* val) {
if (val->dataType->getLogicalTypeID() != LogicalTypeID::REL) {
auto actualType = LogicalTypeUtils::dataTypeToString(val->dataType->getLogicalTypeID());
throw Exception(fmt::format("Expected REL type, but got {} type", actualType));

Check warning on line 86 in src/common/types/value/rel.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/types/value/rel.cpp#L85-L86

Added lines #L85 - L86 were not covered by tests
}
}

} // namespace common
} // namespace kuzu
Loading