Skip to content

Commit

Permalink
change value type to unique ptr (#1852)
Browse files Browse the repository at this point in the history
* change value type to unique ptr

* Fix Java and Node.js APIs

---------

Co-authored-by: Chang Liu <liuc223@gmail.com>
  • Loading branch information
andyfengHKU and mewim committed Jul 24, 2023
1 parent f6de8ea commit b181462
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 156 deletions.
6 changes: 3 additions & 3 deletions src/c_api/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ kuzu_value* kuzu_value_get_list_element(kuzu_value* value, uint64_t index) {
uint64_t kuzu_value_get_struct_num_fields(kuzu_value* value) {
auto val = static_cast<Value*>(value->_value);
auto data_type = val->getDataType();
return StructType::getNumFields(&data_type);
return StructType::getNumFields(data_type);
}

char* kuzu_value_get_struct_field_name(kuzu_value* value, uint64_t index) {
auto val = static_cast<Value*>(value->_value);
auto data_type = val->getDataType();
auto struct_field_name = StructType::getFields(&data_type)[index]->getName();
auto struct_field_name = StructType::getFields(data_type)[index]->getName();
auto* c_struct_field_name = (char*)malloc(sizeof(char) * (struct_field_name.size() + 1));
strcpy(c_struct_field_name, struct_field_name.c_str());
return c_struct_field_name;
Expand All @@ -177,7 +177,7 @@ kuzu_value* kuzu_value_get_recursive_rel_rel_list(kuzu_value* value) {

kuzu_logical_type* kuzu_value_get_data_type(kuzu_value* value) {
auto* c_data_type = (kuzu_logical_type*)malloc(sizeof(kuzu_logical_type));
c_data_type->_data_type = new LogicalType(static_cast<Value*>(value->_value)->getDataType());
c_data_type->_data_type = new LogicalType(*static_cast<Value*>(value->_value)->getDataType());
return c_data_type;
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/arrow/arrow_row_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void ArrowRowBatch::copyNonNullValue(
} break;
default: {
throw RuntimeException("Invalid data type " +
LogicalTypeUtils::dataTypeToString(value->dataType) +
LogicalTypeUtils::dataTypeToString(*value->dataType) +
" for arrow export.");
}
}
Expand Down Expand Up @@ -335,7 +335,7 @@ void ArrowRowBatch::templateCopyNullValue<LogicalTypeID::VAR_LIST>(
}

void ArrowRowBatch::copyNullValue(ArrowVector* vector, Value* value, std::int64_t pos) {
switch (value->dataType.getLogicalTypeID()) {
switch (value->dataType->getLogicalTypeID()) {
case LogicalTypeID::BOOL: {
templateCopyNullValue<LogicalTypeID::BOOL>(vector, pos);
} break;
Expand Down Expand Up @@ -377,7 +377,7 @@ void ArrowRowBatch::copyNullValue(ArrowVector* vector, Value* value, std::int64_
} break;
default: {
throw RuntimeException("Invalid data type " +
LogicalTypeUtils::dataTypeToString(value->dataType) +
LogicalTypeUtils::dataTypeToString(*value->dataType) +
" for arrow export.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ LogicalType& LogicalType::operator=(LogicalType&& other) noexcept {
return *this;
}

std::unique_ptr<LogicalType> LogicalType::copy() {
std::unique_ptr<LogicalType> LogicalType::copy() const {
auto dataType = std::make_unique<LogicalType>(typeID);
if (extraTypeInfo != nullptr) {
dataType->extraTypeInfo = extraTypeInfo->copy();
Expand Down
Loading

0 comments on commit b181462

Please sign in to comment.