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

Add struct data type front end #1457

Merged
merged 1 commit into from
Apr 10, 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)

project(Kuzu VERSION 0.0.3 LANGUAGES CXX)
project(Kuzu VERSION 0.0.3.1 LANGUAGES CXX)

find_package(Threads REQUIRED)

Expand Down
3 changes: 2 additions & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ TO: ( 'T' | 't' ) ( 'O' | 'o' ) ;

kU_DataType
: oC_SymbolicName
| ( oC_SymbolicName kU_ListIdentifiers ) ;
| ( oC_SymbolicName kU_ListIdentifiers )
| oC_SymbolicName SP? '(' SP? kU_PropertyDefinitions SP? ')' ;

kU_ListIdentifiers : kU_ListIdentifier ( kU_ListIdentifier )* ;

Expand Down
6 changes: 3 additions & 3 deletions src/binder/bind/bind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ std::unordered_map<common::property_id_t, std::string> Binder::bindPropertyToNpy
"Number of npy files is not equal to number of properties in table {}.",
tableSchema->tableName));
}
std::unordered_map<common::property_id_t, std::string> propertyIdxToNpyMap;
std::unordered_map<common::property_id_t, std::string> propertyIDToNpyMap;
for (int i = 0; i < filePaths.size(); i++) {
auto& filePath = filePaths[i];
auto& propertyID = tableSchema->properties[i].propertyID;
propertyIdxToNpyMap[propertyID] = filePath;
propertyIDToNpyMap[propertyID] = filePath;
}
return propertyIdxToNpyMap;
return propertyIDToNpyMap;
}

