Skip to content

Commit

Permalink
Fix nested value iteration (#1845)
Browse files Browse the repository at this point in the history
* X

* Fix iterator performance issue

* Fix C, Java, and Node.js API

* Fix value serialize

---------

Co-authored-by: Chang Liu <liuc223@gmail.com>
Co-authored-by: ziyi chen <chenziyi990424@gmail.com>
  • Loading branch information
3 people committed Jul 23, 2023
1 parent d6abf42 commit f6de8ea
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 293 deletions.
30 changes: 14 additions & 16 deletions src/c_api/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ void kuzu_value_destroy(kuzu_value* value) {
}

uint64_t kuzu_value_get_list_size(kuzu_value* value) {
auto& list_val = static_cast<Value*>(value->_value)->getListValReference();
return list_val.size();
return NestedVal::getChildrenSize(static_cast<Value*>(value->_value));
}

kuzu_value* kuzu_value_get_list_element(kuzu_value* value, uint64_t index) {
auto& list_val = static_cast<Value*>(value->_value)->getListValReference();
if (index >= list_val.size()) {
auto listValue = static_cast<Value*>(value->_value);
if (index >= NestedVal::getChildrenSize(listValue)) {
return nullptr;
}
auto& list_element = list_val[index];
auto val = list_element.get();
auto val = NestedVal::getChildVal(listValue, index);
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = val;
c_value->_is_owned_by_cpp = true;
Expand Down Expand Up @@ -262,16 +260,16 @@ char* kuzu_value_to_string(kuzu_value* value) {
kuzu_value* kuzu_node_val_get_id_val(kuzu_value* node_val) {
auto id_val = NodeVal::getNodeIDVal(static_cast<Value*>(node_val->_value));
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = id_val.release();
c_value->_is_owned_by_cpp = false;
c_value->_value = id_val;
c_value->_is_owned_by_cpp = true;
return c_value;
}

kuzu_value* kuzu_node_val_get_label_val(kuzu_value* node_val) {
auto label_val = NodeVal::getLabelVal(static_cast<Value*>(node_val->_value));
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = label_val.release();
c_value->_is_owned_by_cpp = false;
c_value->_value = label_val;
c_value->_is_owned_by_cpp = true;
return c_value;
}

Expand Down Expand Up @@ -302,7 +300,7 @@ char* kuzu_node_val_get_property_name_at(kuzu_value* node_val, uint64_t index) {
}

kuzu_value* kuzu_node_val_get_property_value_at(kuzu_value* node_val, uint64_t index) {
auto value = NodeVal::getPropertyValueReference(static_cast<Value*>(node_val->_value), index);
auto value = NodeVal::getPropertyVal(static_cast<Value*>(node_val->_value), index);
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = value;
c_value->_is_owned_by_cpp = true;
Expand All @@ -319,16 +317,16 @@ char* kuzu_node_val_to_string(kuzu_value* node_val) {
kuzu_value* kuzu_rel_val_get_src_id_val(kuzu_value* rel_val) {
auto src_id_val = RelVal::getSrcNodeIDVal(static_cast<Value*>(rel_val->_value));
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = src_id_val.release();
c_value->_is_owned_by_cpp = false;
c_value->_value = src_id_val;
c_value->_is_owned_by_cpp = true;
return c_value;
}

kuzu_value* kuzu_rel_val_get_dst_id_val(kuzu_value* rel_val) {
auto dst_id_val = RelVal::getDstNodeIDVal(static_cast<Value*>(rel_val->_value));
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = dst_id_val.release();
c_value->_is_owned_by_cpp = false;
c_value->_value = dst_id_val;
c_value->_is_owned_by_cpp = true;
return c_value;
}

Expand Down Expand Up @@ -366,7 +364,7 @@ char* kuzu_rel_val_get_property_name_at(kuzu_value* rel_val, uint64_t index) {
}

kuzu_value* kuzu_rel_val_get_property_value_at(kuzu_value* rel_val, uint64_t index) {
auto value = RelVal::getPropertyValueReference(static_cast<Value*>(rel_val->_value), index);
auto value = RelVal::getPropertyVal(static_cast<Value*>(rel_val->_value), index);
auto* c_value = (kuzu_value*)malloc(sizeof(kuzu_value));
c_value->_value = value;
c_value->_is_owned_by_cpp = true;
Expand Down
26 changes: 13 additions & 13 deletions src/common/arrow/arrow_row_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::VAR_LIST>(
ArrowVector* vector, const main::DataTypeInfo& typeInfo, Value* value, std::int64_t pos) {
vector->data.resize((pos + 2) * sizeof(std::uint32_t));
auto offsets = (std::uint32_t*)vector->data.data();
auto numElements = value->nestedTypeVal.size();
auto numElements = value->childrenSize;
offsets[pos + 1] = offsets[pos] + numElements;
auto numChildElements = offsets[pos + 1] + 1;
auto currentNumBytesForChildValidity = vector->childData[0]->validity.size();
Expand All @@ -208,8 +208,8 @@ void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::VAR_LIST>(
LogicalType{typeInfo.childrenTypesInfo[0]->typeID}));
}
for (auto i = 0u; i < numElements; i++) {
appendValue(vector->childData[0].get(), *typeInfo.childrenTypesInfo[0],
value->nestedTypeVal[i].get());
appendValue(
vector->childData[0].get(), *typeInfo.childrenTypesInfo[0], value->children[i].get());
}
}

Expand All @@ -226,15 +226,15 @@ void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::INTERNAL_ID>(
template<>
void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::NODE>(
ArrowVector* vector, const main::DataTypeInfo& typeInfo, Value* value, std::int64_t pos) {
appendValue(vector->childData[0].get(), *typeInfo.childrenTypesInfo[0],
NodeVal::getNodeIDVal(value).get());
appendValue(vector->childData[1].get(), *typeInfo.childrenTypesInfo[1],
NodeVal::getLabelVal(value).get());
appendValue(
vector->childData[0].get(), *typeInfo.childrenTypesInfo[0], NodeVal::getNodeIDVal(value));
appendValue(
vector->childData[1].get(), *typeInfo.childrenTypesInfo[1], NodeVal::getLabelVal(value));
std::int64_t propertyId = 2;
auto numProperties = NodeVal::getNumProperties(value);
for (auto i = 0u; i < numProperties; i++) {
auto name = NodeVal::getPropertyName(value, i);
auto val = NodeVal::getPropertyValueReference(value, i);
auto val = NodeVal::getPropertyVal(value, i);
appendValue(
vector->childData[propertyId].get(), *typeInfo.childrenTypesInfo[propertyId], val);
propertyId++;
Expand All @@ -244,15 +244,15 @@ void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::NODE>(
template<>
void ArrowRowBatch::templateCopyNonNullValue<LogicalTypeID::REL>(
ArrowVector* vector, const main::DataTypeInfo& typeInfo, Value* value, std::int64_t pos) {
appendValue(vector->childData[0].get(), *typeInfo.childrenTypesInfo[0],
RelVal::getSrcNodeIDVal(value).get());
appendValue(vector->childData[1].get(), *typeInfo.childrenTypesInfo[1],
RelVal::getDstNodeIDVal(value).get());
appendValue(
vector->childData[0].get(), *typeInfo.childrenTypesInfo[0], RelVal::getSrcNodeIDVal(value));
appendValue(
vector->childData[1].get(), *typeInfo.childrenTypesInfo[1], RelVal::getDstNodeIDVal(value));
std::int64_t propertyId = 2;
auto numProperties = NodeVal::getNumProperties(value);
for (auto i = 0u; i < numProperties; i++) {
auto name = NodeVal::getPropertyName(value, i);
auto val = NodeVal::getPropertyValueReference(value, i);
auto val = NodeVal::getPropertyVal(value, i);
appendValue(
vector->childData[propertyId].get(), *typeInfo.childrenTypesInfo[propertyId], val);
propertyId++;
Expand Down
Loading

0 comments on commit f6de8ea

Please sign in to comment.