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

Support duration. #83

Merged
merged 1 commit into from
Dec 31, 2021
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 .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
Expand Down
48 changes: 36 additions & 12 deletions include/common/datatypes/DataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ struct DataSet {
return *this;
}

const std::vector<std::string>& keys() const { return colNames; }
const std::vector<std::string>& keys() const {
return colNames;
}

const std::vector<Value>& rowValues(std::size_t index) const { return rows[index].values; }
const std::vector<Value>& rowValues(std::size_t index) const {
return rows[index].values;
}

std::vector<Value> colValues(const std::string& colName) const {
std::vector<Value> col;
Expand All @@ -67,13 +71,21 @@ struct DataSet {
using iterator = std::vector<Row>::iterator;
using const_iterator = std::vector<Row>::const_iterator;

iterator begin() { return rows.begin(); }
iterator begin() {
return rows.begin();
}

const_iterator begin() const { return rows.begin(); }
const_iterator begin() const {
return rows.begin();
}

iterator end() { return rows.end(); }
iterator end() {
return rows.end();
}

const_iterator end() const { return rows.end(); }
const_iterator end() const {
return rows.end();
}

template <typename T,
typename = typename std::enable_if<std::is_convertible<T, Row>::value, T>::type>
Expand Down Expand Up @@ -124,13 +136,21 @@ struct DataSet {
rows.clear();
}

void __clear() { clear(); }
void __clear() {
clear();
}

std::size_t size() const { return rowSize(); }
std::size_t size() const {
return rowSize();
}

std::size_t rowSize() const { return rows.size(); }
std::size_t rowSize() const {
return rows.size();
}

std::size_t colSize() const { return colNames.size(); }
std::size_t colSize() const {
return colNames.size();
}

std::string toString() const {
std::stringstream os;
Expand All @@ -151,9 +171,13 @@ struct DataSet {
return os.str();
}

bool operator==(const DataSet& rhs) const { return colNames == rhs.colNames && rows == rhs.rows; }
bool operator==(const DataSet& rhs) const {
return colNames == rhs.colNames && rows == rhs.rows;
}
};

inline std::ostream& operator<<(std::ostream& os, const DataSet& d) { return os << d.toString(); }
inline std::ostream& operator<<(std::ostream& os, const DataSet& d) {
return os << d.toString();
}

} // namespace nebula
12 changes: 9 additions & 3 deletions include/common/datatypes/Date.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ struct Date {
day = 1;
}

void __clear() { clear(); }
void __clear() {
clear();
}

void reset(int16_t y, int8_t m, int8_t d) {
year = y;
Expand Down Expand Up @@ -88,7 +90,9 @@ struct Time {
microsec = 0;
}

void __clear() { clear(); }
void __clear() {
clear();
}

bool operator==(const Time& rhs) const {
return hour == rhs.hour && minute == rhs.minute && sec == rhs.sec && microsec == rhs.microsec;
Expand Down Expand Up @@ -169,7 +173,9 @@ struct DateTime {
microsec = 0;
}

void __clear() { clear(); }
void __clear() {
clear();
}

bool operator==(const DateTime& rhs) const {
return year == rhs.year && month == rhs.month && day == rhs.day && hour == rhs.hour &&
Expand Down
37 changes: 25 additions & 12 deletions include/common/datatypes/Duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,37 @@ struct Duration {
Duration() : seconds(0), microseconds(0), months(0) {}
Duration(int32_t m, int64_t s, int32_t us) : seconds(s), microseconds(us), months(m) {}

int64_t years() const { return months / 12; }
int64_t years() const {
return months / 12;
}

int64_t monthsInYear() const { return months % 12; }
int64_t monthsInYear() const {
return months % 12;
}

int64_t days() const { return seconds / time::kSecondsOfDay; }
int64_t days() const {
return seconds / time::kSecondsOfDay;
}

int64_t hours() const { return seconds % time::kSecondsOfDay / time::kSecondsOfHour; }
int64_t hours() const {
return seconds % time::kSecondsOfDay / time::kSecondsOfHour;
}

int64_t minutes() const { return seconds % time::kSecondsOfHour / time::kSecondsOfMinute; }
int64_t minutes() const {
return seconds % time::kSecondsOfHour / time::kSecondsOfMinute;
}

int64_t secondsInMinute() const { return seconds % time::kSecondsOfMinute; }
int64_t secondsInMinute() const {
return seconds % time::kSecondsOfMinute;
}

int64_t microsecondsInSecond() const { return microseconds; }
int64_t microsecondsInSecond() const {
return microseconds;
}

Duration operator-() const { return Duration(-months, -seconds, -microseconds); }
Duration operator-() const {
return Duration(-months, -seconds, -microseconds);
}

Duration operator+(const Duration& rhs) const {
return Duration(months + rhs.months, seconds + rhs.seconds, microseconds + rhs.microseconds);
Expand Down Expand Up @@ -106,10 +122,7 @@ struct Duration {
return months == rhs.months && seconds == rhs.seconds && microseconds == rhs.microseconds;
}

std::string toString() const {
return folly::sformat(
"P{}MT{}.{:0>6}000S", months, seconds + microseconds / 1000000, microseconds % 1000000);
}
std::string toString() const;
};

} // namespace nebula
Expand Down
8 changes: 6 additions & 2 deletions include/common/datatypes/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ struct Edge {

void clear();

void __clear() { clear(); }
void __clear() {
clear();
}

std::string toString() const;

Expand All @@ -66,7 +68,9 @@ struct Edge {
const Value& value(const std::string& key) const;
};

inline std::ostream& operator<<(std::ostream& os, const Edge& v) { return os << v.toString(); }
inline std::ostream& operator<<(std::ostream& os, const Edge& v) {
return os << v.toString();
}

} // namespace nebula

Expand Down
80 changes: 60 additions & 20 deletions include/common/datatypes/Geography.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ struct Coordinate {
x = 0.0;
y = 0.0;
}
void __clear() { clear(); }
void __clear() {
clear();
}

bool operator==(const Coordinate& rhs) const {
return std::abs(x - rhs.x) < kEpsilon && std::abs(y - rhs.y) < kEpsilon;
}
bool operator!=(const Coordinate& rhs) const { return !(*this == rhs); }
bool operator!=(const Coordinate& rhs) const {
return !(*this == rhs);
}
bool operator<(const Coordinate& rhs) const {
if (x != rhs.x) {
return x < rhs.x;
Expand All @@ -73,11 +77,19 @@ struct Point {
explicit Point(const Coordinate& v) : coord(v) {}
explicit Point(Coordinate&& v) : coord(std::move(v)) {}

void clear() { coord.clear(); }
void __clear() { clear(); }
void clear() {
coord.clear();
}
void __clear() {
clear();
}

bool operator==(const Point& rhs) const { return coord == rhs.coord; }
bool operator<(const Point& rhs) const { return coord < rhs.coord; }
bool operator==(const Point& rhs) const {
return coord == rhs.coord;
}
bool operator<(const Point& rhs) const {
return coord < rhs.coord;
}
};

struct LineString {
Expand All @@ -87,13 +99,23 @@ struct LineString {
explicit LineString(const std::vector<Coordinate>& v) : coordList(v) {}
explicit LineString(std::vector<Coordinate>&& v) : coordList(std::move(v)) {}

uint32_t numCoord() const { return coordList.size(); }
uint32_t numCoord() const {
return coordList.size();
}

void clear() { coordList.clear(); }
void __clear() { clear(); }
void clear() {
coordList.clear();
}
void __clear() {
clear();
}

bool operator==(const LineString& rhs) const { return coordList == rhs.coordList; }
bool operator<(const LineString& rhs) const { return coordList < rhs.coordList; }
bool operator==(const LineString& rhs) const {
return coordList == rhs.coordList;
}
bool operator<(const LineString& rhs) const {
return coordList < rhs.coordList;
}
};

struct Polygon {
Expand All @@ -103,13 +125,23 @@ struct Polygon {
explicit Polygon(const std::vector<std::vector<Coordinate>>& v) : coordListList(v) {}
explicit Polygon(std::vector<std::vector<Coordinate>>&& v) : coordListList(std::move(v)) {}

uint32_t numCoordList() const { return coordListList.size(); }
uint32_t numCoordList() const {
return coordListList.size();
}

void clear() { coordListList.clear(); }
void __clear() { clear(); }
void clear() {
coordListList.clear();
}
void __clear() {
clear();
}

bool operator==(const Polygon& rhs) const { return coordListList == rhs.coordListList; }
bool operator<(const Polygon& rhs) const { return coordListList < rhs.coordListList; }
bool operator==(const Polygon& rhs) const {
return coordListList == rhs.coordListList;
}
bool operator<(const Polygon& rhs) const {
return coordListList < rhs.coordListList;
}
};

struct Geography {
Expand Down Expand Up @@ -137,17 +169,25 @@ struct Geography {

std::string asWKB() const;

std::string toString() const { return asWKT(); }
std::string toString() const {
return asWKT();
}

void clear() { geo_.~variant(); }
void clear() {
geo_.~variant();
}

void __clear() { clear(); }
void __clear() {
clear();
}

bool operator==(const Geography& rhs) const;
bool operator<(const Geography& rhs) const;
};

inline std::ostream& operator<<(std::ostream& os, const Geography& g) { return os << g.toString(); }
inline std::ostream& operator<<(std::ostream& os, const Geography& g) {
return os << g.toString();
}

} // namespace nebula

Expand Down
4 changes: 3 additions & 1 deletion include/common/datatypes/HostAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ struct HostAddr {
port = 0;
}

void __clear() { clear(); }
void __clear() {
clear();
}

std::string toString() const {
std::stringstream os;
Expand Down
4 changes: 3 additions & 1 deletion include/common/datatypes/KeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ struct KeyValue {
value.clear();
}

void __clear() { clear(); }
void __clear() {
clear();
}

bool operator==(const KeyValue& rhs) const {
if (key != rhs.key) {
Expand Down
Loading