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 millisecond field for time map initialize. #2781

Merged
21 changes: 17 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,15 @@ 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))));
}
// range [(0, 0, 0, 0), (23, 59, 59, 999999)]
{
TEST_FUNCTION(time,
Expand Down Expand Up @@ -566,8 +577,10 @@ 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,
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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use switch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch can't process string type.

if (kv.second.getInt() < 0 || kv.second.getInt() > 999) {
return Status::Error("Invalid millisecond number `%ld'.", kv.second.getInt());
Shylock-Hg marked this conversation as resolved.
Show resolved Hide resolved
}
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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add a new test case instead of modifying?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The origin case is tested in other case too.

YIELD f_date, f_time, f_datetime;
"""
Then the result should be, in any order:
Expand Down