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 duration. #3338

Merged
merged 29 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
719ecf1
Add duration.
Shylock-Hg Nov 22, 2021
0d0db53
Merge branch 'master' into feature/duration
Shylock-Hg Nov 22, 2021
7384e90
Add datetime/duration computation support.
Shylock-Hg Nov 24, 2021
33b84b1
Merge branch 'feature/duration' of github.com:Shylock-Hg/nebula into …
Shylock-Hg Nov 24, 2021
495eb04
Merge branch 'master' into feature/duration
Shylock-Hg Nov 24, 2021
0e8158b
Remove debug code.
Shylock-Hg Nov 24, 2021
f19adcc
Merge branch 'master' into feature/duration
Shylock-Hg Nov 24, 2021
47d94b2
Merge branch 'master' into feature/duration
Shylock-Hg Nov 30, 2021
769afb1
Add operator override.
Shylock-Hg Dec 1, 2021
0729f45
Merge branch 'master' into feature/duration
Shylock-Hg Dec 1, 2021
5b3c6a4
Support syntax.
Shylock-Hg Dec 2, 2021
2b353f0
Merge branch 'feature/duration' of github.com:Shylock-Hg/nebula into …
Shylock-Hg Dec 2, 2021
438e0a8
Merge branch 'master' into feature/duration
Shylock-Hg Dec 2, 2021
a415d76
Fix the compare behavior.
Shylock-Hg Dec 2, 2021
1f6428c
Merge branch 'master' into feature/duration
Shylock-Hg Dec 2, 2021
de558c7
Store property data in disk.
Shylock-Hg Dec 3, 2021
362f0ae
Merge branch 'feature/duration' of github.com:Shylock-Hg/nebula into …
Shylock-Hg Dec 3, 2021
0339144
Merge branch 'master' into feature/duration
Shylock-Hg Dec 3, 2021
beca931
Merge branch 'master' into feature/duration
Shylock-Hg Dec 6, 2021
2d23093
Merge branch 'master' into feature/duration
Shylock-Hg Dec 8, 2021
3e8bfe9
Merge branch 'master' into feature/duration
Shylock-Hg Dec 8, 2021
f454f9c
Merge branch 'master' into feature/duration
Shylock-Hg Dec 8, 2021
525aa8f
Merge branch 'master' into feature/duration
Shylock-Hg Dec 9, 2021
db6a4f1
Merge branch 'master' into feature/duration
Shylock-Hg Dec 10, 2021
cbeea71
Merge branch 'master' of https://github.com/vesoft-inc/nebula into fe…
Shylock-Hg Dec 15, 2021
729de56
Merge branch 'master' into feature/duration
Shylock-Hg Dec 15, 2021
7938ca1
Merge branch 'master' into feature/duration
Shylock-Hg Dec 15, 2021
e8a94bf
Merge branch 'master' into feature/duration
yixinglu Dec 18, 2021
f179fb4
Merge branch 'master' into feature/duration
Sophie-Xie Dec 20, 2021
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
11 changes: 11 additions & 0 deletions src/codec/RowReaderV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ Value RowReaderV2::getValueByIndex(const int64_t index) const noexcept {
dt.microsec = microsec;
return dt;
}
case PropertyType::DURATION: {
Duration d;
memcpy(reinterpret_cast<void*>(&d.seconds), &data_[offset], sizeof(int64_t));
memcpy(reinterpret_cast<void*>(&d.microseconds),
&data_[offset + sizeof(int64_t)],
sizeof(int32_t));
memcpy(reinterpret_cast<void*>(&d.months),
&data_[offset + sizeof(int64_t) + sizeof(int32_t)],
sizeof(int32_t));
return d;
}
case PropertyType::GEOGRAPHY: {
int32_t strOffset;
int32_t strLen;
Expand Down
31 changes: 31 additions & 0 deletions src/codec/RowWriterV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ RowWriterV2::RowWriterV2(RowReader& reader) : RowWriterV2(reader.getSchema()) {
case Value::Type::GEOGRAPHY:
set(i, v.moveGeography());
break;
case Value::Type::DURATION:
set(i, v.moveDuration());
break;
default:
LOG(FATAL) << "Invalid data: " << v << ", type: " << v.typeName();
}
Expand Down Expand Up @@ -209,6 +212,8 @@ WriteResult RowWriterV2::setValue(ssize_t index, const Value& val) noexcept {
return write(index, val.getDateTime());
case Value::Type::GEOGRAPHY:
return write(index, val.getGeography());
case Value::Type::DURATION:
return write(index, val.getDuration());
default:
return WriteResult::TYPE_MISMATCH;
}
Expand Down Expand Up @@ -762,6 +767,29 @@ WriteResult RowWriterV2::write(ssize_t index, const DateTime& v) noexcept {
return WriteResult::SUCCEEDED;
}

WriteResult RowWriterV2::write(ssize_t index, const Duration& v) noexcept {
auto field = schema_->field(index);
auto offset = headerLen_ + numNullBytes_ + field->offset();
switch (field->type()) {
case PropertyType::DURATION:
memcpy(&buf_[offset], reinterpret_cast<const void*>(&v.seconds), sizeof(int64_t));
memcpy(&buf_[offset + sizeof(int64_t)],
reinterpret_cast<const void*>(&v.microseconds),
sizeof(int32_t));
memcpy(&buf_[offset + sizeof(int64_t) + sizeof(int32_t)],
reinterpret_cast<const void*>(&v.months),
sizeof(int32_t));
break;
default:
return WriteResult::TYPE_MISMATCH;
}
if (field->nullable()) {
clearNullBit(field->nullFlagPos());
}
isSet_[index] = true;
return WriteResult::SUCCEEDED;
}

WriteResult RowWriterV2::write(ssize_t index, const Geography& v) noexcept {
auto field = schema_->field(index);
auto geoShape = field->geoShape();
Expand Down Expand Up @@ -815,6 +843,9 @@ WriteResult RowWriterV2::checkUnsetFields() noexcept {
case Value::Type::GEOGRAPHY:
r = write(i, defVal.getGeography());
break;
case Value::Type::DURATION:
r = write(i, defVal.getDuration());
break;
default:
LOG(FATAL) << "Unsupported default value type: " << defVal.typeName()
<< ", default value: " << defVal
Expand Down
1 change: 1 addition & 0 deletions src/codec/RowWriterV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class RowWriterV2 {
WriteResult write(ssize_t index, const Date& v) noexcept;
WriteResult write(ssize_t index, const Time& v) noexcept;
WriteResult write(ssize_t index, const DateTime& v) noexcept;
WriteResult write(ssize_t index, const Duration& v) noexcept;

WriteResult write(ssize_t index, const Geography& v) noexcept;
};
Expand Down
11 changes: 11 additions & 0 deletions src/codec/test/RowWriterV2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Geography geogPolygon = Polygon(
Coordinate(-102.9, 37.6),
Coordinate(-96.8, 37.5),
Coordinate(-100.1, 41.4)}});
const Duration du = Duration(1, 2, 3);

TEST(RowWriterV2, NoDefaultValue) {
SchemaWriter schema(12 /*Schema version*/);
Expand All @@ -68,6 +69,7 @@ TEST(RowWriterV2, NoDefaultValue) {
schema.appendCol(
"Col18", PropertyType::GEOGRAPHY, 0, false, nullptr, meta::cpp2::GeoShape::POLYGON);
schema.appendCol("Col19", PropertyType::GEOGRAPHY, 0, true, nullptr, meta::cpp2::GeoShape::ANY);
schema.appendCol("Col20", PropertyType::DURATION);

ASSERT_EQ(Value::Type::STRING, sVal.type());
ASSERT_EQ(Value::Type::INT, iVal.type());
Expand All @@ -92,6 +94,7 @@ TEST(RowWriterV2, NoDefaultValue) {
EXPECT_EQ(WriteResult::SUCCEEDED, writer1.set(16, geogLineString));
EXPECT_EQ(WriteResult::SUCCEEDED, writer1.set(17, geogPolygon));
// Purposely skip the col19
EXPECT_EQ(WriteResult::SUCCEEDED, writer1.set(19, du));
ASSERT_EQ(WriteResult::SUCCEEDED, writer1.finish());

RowWriterV2 writer2(&schema);
Expand All @@ -114,6 +117,7 @@ TEST(RowWriterV2, NoDefaultValue) {
EXPECT_EQ(WriteResult::SUCCEEDED, writer2.set("Col17", geogLineString));
EXPECT_EQ(WriteResult::SUCCEEDED, writer2.set("Col18", geogPolygon));
// Purposely skip the col19
EXPECT_EQ(WriteResult::SUCCEEDED, writer2.set("Col20", du));
ASSERT_EQ(WriteResult::SUCCEEDED, writer2.finish());

std::string encoded1 = std::move(writer1).moveEncodedStr();
Expand Down Expand Up @@ -253,6 +257,13 @@ TEST(RowWriterV2, NoDefaultValue) {
v2 = reader2->getValueByIndex(18);
EXPECT_EQ(Value::Type::NULLVALUE, v1.type());
EXPECT_EQ(v1, v2);

// Col20
v1 = reader1->getValueByName("Col20");
v2 = reader2->getValueByIndex(19);
EXPECT_EQ(Value::Type::DURATION, v1.type());
EXPECT_EQ(du, v1.getDuration());
EXPECT_EQ(v1, v2);
}

TEST(RowWriterV2, WithDefaultValue) {
Expand Down
3 changes: 3 additions & 0 deletions src/codec/test/SchemaWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ SchemaWriter& SchemaWriter::appendCol(folly::StringPiece name,
case PropertyType::GEOGRAPHY:
size = 2 * sizeof(int32_t); // as same as STRING
break;
case PropertyType::DURATION:
size = sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t);
break;
default:
LOG(FATAL) << "Unknown column type";
}
Expand Down
1 change: 1 addition & 0 deletions src/common/datatypes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nebula_add_library(
List.cpp
Set.cpp
Geography.cpp
Duration.cpp
)

nebula_add_subdirectory(test)
2 changes: 2 additions & 0 deletions src/common/datatypes/CommonCpp2Ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Point;
struct LineString;
struct Polygon;
struct Geography;
struct Duration;
} // namespace nebula

namespace apache::thrift {
Expand All @@ -52,6 +53,7 @@ SPECIALIZE_CPP2OPS(nebula::Point);
SPECIALIZE_CPP2OPS(nebula::LineString);
SPECIALIZE_CPP2OPS(nebula::Polygon);
SPECIALIZE_CPP2OPS(nebula::Geography);
SPECIALIZE_CPP2OPS(nebula::Duration);

} // namespace apache::thrift

Expand Down
Loading