Skip to content

Commit

Permalink
relID refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
acquamarin committed Jan 30, 2023
1 parent 50c1da7 commit 72529ed
Show file tree
Hide file tree
Showing 91 changed files with 710 additions and 556 deletions.
2 changes: 0 additions & 2 deletions src/binder/bind/bind_projection_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ unique_ptr<BoundReturnClause> Binder::bindReturnClause(const ReturnClause& retur
auto projectionBody = returnClause.getProjectionBody();
auto boundProjectionExpressions = bindProjectionExpressions(
projectionBody->getProjectionExpressions(), projectionBody->containsStar());
validateProjectionColumnHasNoInternalType(boundProjectionExpressions);
// expand node/rel to all of its properties.
auto statementResult = make_unique<BoundStatementResult>();
for (auto& expression : boundProjectionExpressions) {
auto dataType = expression->getDataType();
Expand Down
2 changes: 1 addition & 1 deletion src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ unique_ptr<Expression> ExpressionBinder::createInternalNodeIDExpression(
propertyIDPerTable.insert({tableID, INVALID_PROPERTY_ID});
}
auto result = make_unique<PropertyExpression>(
DataType(NODE_ID), INTERNAL_ID_SUFFIX, node, std::move(propertyIDPerTable));
DataType(INTERNAL_ID), INTERNAL_ID_SUFFIX, node, std::move(propertyIDPerTable));
return result;
}

Expand Down
11 changes: 0 additions & 11 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ void Binder::validateProjectionColumnNamesAreUnique(const expression_vector& exp
}
}

void Binder::validateProjectionColumnHasNoInternalType(const expression_vector& expressions) {
auto internalTypes = unordered_set<DataTypeID>{NODE_ID};
for (auto& expression : expressions) {
if (internalTypes.contains(expression->dataType.typeID)) {
throw BinderException("Cannot return expression " + expression->getRawName() +
" with internal type " +
Types::dataTypeToString(expression->dataType));
}
}
}

