Skip to content

Commit

Permalink
update headers
Browse files Browse the repository at this point in the history
  • Loading branch information
guodong authored and guodong committed Feb 8, 2023
1 parent c35825b commit 68278ed
Show file tree
Hide file tree
Showing 73 changed files with 1,250 additions and 657 deletions.
15 changes: 10 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ add_subdirectory(storage)
add_subdirectory(transaction)

add_library(kuzu STATIC ${ALL_OBJECT_FILES})
target_link_libraries(kuzu PUBLIC antlr4_cypher antlr4_runtime utf8proc re2
parquet_lib arrow_lib arrow_deps Threads::Threads)
target_include_directories(
kuzu PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(kuzu
PUBLIC antlr4_cypher antlr4_runtime utf8proc re2 parquet_lib arrow_lib arrow_deps Threads::Threads)
target_include_directories(kuzu
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
add_library(kuzu_shared SHARED ${ALL_OBJECT_FILES})
set_target_properties(kuzu_shared PROPERTIES OUTPUT_NAME kuzu)
target_link_libraries(kuzu_shared
PUBLIC antlr4_cypher antlr4_runtime utf8proc re2 parquet_lib arrow_lib arrow_deps Threads::Threads)
target_include_directories(kuzu_shared
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
3 changes: 3 additions & 0 deletions src/common/arrow/arrow_row_batch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "common/arrow/arrow_row_batch.h"

#include "common/types/value.h"
#include "processor/result/flat_tuple.h"

namespace kuzu {
namespace common {

Expand Down
1 change: 1 addition & 0 deletions src/common/types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(kuzu_common_types
OBJECT
date_t.cpp
dtime_t.cpp
internal_id_t.cpp
interval_t.cpp
ku_list.cpp
ku_string.cpp
Expand Down
55 changes: 55 additions & 0 deletions src/common/types/date_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@
namespace kuzu {
namespace common {

date_t::date_t() : days{0} {}

date_t::date_t(int32_t days_p) : days(days_p) {}

bool date_t::operator==(const date_t& rhs) const {
return days == rhs.days;
}

bool date_t::operator!=(const date_t& rhs) const {
return days != rhs.days;
}

bool date_t::operator<=(const date_t& rhs) const {
return days <= rhs.days;
}

bool date_t::operator<(const date_t& rhs) const {
return days < rhs.days;
}

bool date_t::operator>(const date_t& rhs) const {
return days > rhs.days;
}

bool date_t::operator>=(const date_t& rhs) const {
return days >= rhs.days;
}

date_t date_t::operator+(const interval_t& interval) const {
date_t result{};
if (interval.months != 0) {
Expand Down Expand Up @@ -57,10 +85,33 @@ bool date_t::operator==(const timestamp_t& rhs) const {
return Timestamp::FromDatetime(*this, dtime_t(0)).value == rhs.value;
}

bool date_t::operator!=(const timestamp_t& rhs) const {
return !(*this == rhs);
}

bool date_t::operator<(const timestamp_t& rhs) const {
return Timestamp::FromDatetime(*this, dtime_t(0)).value < rhs.value;
}

bool date_t::operator<=(const timestamp_t& rhs) const {
return (*this) < rhs || (*this) == rhs;
}

bool date_t::operator>(const timestamp_t& rhs) const {
return !(*this <= rhs);
}

bool date_t::operator>=(const timestamp_t& rhs) const {
return !(*this < rhs);
}

date_t date_t::operator+(const int32_t& day) const {
return date_t(this->days + day);
};
date_t date_t::operator-(const int32_t& day) const {
return date_t(this->days - day);
};

const int32_t Date::NORMAL_DAYS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int32_t Date::LEAP_DAYS[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int32_t Date::CUMULATIVE_LEAP_DAYS[] = {
Expand Down Expand Up @@ -417,5 +468,9 @@ date_t Date::trunc(DatePartSpecifier specifier, date_t& date) {
}
}

int64_t Date::getEpochNanoSeconds(const date_t& date) {
return ((int64_t)date.days) * (Interval::MICROS_PER_DAY * Interval::NANOS_PER_MICRO);
}

} // namespace common
} // namespace kuzu
41 changes: 41 additions & 0 deletions src/common/types/dtime_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@ namespace common {

static_assert(sizeof(dtime_t) == sizeof(int64_t), "dtime_t was padded");

dtime_t::dtime_t() : micros(0) {}

dtime_t::dtime_t(int64_t micros_p) : micros(micros_p) {}

dtime_t& dtime_t::operator=(int64_t micros_p) {
micros = micros_p;
return *this;
}

dtime_t::operator int64_t() const {
return micros;
}

dtime_t::operator double() const {
return micros;
}

bool dtime_t::operator==(const dtime_t& rhs) const {
return micros == rhs.micros;
}

bool dtime_t::operator!=(const dtime_t& rhs) const {
return micros != rhs.micros;
}

bool dtime_t::operator<=(const dtime_t& rhs) const {
return micros <= rhs.micros;
}

bool dtime_t::operator<(const dtime_t& rhs) const {
return micros < rhs.micros;
}

bool dtime_t::operator>(const dtime_t& rhs) const {
return micros > rhs.micros;
}

bool dtime_t::operator>=(const dtime_t& rhs) const {
return micros >= rhs.micros;
}

// string format is hh:mm:ss[.mmmmmm] (ISO 8601) (m represent microseconds)
// microseconds is optional, timezone is currently not supported
bool Time::TryConvertTime(const char* buf, uint64_t len, uint64_t& pos, dtime_t& result) {
Expand Down
36 changes: 36 additions & 0 deletions src/common/types/internal_id_t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "common/types/internal_id_t.h"

namespace kuzu {
namespace common {

internalID_t::internalID_t() : offset{INVALID_NODE_OFFSET}, tableID{INVALID_TABLE_ID} {}

internalID_t::internalID_t(offset_t offset, table_id_t tableID)
: offset(offset), tableID(tableID) {}

bool internalID_t::operator==(const internalID_t& rhs) const {
return offset == rhs.offset && tableID == rhs.tableID;
}

bool internalID_t::operator!=(const internalID_t& rhs) const {
return offset != rhs.offset || tableID != rhs.tableID;
}

bool internalID_t::operator>(const internalID_t& rhs) const {
return (tableID > rhs.tableID) || (tableID == rhs.tableID && offset > rhs.offset);
}

bool internalID_t::operator>=(const internalID_t& rhs) const {
return (tableID > rhs.tableID) || (tableID == rhs.tableID && offset >= rhs.offset);
}

bool internalID_t::operator<(const internalID_t& rhs) const {
return (tableID < rhs.tableID) || (tableID == rhs.tableID && offset < rhs.offset);
}

bool internalID_t::operator<=(const internalID_t& rhs) const {
return (tableID < rhs.tableID) || (tableID == rhs.tableID && offset <= rhs.offset);
}

} // namespace common
} // namespace kuzu
33 changes: 33 additions & 0 deletions src/common/types/interval_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,35 @@
namespace kuzu {
namespace common {

interval_t::interval_t() = default;

interval_t::interval_t(int32_t months_p, int32_t days_p, int64_t micros_p)
: months(months_p), days(days_p), micros(micros_p) {}

bool interval_t::operator==(const interval_t& rhs) const {
return this->days == rhs.days && this->months == rhs.months && this->micros == rhs.micros;
}

bool interval_t::operator!=(const interval_t& rhs) const {
return !(*this == rhs);
}

bool interval_t::operator>(const interval_t& rhs) const {
return Interval::GreaterThan(*this, rhs);
}

bool interval_t::operator<=(const interval_t& rhs) const {
return !(*this > rhs);
}

bool interval_t::operator<(const interval_t& rhs) const {
return !(*this >= rhs);
}

bool interval_t::operator>=(const interval_t& rhs) const {
return *this > rhs || *this == rhs;
}

interval_t interval_t::operator+(const interval_t& rhs) const {
interval_t result{};
result.months = months + rhs.months;
Expand Down Expand Up @@ -225,5 +250,13 @@ int32_t Interval::getIntervalPart(DatePartSpecifier specifier, interval_t& inter
}
}

int64_t Interval::getMicro(const interval_t& val) {
return val.micros + val.months * MICROS_PER_MONTH + val.days * MICROS_PER_DAY;
}

int64_t Interval::getNanoseconds(const interval_t& val) {
return getMicro(val) * NANOS_PER_MICRO;
}

} // namespace common
} // namespace kuzu
65 changes: 65 additions & 0 deletions src/common/types/timestamp_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,67 @@
namespace kuzu {
namespace common {

timestamp_t::timestamp_t() : value(0) {}

timestamp_t::timestamp_t(int64_t value_p) : value(value_p) {}

timestamp_t& timestamp_t::operator=(int64_t value_p) {
value = value_p;
return *this;
}

timestamp_t::operator int64_t() const {
return value;
}

bool timestamp_t::operator==(const timestamp_t& rhs) const {
return value == rhs.value;
}

bool timestamp_t::operator!=(const timestamp_t& rhs) const {
return value != rhs.value;
}

bool timestamp_t::operator<=(const timestamp_t& rhs) const {
return value <= rhs.value;
}

bool timestamp_t::operator<(const timestamp_t& rhs) const {
return value < rhs.value;
}

bool timestamp_t::operator>(const timestamp_t& rhs) const {
return value > rhs.value;
}

bool timestamp_t::operator>=(const timestamp_t& rhs) const {
return value >= rhs.value;
};

bool timestamp_t::operator==(const date_t& rhs) const {
return rhs == *this;
}

bool timestamp_t::operator!=(const date_t& rhs) const {
return !(rhs == *this);
}

bool timestamp_t::operator<(const date_t& rhs) const {
return rhs > *this;
}

bool timestamp_t::operator<=(const date_t& rhs) const {
return rhs >= *this;
}

bool timestamp_t::operator>(const date_t& rhs) const {
return rhs < *this;
}

bool timestamp_t::operator>=(const date_t& rhs) const {
return rhs <= *this;
}

timestamp_t timestamp_t::operator+(const interval_t& interval) const {
date_t date{};
date_t result_date{};
Expand Down Expand Up @@ -239,5 +300,9 @@ timestamp_t Timestamp::trunc(DatePartSpecifier specifier, timestamp_t& timestamp
}
}

int64_t Timestamp::getEpochNanoSeconds(const timestamp_t& timestamp) {
return timestamp.value * Interval::NANOS_PER_MICRO;
}

} // namespace common
} // namespace kuzu
41 changes: 41 additions & 0 deletions src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,35 @@
namespace kuzu {
namespace common {

DataType::DataType() : typeID{ANY}, childType{nullptr} {}

DataType::DataType(DataTypeID typeID) : typeID{typeID}, childType{nullptr} {
assert(typeID != LIST);
}

DataType::DataType(DataTypeID typeID, std::unique_ptr<DataType> childType)
: typeID{typeID}, childType{std::move(childType)} {
assert(typeID == LIST);
}

DataType::DataType(const DataType& other) : typeID{other.typeID} {
if (other.childType) {
childType = other.childType->copy();
}
}

DataType::DataType(DataType&& other) noexcept
: typeID{other.typeID}, childType{std::move(other.childType)} {}

std::vector<DataTypeID> DataType::getNumericalTypeIDs() {
return std::vector<DataTypeID>{INT64, DOUBLE};
}

std::vector<DataTypeID> DataType::getAllValidTypeIDs() {
return std::vector<DataTypeID>{
INTERNAL_ID, BOOL, INT64, DOUBLE, STRING, DATE, TIMESTAMP, INTERVAL, LIST};
}

DataType& DataType::operator=(const DataType& other) {
typeID = other.typeID;
if (other.childType) {
Expand All @@ -32,6 +55,16 @@ bool DataType::operator==(const DataType& other) const {
return true;
}

bool DataType::operator!=(const DataType& other) const {
return !((*this) == other);
}

DataType& DataType::operator=(DataType&& other) noexcept {
typeID = other.typeID;
childType = std::move(other.childType);
return *this;
}

std::unique_ptr<DataType> DataType::copy() {
if (childType) {
return make_unique<DataType>(typeID, childType->copy());
Expand All @@ -40,6 +73,14 @@ std::unique_ptr<DataType> DataType::copy() {
}
}

DataTypeID DataType::getTypeID() const {
return typeID;
}

DataType* DataType::getChildType() const {
return childType.get();
}

DataType Types::dataTypeFromString(const std::string& dataTypeString) {
DataType dataType;
if (dataTypeString.ends_with("[]")) {
Expand Down
Loading

0 comments on commit 68278ed

Please sign in to comment.