Skip to content

Commit

Permalink
remove copyValue from ValueVectorUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Jun 17, 2023
1 parent 12aec42 commit b069813
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 95 deletions.
70 changes: 66 additions & 4 deletions src/common/vector/value_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ void ValueVector::copyFromRowData(uint32_t pos, const uint8_t* rowData) {
}
}

void ValueVector::copyFromVectorData(
uint8_t* dstData, const ValueVector* srcVector, const uint8_t* srcVectorData) {
assert(srcVector->dataType.getPhysicalType() == dataType.getPhysicalType());
switch (srcVector->dataType.getPhysicalType()) {
case PhysicalTypeID::STRUCT: {
StructVector::copyFromVectorData(this, dstData, srcVector, srcVectorData);
} break;
case PhysicalTypeID::VAR_LIST: {
ListVector::copyFromVectorData(this, dstData, srcVector, srcVectorData);
} break;
case PhysicalTypeID::STRING: {
StringVector::addString(this, *(ku_string_t*)dstData, *(ku_string_t*)srcVectorData);
} break;
default: {
memcpy(dstData, srcVectorData, srcVector->getNumBytesPerValue());
}
}
}

void ValueVector::resetAuxiliaryBuffer() {
switch (dataType.getPhysicalType()) {
case PhysicalTypeID::STRING: {
Expand Down Expand Up @@ -201,12 +220,12 @@ void StringVector::addString(

void ListVector::copyFromRowData(ValueVector* vector, uint32_t pos, const uint8_t* rowData) {
assert(vector->dataType.getPhysicalType() == PhysicalTypeID::VAR_LIST);
auto srcKuList = *(ku_list_t*)rowData;
auto& srcKuList = *(ku_list_t*)rowData;
auto srcNullBytes = reinterpret_cast<uint8_t*>(srcKuList.overflowPtr);
auto srcListValues = srcNullBytes + NullBuffer::getNumBytesForNullValues(srcKuList.size);
auto dstListEntry = ListVector::addList(vector, srcKuList.size);
auto dstListEntry = addList(vector, srcKuList.size);
vector->setValue<list_entry_t>(pos, dstListEntry);
auto resultDataVector = common::ListVector::getDataVector(vector);
auto resultDataVector = getDataVector(vector);
auto rowLayoutSize = LogicalTypeUtils::getRowLayoutSize(resultDataVector->dataType);
for (auto i = 0u; i < srcKuList.size; i++) {
auto dstListValuePos = dstListEntry.offset + i;
Expand All @@ -219,9 +238,30 @@ void ListVector::copyFromRowData(ValueVector* vector, uint32_t pos, const uint8_
}
}

void ListVector::copyFromVectorData(ValueVector* dstVector, uint8_t* dstData,
const ValueVector* srcVector, const uint8_t* srcData) {
auto& srcListEntry = *(common::list_entry_t*)(srcData);
auto& dstListEntry = *(common::list_entry_t*)(dstData);
dstListEntry = addList(dstVector, srcListEntry.size);
auto srcListData = getListValues(srcVector, srcListEntry);
auto srcDataVector = getDataVector(srcVector);
auto dstListData = getListValues(dstVector, dstListEntry);
auto dstDataVector = getDataVector(dstVector);
auto numBytesPerValue = srcDataVector->getNumBytesPerValue();
for (auto i = 0u; i < srcListEntry.size; i++) {
if (srcDataVector->isNull(srcListEntry.offset + i)) {
dstDataVector->setNull(dstListEntry.offset + i, true);
} else {
dstDataVector->copyFromVectorData(dstListData, srcDataVector, srcListData);
}
srcListData += numBytesPerValue;
dstListData += numBytesPerValue;
}
}

void StructVector::copyFromRowData(ValueVector* vector, uint32_t pos, const uint8_t* rowData) {
assert(vector->dataType.getPhysicalType() == PhysicalTypeID::STRUCT);
auto structFields = getFieldVectors(vector);
auto& structFields = getFieldVectors(vector);
auto structNullBytes = rowData;
auto structValues = structNullBytes + NullBuffer::getNumBytesForNullValues(structFields.size());
for (auto i = 0u; i < structFields.size(); i++) {
Expand All @@ -235,5 +275,27 @@ void StructVector::copyFromRowData(ValueVector* vector, uint32_t pos, const uint
}
}

void StructVector::copyFromVectorData(ValueVector* dstVector, const uint8_t* dstData,
const ValueVector* srcVector, const uint8_t* srcData) {
auto& srcPos = *(int64_t*)srcData;
auto& dstPos = *(int64_t*)dstData;
auto& srcFieldVectors = getFieldVectors(srcVector);
auto& dstFieldVectors = getFieldVectors(dstVector);
for (auto i = 0u; i < srcFieldVectors.size(); i++) {
auto srcFieldVector = srcFieldVectors[i];
auto dstFieldVector = dstFieldVectors[i];
if (srcFieldVector->isNull(srcPos)) {
dstFieldVector->setNull(dstPos, true /* isNull */);
} else {
auto srcFieldVectorData =
srcFieldVector->getData() + srcFieldVector->getNumBytesPerValue() * srcPos;
auto dstFieldVectorData =
dstFieldVector->getData() + dstFieldVector->getNumBytesPerValue() * dstPos;
dstFieldVector->copyFromVectorData(
dstFieldVectorData, srcFieldVector.get(), srcFieldVectorData);
}
}
}

} // namespace common
} // namespace kuzu
47 changes: 0 additions & 47 deletions src/common/vector/value_vector_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,50 +68,3 @@ void ValueVectorUtils::copyNonNullDataWithSameTypeOutFromPos(const ValueVector&
}
}
}

void ValueVectorUtils::copyValue(uint8_t* dstValue, common::ValueVector& dstVector,
const uint8_t* srcValue, const common::ValueVector& srcVector) {
switch (srcVector.dataType.getPhysicalType()) {
case PhysicalTypeID::VAR_LIST: {
auto srcList = reinterpret_cast<const common::list_entry_t*>(srcValue);
auto dstList = reinterpret_cast<common::list_entry_t*>(dstValue);
*dstList = ListVector::addList(&dstVector, srcList->size);
auto srcValues = ListVector::getListValues(&srcVector, *srcList);
auto srcDataVector = ListVector::getDataVector(&srcVector);
auto dstValues = ListVector::getListValues(&dstVector, *dstList);
auto dstDataVector = ListVector::getDataVector(&dstVector);
auto numBytesPerValue = srcDataVector->getNumBytesPerValue();
for (auto i = 0u; i < srcList->size; i++) {
if (srcDataVector->isNull(srcList->offset + i)) {
dstDataVector->setNull(dstList->offset + i, true);
} else {
copyValue(dstValues, *dstDataVector, srcValues, *srcDataVector);
}
srcValues += numBytesPerValue;
dstValues += numBytesPerValue;
}
} break;
case PhysicalTypeID::STRUCT: {
auto srcFields = common::StructVector::getFieldVectors(&srcVector);
auto dstFields = common::StructVector::getFieldVectors(&dstVector);
auto srcPos = *(int64_t*)srcValue;
auto dstPos = *(int64_t*)dstValue;
for (auto i = 0u; i < srcFields.size(); i++) {
auto srcField = srcFields[i];
auto dstField = dstFields[i];
if (srcField->isNull(srcPos)) {
dstField->setNull(dstPos, true /* isNull */);
} else {
copyValue(dstField->getData() + dstField->getNumBytesPerValue() * dstPos, *dstField,
srcField->getData() + srcField->getNumBytesPerValue() * srcPos, *srcField);
}
}
} break;
case PhysicalTypeID::STRING: {
StringVector::addString(&dstVector, *(ku_string_t*)dstValue, *(ku_string_t*)srcValue);
} break;
default: {
memcpy(dstValue, srcValue, srcVector.getNumBytesPerValue());
}
}
}
4 changes: 2 additions & 2 deletions src/expression_evaluator/case_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void CaseExpressionEvaluator::fillEntry(sel_t resultPos, const ValueVector& then
if (thenVector.dataType.getLogicalTypeID() == common::LogicalTypeID::VAR_LIST) {
auto srcListEntry = thenVector.getValue<list_entry_t>(thenPos);
list_entry_t resultEntry = ListVector::addList(resultVector.get(), srcListEntry.size);
common::ValueVectorUtils::copyValue(reinterpret_cast<uint8_t*>(&resultEntry),
*resultVector, reinterpret_cast<uint8_t*>(&srcListEntry), thenVector);
resultVector->copyFromVectorData(reinterpret_cast<uint8_t*>(&resultEntry), &thenVector,
reinterpret_cast<uint8_t*>(&srcListEntry));
resultVector->setValue(resultPos, resultEntry);
} else {
auto val = thenVector.getValue<T>(thenPos);
Expand Down
4 changes: 2 additions & 2 deletions src/function/vector_list_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void ListCreationVectorOperation::execFunc(
if (parameter->isNull(paramPos)) {
resultDataVector->setNull(resultEntry.offset + i, true);
} else {
common::ValueVectorUtils::copyValue(resultValues, *resultDataVector,
parameter->getData() + parameter->getNumBytesPerValue() * paramPos, *parameter);
resultDataVector->copyFromVectorData(resultValues, parameter.get(),
parameter->getData() + parameter->getNumBytesPerValue() * paramPos);
}
resultValues += numBytesPerValue;
}
Expand Down
12 changes: 6 additions & 6 deletions src/function/vector_struct_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ void StructPackVectorOperations::copyParameterValueToStructFieldVector(
if (isSrcValueNull) {
structField->setNull(pos, true /* isNull */);
} else {
common::ValueVectorUtils::copyValue(
structField->getData() + structField->getNumBytesPerValue() * pos, *structField,
srcValue, *parameter);
structField->copyFromVectorData(
structField->getData() + structField->getNumBytesPerValue() * pos, parameter,
srcValue);
}
} else {
for (auto j = 0u; j < structField->state->selVector->selectedSize; j++) {
auto pos = structField->state->selVector->selectedPositions[j];
if (isSrcValueNull) {
structField->setNull(pos, true /* isNull */);
} else {
common::ValueVectorUtils::copyValue(
structField->getData() + structField->getNumBytesPerValue() * pos, *structField,
srcValue, *parameter);
structField->copyFromVectorData(
structField->getData() + structField->getNumBytesPerValue() * pos, parameter,
srcValue);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/include/common/vector/value_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ class ValueVector {
}
template<typename T>
void setValue(uint32_t pos, T val);
// This function assumes rowData is non-NULL.
void copyFromRowData(uint32_t pos, const uint8_t* rowData);
void copyFromVectorData(
uint8_t* dstData, const ValueVector* srcVector, const uint8_t* srcVectorData);

inline uint8_t* getData() const { return valueBuffer.get(); }

Expand Down Expand Up @@ -125,6 +128,8 @@ class ListVector {
}

static void copyFromRowData(ValueVector* vector, uint32_t pos, const uint8_t* rowData);
static void copyFromVectorData(ValueVector* dstVector, uint8_t* dstData,
const ValueVector* srcVector, const uint8_t* srcData);
};

class StructVector {
Expand Down Expand Up @@ -155,6 +160,8 @@ class StructVector {
}

static void copyFromRowData(ValueVector* vector, uint32_t pos, const uint8_t* rowData);
static void copyFromVectorData(ValueVector* dstVector, const uint8_t* dstData,
const ValueVector* srcVector, const uint8_t* srcData);
};

class UnionVector {
Expand Down
2 changes: 0 additions & 2 deletions src/include/common/vector/value_vector_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class ValueVectorUtils {
public:
static void copyNonNullDataWithSameTypeOutFromPos(const ValueVector& srcVector, uint64_t pos,
uint8_t* dstData, InMemOverflowBuffer& dstOverflowBuffer);
static void copyValue(uint8_t* dstValue, common::ValueVector& dstVector,
const uint8_t* srcValue, const common::ValueVector& srcVector);
};

} // namespace common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ struct BaseListSortOperation {
inputValues += numBytesPerValue;
continue;
}
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, inputValues, *inputDataVector);
resultDataVector->copyFromVectorData(resultValues, inputDataVector, inputValues);
resultValues += numBytesPerValue;
inputValues += numBytesPerValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct ListAnyValue {

for (auto i = 0; i < input.size; i++) {
if (!(inputDataVector->isNull(input.offset + i))) {
common::ValueVectorUtils::copyValue(
(uint8_t*)(&result), resultVector, inputValues, *inputDataVector);
resultVector.copyFromVectorData(
reinterpret_cast<uint8_t*>(&result), inputDataVector, inputValues);
break;
}
inputValues += numBytesPerValue;
Expand Down
7 changes: 3 additions & 4 deletions src/include/function/list/operations/list_append_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ struct ListAppend {
auto resultDataVector = common::ListVector::getDataVector(&resultVector);
auto numBytesPerValue = resultDataVector->getNumBytesPerValue();
for (auto i = 0u; i < listEntry.size; i++) {
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, listValues, *listDataVector);
resultDataVector->copyFromVectorData(resultValues, listDataVector, listValues);
listValues += numBytesPerValue;
resultValues += numBytesPerValue;
}
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, reinterpret_cast<uint8_t*>(&value), valueVector);
resultDataVector->copyFromVectorData(
resultValues, &valueVector, reinterpret_cast<uint8_t*>(&value));
}
};

Expand Down
6 changes: 2 additions & 4 deletions src/include/function/list/operations/list_concat_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ struct ListConcat {
auto resultDataVector = common::ListVector::getDataVector(&resultVector);
auto numBytesPerValue = resultDataVector->getNumBytesPerValue();
for (auto i = 0u; i < left.size; i++) {
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, leftValues, *leftDataVector);
resultDataVector->copyFromVectorData(resultValues, leftDataVector, leftValues);
resultValues += numBytesPerValue;
leftValues += numBytesPerValue;
}
auto rightValues = common::ListVector::getListValues(&rightVector, right);
auto rightDataVector = common::ListVector::getDataVector(&rightVector);
for (auto i = 0u; i < right.size; i++) {
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, rightValues, *rightDataVector);
resultDataVector->copyFromVectorData(resultValues, rightDataVector, rightValues);
resultValues += numBytesPerValue;
rightValues += numBytesPerValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct ListDistinct {
auto resultDataVector = common::ListVector::getDataVector(&resultVector);
auto numBytesPerValue = inputDataVector->getNumBytesPerValue();
for (auto val : uniqueValues) {
common::ValueVectorUtils::copyValue(resultValues, *resultDataVector,
reinterpret_cast<uint8_t*>(&val), *inputDataVector);
resultDataVector->copyFromVectorData(
resultValues, inputDataVector, reinterpret_cast<uint8_t*>(&val));
resultValues += numBytesPerValue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/include/function/list/operations/list_extract_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct ListExtract {
auto listDataVector = common::ListVector::getDataVector(&listVector);
auto listValues =
common::ListVector::getListValuesWithOffset(&listVector, listEntry, pos - 1);
common::ValueVectorUtils::copyValue(
(uint8_t*)(&result), resultVector, listValues, *listDataVector);
resultVector.copyFromVectorData(
reinterpret_cast<uint8_t*>(&result), listDataVector, listValues);
}

static inline void operation(
Expand Down
7 changes: 3 additions & 4 deletions src/include/function/list/operations/list_prepend_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ struct ListPrepend {
auto resultValues = common::ListVector::getListValues(&resultVector, result);
auto resultDataVector = common::ListVector::getDataVector(&resultVector);
auto numBytesPerValue = resultDataVector->getNumBytesPerValue();
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, reinterpret_cast<uint8_t*>(&value), valueVector);
resultDataVector->copyFromVectorData(
resultValues, &valueVector, reinterpret_cast<uint8_t*>(&value));
resultValues += numBytesPerValue;
for (auto i = 0u; i < listEntry.size; i++) {
common::ValueVectorUtils::copyValue(
resultValues, *resultDataVector, listValues, *listDataVector);
resultDataVector->copyFromVectorData(resultValues, listDataVector, listValues);
listValues += numBytesPerValue;
resultValues += numBytesPerValue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/include/function/list/operations/list_slice_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ struct ListSlice {
auto srcDataVector = common::ListVector::getDataVector(&listVector);
auto dstDataVector = common::ListVector::getDataVector(&resultVector);
for (auto i = startIdx; i < endIdx; i++) {
common::ValueVectorUtils::copyValue(
dstValues, *dstDataVector, srcValues, *srcDataVector);
dstDataVector->copyFromVectorData(dstValues, srcDataVector, srcValues);
srcValues += numBytesPerValue;
dstValues += numBytesPerValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct BaseMapExtract {
auto dstValues = common::ListVector::getListValues(&resultVector, resultEntry);
auto dstDataVector = common::ListVector::getDataVector(&resultVector);
for (auto i = 0u; i < numValuesToCopy; i++) {
common::ValueVectorUtils::copyValue(dstValues, *dstDataVector, srcValues, *srcVector);
dstDataVector->copyFromVectorData(dstValues, srcVector, srcValues);
dstValues += dstDataVector->getNumBytesPerValue();
srcValues += srcVector->getNumBytesPerValue();
}
Expand Down
3 changes: 1 addition & 2 deletions src/include/function/map/operations/map_creation_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ struct MapCreation {
auto srcValues = common::ListVector::getListValues(srcVector, srcEntry);
auto srcDataVector = common::ListVector::getDataVector(srcVector);
for (auto i = 0u; i < srcEntry.size; i++) {
common::ValueVectorUtils::copyValue(
resultValues, *resultVector, srcValues, *srcDataVector);
resultVector->copyFromVectorData(resultValues, srcDataVector, srcValues);
srcValues += srcDataVector->getNumBytesPerValue();
resultValues += resultVector->getNumBytesPerValue();
}
Expand Down
7 changes: 4 additions & 3 deletions src/include/function/map/operations/map_extract_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ struct MapExtract {
if (common::TypeUtils::isValueEqual(
*reinterpret_cast<T*>(mapKeyValues), key, mapKeyVector, &keyVector)) {
resultEntry = common::ListVector::addList(&resultVector, 1 /* size */);
common::ValueVectorUtils::copyValue(
common::ListVector::getListValues(&resultVector, resultEntry),
*common::ListVector::getDataVector(&resultVector), mapValValues, *mapValVector);
common::ListVector::getDataVector(&resultVector)
->copyFromVectorData(
common::ListVector::getListValues(&resultVector, resultEntry), mapValVector,
mapValValues);
return;
}
mapKeyValues += mapKeyVector->getNumBytesPerValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct RegexpExtractAll : BaseRegexpOperation {
for (const auto& match : matches) {
common::ku_string_t kuString;
copyToKuzuString(match, kuString, *resultDataVector);
common::ValueVectorUtils::copyValue(resultValues, *resultDataVector,
reinterpret_cast<uint8_t*>(&kuString), *resultDataVector);
resultDataVector->copyFromVectorData(
resultValues, resultDataVector, reinterpret_cast<uint8_t*>(&kuString));
resultValues += numBytesPerValue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/processor/operator/unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ void Unwind::copyTuplesToOutVector(uint64_t startPos, uint64_t endPos) const {
auto listDataVector =
common::ListVector::getDataVector(expressionEvaluator->resultVector.get());
for (auto pos = startPos; pos < endPos; pos++) {
common::ValueVectorUtils::copyValue(
outValueVector->copyFromVectorData(
outValueVector->getData() + outValueVector->getNumBytesPerValue() * (pos - startPos),
*outValueVector, listValues, *listDataVector);
listDataVector, listValues);
listValues += listDataVector->getNumBytesPerValue();
}
}
Expand Down

0 comments on commit b069813

Please sign in to comment.