Skip to content

Commit

Permalink
Add millisecond field for time map initialize (#2781)
Browse files Browse the repository at this point in the history
* Add millisecond field for time map initialize.

* Add the tck case.

* Add some bound case.
  • Loading branch information
Shylock-Hg authored Sep 24, 2021
1 parent fd2e949 commit d968b44
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
84 changes: 80 additions & 4 deletions src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class FunctionManagerTest : public ::testing::Test {
}
auto res = result.value()(argsRef);
if (res.type() != expect.type()) {
return ::testing::AssertionFailure() << "function return type check failed: " << expr;
return ::testing::AssertionFailure() << "function return type check failed, expect "
<< expect.type() << ", got " << res.type();
}
if (res != expect) {
return ::testing::AssertionFailure() << "function return value check failed: " << expr;
return ::testing::AssertionFailure()
<< "function return value check failed, expect " << expect << ", got " << res;
}
return ::testing::AssertionSuccess();
}
Expand Down Expand Up @@ -519,6 +521,42 @@ TEST_F(FunctionManagerTest, functionCall) {
{Map({{"hour", 20}, {"minute", 9}, {"second", 15}})},
Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 0))));
}
{
TEST_FUNCTION(time,
{Map({{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 10},
{"microsecond", 15}})},
Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 10015))));
}
{
TEST_FUNCTION(time,
{Map({{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 999},
{"microsecond", 999}})},
Value(time::TimeUtils::timeToUTC(Time(20, 9, 15, 999999))));
}
{
TEST_FUNCTION(time,
{Map({{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 1000},
{"microsecond", 999}})},
Value::kNullBadData);
}
{
TEST_FUNCTION(time,
{Map({{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 999},
{"microsecond", 1000}})},
Value::kNullBadData);
}
// range [(0, 0, 0, 0), (23, 59, 59, 999999)]
{
TEST_FUNCTION(time,
Expand Down Expand Up @@ -566,8 +604,46 @@ TEST_F(FunctionManagerTest, functionCall) {
{"day", 15},
{"hour", 20},
{"minute", 9},
{"second", 15}})},
Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 0))));
{"second", 15},
{"millisecond", 10},
{"microsecond", 15}})},
Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 10015))));
}
{
TEST_FUNCTION(datetime,
{Map({{"year", 2020},
{"month", 9},
{"day", 15},
{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 999},
{"microsecond", 999}})},
Value(time::TimeUtils::dateTimeToUTC(DateTime(2020, 9, 15, 20, 9, 15, 999999))));
}
{
TEST_FUNCTION(datetime,
{Map({{"year", 2020},
{"month", 9},
{"day", 15},
{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 1000},
{"microsecond", 999}})},
Value::kNullBadData);
}
{
TEST_FUNCTION(datetime,
{Map({{"year", 2020},
{"month", 9},
{"day", 15},
{"hour", 20},
{"minute", 9},
{"second", 15},
{"millisecond", 999},
{"microsecond", 1000}})},
Value::kNullBadData);
}
{
TEST_FUNCTION(datetime,
Expand Down
18 changes: 14 additions & 4 deletions src/common/time/TimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ constexpr int64_t kMaxTimestamp = std::numeric_limits<int64_t>::max() / 10000000
return Status::Error("Invalid second number `%ld'.", kv.second.getInt());
}
dt.sec = kv.second.getInt();
} else if (kv.first == "millisecond") {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999) {
return Status::Error("Invalid millisecond number `%ld'.", kv.second.getInt());
}
dt.microsec += kv.second.getInt() * 1000;
} else if (kv.first == "microsecond") {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999999) {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999) {
return Status::Error("Invalid microsecond number `%ld'.", kv.second.getInt());
}
dt.microsec = kv.second.getInt();
dt.microsec += kv.second.getInt();
} else {
return Status::Error("Invlaid parameter `%s'.", kv.first.c_str());
}
Expand Down Expand Up @@ -125,11 +130,16 @@ constexpr int64_t kMaxTimestamp = std::numeric_limits<int64_t>::max() / 10000000
return Status::Error("Invalid second number `%ld'.", kv.second.getInt());
}
t.sec = kv.second.getInt();
} else if (kv.first == "millisecond") {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999) {
return Status::Error("Invalid millisecond number `%ld'.", kv.second.getInt());
}
t.microsec += kv.second.getInt() * 1000;
} else if (kv.first == "microsecond") {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999999) {
if (kv.second.getInt() < 0 || kv.second.getInt() > 999) {
return Status::Error("Invalid microsecond number `%ld'.", kv.second.getInt());
}
t.microsec = kv.second.getInt();
t.microsec += kv.second.getInt();
} else {
return Status::Error("Invlaid parameter `%s'.", kv.first.c_str());
}
Expand Down
6 changes: 3 additions & 3 deletions tests/tck/features/mutate/InsertWithTimeType.feature
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ Feature: Insert with time-dependent types
"""
UPDATE VERTEX "test"
SET
tag_date.f_date = Date("2018-03-04"),
tag_date.f_time = Time("22:01:00"),
tag_date.f_datetime = DateTime("2018-03-04T22:30:40")
tag_date.f_date = Date({year: 2018, month: 3, day: 4}),
tag_date.f_time = Time({hour: 22, minute: 1, second: 0, millisecond: 0, microsecond: 0}),
tag_date.f_datetime = DateTime({year: 2018, month: 3, day: 4, hour: 22, minute: 30, second: 40, millisecond: 0, microsecond: 0})
YIELD f_date, f_time, f_datetime;
"""
Then the result should be, in any order:
Expand Down

0 comments on commit d968b44

Please sign in to comment.