void Binder::validateProjectionColumnsInWithClauseAreAliased(const expression_vector& expressions) {
for (auto& expression : expressions) {
if (!expression->hasAlias()) {
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ table_id_t CatalogContent::addRelTableSchema(string tableName, RelMultiplicity r
}
vector<Property> properties;
auto propertyID = 0;
auto propertyNameDataType = PropertyNameDataType(INTERNAL_ID_SUFFIX, INT64);
auto propertyNameDataType = PropertyNameDataType(INTERNAL_ID_SUFFIX, INTERNAL_ID);
properties.push_back(
Property::constructRelProperty(propertyNameDataType, propertyID++, tableID));
for (auto& propertyDefinition : propertyDefinitions) {
Expand Down
12 changes: 6 additions & 6 deletions src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ DataType Types::dataTypeFromString(const string& dataTypeString) {
}

DataTypeID Types::dataTypeIDFromString(const std::string& dataTypeIDString) {
if ("NODE_ID" == dataTypeIDString) {
return NODE_ID;
if ("INTERNAL_ID" == dataTypeIDString) {
return INTERNAL_ID;
} else if ("INT64" == dataTypeIDString) {
return INT64;
} else if ("DOUBLE" == dataTypeIDString) {
Expand Down Expand Up @@ -93,8 +93,8 @@ string Types::dataTypeToString(DataTypeID dataTypeID) {
return "NODE";
case REL:
return "REL";
case NODE_ID:
return "NODE_ID";
case INTERNAL_ID:
return "INTERNAL_ID";
case BOOL:
return "BOOL";
case INT64:
Expand Down Expand Up @@ -138,8 +138,8 @@ string Types::dataTypesToString(const vector<DataTypeID>& dataTypeIDs) {

uint32_t Types::getDataTypeSize(DataTypeID dataTypeID) {
switch (dataTypeID) {
case NODE_ID:
return sizeof(nodeID_t);
case INTERNAL_ID:
return sizeof(internalID_t);
case BOOL:
return sizeof(uint8_t);
case INT64:
Expand Down
18 changes: 9 additions & 9 deletions src/common/types/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Value Value::createDefaultValue(const DataType& dataType) {
return Value(timestamp_t());
case INTERVAL:
return Value(interval_t());
case NODE_ID:
case INTERNAL_ID:
return Value(nodeID_t());
case STRING:
return Value(string(""));
Expand Down Expand Up @@ -67,8 +67,8 @@ Value::Value(kuzu::common::interval_t val_) : dataType{INTERVAL}, isNull_{false}
val.intervalVal = val_;
}

Value::Value(kuzu::common::nodeID_t val_) : dataType{NODE_ID}, isNull_{false} {
val.nodeIDVal = val_;
Value::Value(kuzu::common::internalID_t val_) : dataType{INTERNAL_ID}, isNull_{false} {
val.internalIDVal = val_;
}

Value::Value(const char* val_) : dataType{STRING}, isNull_{false} {
Expand Down Expand Up @@ -121,8 +121,8 @@ void Value::copyValueFrom(const uint8_t* value) {
case INTERVAL: {
val.intervalVal = *((interval_t*)value);
} break;
case NODE_ID: {
val.nodeIDVal = *((nodeID_t*)value);
case INTERNAL_ID: {
val.internalIDVal = *((nodeID_t*)value);
} break;
case STRING: {
strVal = ((ku_string_t*)value)->getAsString();
Expand Down Expand Up @@ -162,8 +162,8 @@ void Value::copyValueFrom(const Value& other) {
case INTERVAL: {
val.intervalVal = other.val.intervalVal;
} break;
case NODE_ID: {
val.nodeIDVal = other.val.nodeIDVal;
case INTERNAL_ID: {
val.internalIDVal = other.val.internalIDVal;
} break;
case STRING: {
strVal = other.strVal;
Expand Down Expand Up @@ -202,8 +202,8 @@ string Value::toString() const {
return TypeUtils::toString(val.timestampVal);
case INTERVAL:
return TypeUtils::toString(val.intervalVal);
case NODE_ID:
return TypeUtils::toString(val.nodeIDVal);
case INTERNAL_ID:
return TypeUtils::toString(val.internalIDVal);
case STRING:
return strVal;
case LIST: {
Expand Down
2 changes: 1 addition & 1 deletion src/function/aggregate_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ unique_ptr<AggregateFunction> AggregateFunctionUtil::getMinMaxFunction(
MinMaxFunction<ku_string_t>::updatePos<FUNC>,
MinMaxFunction<ku_string_t>::combine<FUNC>, MinMaxFunction<ku_string_t>::finalize,
inputType, isDistinct);
case NODE_ID:
case INTERNAL_ID:
return make_unique<AggregateFunction>(MinMaxFunction<nodeID_t>::initialize,
MinMaxFunction<nodeID_t>::updateAll<FUNC>, MinMaxFunction<nodeID_t>::updatePos<FUNC>,
MinMaxFunction<nodeID_t>::combine<FUNC>, MinMaxFunction<nodeID_t>::finalize, inputType,
Expand Down
6 changes: 3 additions & 3 deletions src/function/built_in_vector_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ void BuiltInVectorOperations::registerListOperations() {
void BuiltInVectorOperations::registerInternalIDOperation() {
vector<unique_ptr<VectorOperationDefinition>> definitions;
definitions.push_back(make_unique<VectorOperationDefinition>(
ID_FUNC_NAME, vector<DataTypeID>{NODE}, NODE_ID, nullptr));
ID_FUNC_NAME, vector<DataTypeID>{NODE}, INTERNAL_ID, nullptr));
definitions.push_back(make_unique<VectorOperationDefinition>(
ID_FUNC_NAME, vector<DataTypeID>{REL}, INT64, nullptr));
vectorOperations.insert({ID_FUNC_NAME, move(definitions)});
ID_FUNC_NAME, vector<DataTypeID>{REL}, INTERNAL_ID, nullptr));
vectorOperations.insert({ID_FUNC_NAME, std::move(definitions)});
}

} // namespace function
Expand Down
4 changes: 2 additions & 2 deletions src/function/vector_hash_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void VectorHashOperations::computeHash(ValueVector* operand, ValueVector* result
result->state = operand->state;
assert(result->dataType.typeID == INT64);
switch (operand->dataType.typeID) {
case NODE_ID: {
UnaryHashOperationExecutor::execute<nodeID_t, hash_t>(*operand, *result);
case INTERNAL_ID: {
UnaryHashOperationExecutor::execute<internalID_t, hash_t>(*operand, *result);
} break;
case BOOL: {
UnaryHashOperationExecutor::execute<bool, hash_t>(*operand, *result);
Expand Down
3 changes: 0 additions & 3 deletions src/include/binder/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ class Binder {
// E.g. ... RETURN a, b AS a
static void validateProjectionColumnNamesAreUnique(const expression_vector& expressions);

// E.g. ... RETURN ID(a)
static void validateProjectionColumnHasNoInternalType(const expression_vector& expressions);

// E.g. ... WITH COUNT(*) MATCH ...
static void validateProjectionColumnsInWithClauseAreAliased(
const expression_vector& expressions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
namespace kuzu {
namespace common {

struct internalID_t;
typedef internalID_t nodeID_t;
typedef internalID_t relID_t;

typedef uint64_t table_id_t;
typedef uint64_t node_offset_t;
typedef uint64_t offset_t;
constexpr table_id_t INVALID_TABLE_ID = UINT64_MAX;
constexpr node_offset_t INVALID_NODE_OFFSET = UINT64_MAX;
constexpr offset_t INVALID_NODE_OFFSET = UINT64_MAX;

// System representation for nodeID.
struct nodeID_t {
node_offset_t offset;
// System representation for internalID.
struct internalID_t {
offset_t offset;
table_id_t tableID;

nodeID_t() = default;
explicit inline nodeID_t(node_offset_t _offset, table_id_t tableID)
: offset(_offset), tableID(tableID) {}
internalID_t() = default;
internalID_t(offset_t offset, table_id_t tableID) : offset(offset), tableID(tableID) {}

// comparison operators
inline bool operator==(const nodeID_t& rhs) const {
inline bool operator==(const internalID_t& rhs) const {
return offset == rhs.offset && tableID == rhs.tableID;
};
inline bool operator!=(const nodeID_t& rhs) const {
inline bool operator!=(const internalID_t& rhs) const {
return offset != rhs.offset || tableID != rhs.tableID;
};
inline bool operator>(const nodeID_t& rhs) const {
inline bool operator>(const internalID_t& rhs) const {
return (tableID > rhs.tableID) || (tableID == rhs.tableID && offset > rhs.offset);
};
inline bool operator>=(const nodeID_t& rhs) const {
inline bool operator>=(const internalID_t& rhs) const {
return (tableID > rhs.tableID) || (tableID == rhs.tableID && offset >= rhs.offset);
};
inline bool operator<(const nodeID_t& rhs) const {
inline bool operator<(const internalID_t& rhs) const {
return (tableID < rhs.tableID) || (tableID == rhs.tableID && offset < rhs.offset);
};
inline bool operator<=(const nodeID_t& rhs) const {
inline bool operator<=(const internalID_t& rhs) const {
return (tableID < rhs.tableID) || (tableID == rhs.tableID && offset <= rhs.offset);
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/include/common/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum DataTypeID : uint8_t {
TIMESTAMP = 26,
INTERVAL = 27,

NODE_ID = 40,
INTERNAL_ID = 40,

// variable size types
STRING = 50,
Expand All @@ -80,7 +80,7 @@ class DataType {
}
static inline std::vector<DataTypeID> getAllValidTypeIDs() {
return std::vector<DataTypeID>{
NODE_ID, BOOL, INT64, DOUBLE, STRING, DATE, TIMESTAMP, INTERVAL, LIST};
INTERNAL_ID, BOOL, INT64, DOUBLE, STRING, DATE, TIMESTAMP, INTERVAL, LIST};
}

DataType& operator=(const DataType& other);
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/types_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include "date_t.h"
#include "dtime_t.h"
#include "internal_id_t.h"
#include "interval_t.h"
#include "ku_list.h"
#include "ku_string.h"
#include "node_id_t.h"
#include "timestamp_t.h"
#include "types.h"
12 changes: 6 additions & 6 deletions src/include/common/types/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Value {
explicit Value(date_t val_);
explicit Value(timestamp_t val_);
explicit Value(interval_t val_);
explicit Value(nodeID_t val_);
explicit Value(internalID_t val_);
explicit Value(const char* val_);
explicit Value(const string& val_);
explicit Value(DataType dataType, vector<unique_ptr<Value>> vals);
Expand Down Expand Up @@ -91,7 +91,7 @@ class Value {
common::date_t dateVal;
common::timestamp_t timestampVal;
common::interval_t intervalVal;
common::nodeID_t nodeIDVal;
common::internalID_t internalIDVal;
} val;
std::string strVal;
vector<unique_ptr<Value>> listVal;
Expand Down Expand Up @@ -191,8 +191,8 @@ inline interval_t Value::getValue() const {

template<>
inline nodeID_t Value::getValue() const {
validateType(NODE_ID);
return val.nodeIDVal;
validateType(INTERNAL_ID);
return val.internalIDVal;
}

template<>
Expand Down Expand Up @@ -251,8 +251,8 @@ inline interval_t& Value::getValueReference() {

template<>
inline nodeID_t& Value::getValueReference() {
assert(dataType.typeID == NODE_ID);
return val.nodeIDVal;
assert(dataType.typeID == INTERNAL_ID);
return val.internalIDVal;
}

template<>
Expand Down
4 changes: 2 additions & 2 deletions src/include/common/vector/value_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ValueVector {

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

inline node_offset_t readNodeOffset(uint32_t pos) const {
assert(dataType.typeID == NODE_ID);
inline offset_t readNodeOffset(uint32_t pos) const {
assert(dataType.typeID == INTERNAL_ID);
return getValue<nodeID_t>(pos).offset;
}

Expand Down
11 changes: 6 additions & 5 deletions src/include/function/comparison/vector_comparison_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class VectorComparisonOperations : public VectorOperations {
definitions.push_back(getDefinition<FUNC>(name, leftTypeID, rightTypeID));
}
}
for (auto& typeID : vector<DataTypeID>{BOOL, STRING, NODE_ID, DATE, TIMESTAMP, INTERVAL}) {
for (auto& typeID :
vector<DataTypeID>{BOOL, STRING, INTERNAL_ID, DATE, TIMESTAMP, INTERVAL}) {
definitions.push_back(getDefinition<FUNC>(name, typeID, typeID));
}
definitions.push_back(getDefinition<FUNC>(name, DATE, TIMESTAMP));
Expand Down Expand Up @@ -75,8 +76,8 @@ class VectorComparisonOperations : public VectorOperations {
assert(rightTypeID == STRING);
return BinaryExecFunction<ku_string_t, ku_string_t, uint8_t, FUNC>;
}
case NODE_ID: {
assert(rightTypeID == NODE_ID);
case INTERNAL_ID: {
assert(rightTypeID == INTERNAL_ID);
return BinaryExecFunction<nodeID_t, nodeID_t, uint8_t, FUNC>;
}
case DATE: {
Expand Down Expand Up @@ -157,8 +158,8 @@ class VectorComparisonOperations : public VectorOperations {
assert(rightTypeID == STRING);
return BinarySelectFunction<ku_string_t, ku_string_t, FUNC>;
}
case NODE_ID: {
assert(rightTypeID == NODE_ID);
case INTERNAL_ID: {
assert(rightTypeID == INTERNAL_ID);
return BinarySelectFunction<nodeID_t, nodeID_t, FUNC>;
}
case DATE: {
Expand Down
10 changes: 5 additions & 5 deletions src/include/function/hash/hash_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ struct CombineHash {
}
};

template<>
inline void Hash::operation(const internalID_t& key, hash_t& result) {
result = murmurhash64(key.offset) ^ murmurhash64(key.tableID);
}

template<>
inline void Hash::operation(const bool& key, hash_t& result) {
result = murmurhash64(key);
Expand Down Expand Up @@ -96,11 +101,6 @@ inline void Hash::operation(const interval_t& key, hash_t& result) {
combineHashScalar(murmurhash64(key.days), murmurhash64(key.micros)));
}

template<>
inline void Hash::operation(const nodeID_t& key, hash_t& result) {
result = murmurhash64(key.offset) ^ murmurhash64(key.tableID);
}

template<>
inline void Hash::operation(const unordered_set<string>& key, hash_t& result) {
for (auto&& s : key) {
Expand Down
Loading

0 comments on commit 72529ed

Please sign in to comment.