CSVReaderConfig Binder::bindParsingOptions(
Expand Down
11 changes: 6 additions & 5 deletions src/binder/bind/bind_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,19 @@ DataType Binder::bindDataType(const std::string& dataType) {
auto boundType = Types::dataTypeFromString(dataType);
if (boundType.typeID == common::FIXED_LIST) {
auto validNumericTypes = common::DataType::getNumericalTypeIDs();
if (find(validNumericTypes.begin(), validNumericTypes.end(), boundType.childType->typeID) ==
validNumericTypes.end()) {
auto fixedListTypeInfo = reinterpret_cast<FixedListTypeInfo*>(boundType.getExtraTypeInfo());
if (find(validNumericTypes.begin(), validNumericTypes.end(),
boundType.getChildType()->typeID) == validNumericTypes.end()) {
throw common::BinderException(
"The child type of a fixed list must be a numeric type. Given: " +
common::Types::dataTypeToString(*boundType.childType) + ".");
common::Types::dataTypeToString(*boundType.getChildType()) + ".");
}
if (boundType.fixedNumElementsInList == 0) {
if (fixedListTypeInfo->getFixedNumElementsInList() == 0) {
// Note: the parser already guarantees that the number of elements is a non-negative
// number. However, we still need to check whether the number of elements is 0.
throw common::BinderException(
"The number of elements in a fixed list must be greater than 0. Given: " +
std::to_string(boundType.fixedNumElementsInList) + ".");
std::to_string(fixedListTypeInfo->getFixedNumElementsInList()) + ".");
}
auto numElementsPerPage = storage::PageUtils::getNumElementsInAPage(
Types::getDataTypeSize(boundType), true /* hasNull */);
Expand Down
2 changes: 1 addition & 1 deletion src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindUnwindClause(const ReadingClause
auto boundExpression = expressionBinder.bindExpression(*unwindClause.getExpression());
boundExpression = ExpressionBinder::implicitCastIfNecessary(boundExpression, VAR_LIST);
auto aliasExpression =
createVariable(unwindClause.getAlias(), *boundExpression->dataType.childType);
createVariable(unwindClause.getAlias(), *boundExpression->dataType.getChildType());
return make_unique<BoundUnwindClause>(std::move(boundExpression), std::move(aliasExpression));
}

Expand Down
24 changes: 0 additions & 24 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,6 @@ uint64_t SerDeser::deserializeValue<std::string>(
return offset + valueLength;
}

template<>
uint64_t SerDeser::serializeValue<DataType>(
const DataType& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::serializeValue<DataTypeID>(value.typeID, fileInfo, offset);
offset = SerDeser::serializeValue<uint64_t>(value.fixedNumElementsInList, fileInfo, offset);
if (value.typeID == VAR_LIST || value.typeID == FIXED_LIST) {
offset = SerDeser::serializeValue<DataType>(*value.childType, fileInfo, offset);
}
return offset;
}

template<>
uint64_t SerDeser::deserializeValue<DataType>(
DataType& value, FileInfo* fileInfo, uint64_t offset) {
offset = SerDeser::deserializeValue<DataTypeID>(value.typeID, fileInfo, offset);
offset = SerDeser::deserializeValue<uint64_t>(value.fixedNumElementsInList, fileInfo, offset);
if (value.typeID == VAR_LIST || value.typeID == FIXED_LIST) {
auto childDataType = std::make_unique<DataType>();
offset = SerDeser::deserializeValue<DataType>(*childDataType, fileInfo, offset);
value.childType = std::move(childDataType);
}
return offset;
}

template<>
uint64_t SerDeser::serializeValue<Property>(
const Property& value, FileInfo* fileInfo, uint64_t offset) {
Expand Down
32 changes: 16 additions & 16 deletions src/common/in_mem_overflow_buffer_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ void InMemOverflowBufferUtils::copyString(
dest.set(src);
}

void InMemOverflowBufferUtils::copyListNonRecursive(const uint8_t* srcValues, ku_list_t& dest,
void InMemOverflowBufferUtils::copyListNonRecursive(const uint8_t* srcValues, ku_list_t& dst,
const DataType& dataType, InMemOverflowBuffer& inMemOverflowBuffer) {
InMemOverflowBufferUtils::allocateSpaceForList(
dest, dest.size * Types::getDataTypeSize(*dataType.childType), inMemOverflowBuffer);
dest.set(srcValues, dataType);
dst, dst.size * Types::getDataTypeSize(*dataType.getChildType()), inMemOverflowBuffer);
dst.set(srcValues, dataType);
}

void InMemOverflowBufferUtils::copyListRecursiveIfNested(const ku_list_t& src, ku_list_t& dest,
void InMemOverflowBufferUtils::copyListRecursiveIfNested(const ku_list_t& src, ku_list_t& dst,
const DataType& dataType, InMemOverflowBuffer& inMemOverflowBuffer, uint32_t srcStartIdx,
uint32_t srcEndIdx) {
if (src.size == 0) {
dest.size = 0;
dst.size = 0;
return;
}
if (srcEndIdx == UINT32_MAX) {
srcEndIdx = src.size - 1;
}
assert(srcEndIdx < src.size);
auto numElements = srcEndIdx - srcStartIdx + 1;
auto elementSize = Types::getDataTypeSize(*dataType.childType);
auto elementSize = Types::getDataTypeSize(*dataType.getChildType());
InMemOverflowBufferUtils::allocateSpaceForList(
dest, numElements * elementSize, inMemOverflowBuffer);
memcpy((uint8_t*)dest.overflowPtr, (uint8_t*)src.overflowPtr + srcStartIdx * elementSize,
dst, numElements * elementSize, inMemOverflowBuffer);
memcpy((uint8_t*)dst.overflowPtr, (uint8_t*)src.overflowPtr + srcStartIdx * elementSize,
numElements * elementSize);
dest.size = numElements;
if (dataType.childType->typeID == STRING) {
for (auto i = 0u; i < dest.size; i++) {
dst.size = numElements;
if (dataType.getChildType()->typeID == STRING) {
for (auto i = 0u; i < dst.size; i++) {
InMemOverflowBufferUtils::copyString(((ku_string_t*)src.overflowPtr)[i + srcStartIdx],
((ku_string_t*)dest.overflowPtr)[i], inMemOverflowBuffer);
((ku_string_t*)dst.overflowPtr)[i], inMemOverflowBuffer);
}
}
if (dataType.childType->typeID == VAR_LIST) {
for (auto i = 0u; i < dest.size; i++) {
if (dataType.getChildType()->typeID == VAR_LIST) {
for (auto i = 0u; i < dst.size; i++) {
InMemOverflowBufferUtils::copyListRecursiveIfNested(
((ku_list_t*)src.overflowPtr)[i + srcStartIdx], ((ku_list_t*)dest.overflowPtr)[i],
*dataType.childType, inMemOverflowBuffer);
((ku_list_t*)src.overflowPtr)[i + srcStartIdx], ((ku_list_t*)dst.overflowPtr)[i],
*dataType.getChildType(), inMemOverflowBuffer);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/common/type_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ std::string TypeUtils::elementToString(
std::string TypeUtils::toString(const ku_list_t& val, const DataType& dataType) {
std::string result = "[";
for (auto i = 0u; i < val.size - 1; ++i) {
result +=
elementToString(*dataType.childType, reinterpret_cast<uint8_t*>(val.overflowPtr), i) +
",";
result += elementToString(
*dataType.getChildType(), reinterpret_cast<uint8_t*>(val.overflowPtr), i) +
",";
}
result += elementToString(
*dataType.childType, reinterpret_cast<uint8_t*>(val.overflowPtr), val.size - 1) +
result += elementToString(*dataType.getChildType(), reinterpret_cast<uint8_t*>(val.overflowPtr),
val.size - 1) +
"]";
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/ku_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace common {

void ku_list_t::set(const uint8_t* values, const DataType& dataType) const {
memcpy(reinterpret_cast<uint8_t*>(overflowPtr), values,
size * Types::getDataTypeSize(*dataType.childType));
size * Types::getDataTypeSize(*dataType.getChildType()));
}

void ku_list_t::set(const std::vector<uint8_t*>& parameters, DataTypeID childTypeId) {
Expand Down
Loading