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

fix datetime format #4524

Merged
merged 10 commits into from
Aug 30, 2022
Merged

fix datetime format #4524

merged 10 commits into from
Aug 30, 2022

Conversation

caton-hpg
Copy link
Contributor

@caton-hpg caton-hpg commented Aug 16, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number: #4487

Description:

fixed #4487.

It will be BAD_DATA if input a bad year or month.

(root@nebula) [(none)]> return datetime("32767");
+-----------------------------+
| datetime("32767")           |
+-----------------------------+
| 32767-01-01T00:00:00.000000 |
+-----------------------------+
Got 1 rows (time spent 1900/2890 us)


(root@nebula) [(none)]> return datetime("32768");
+-------------------+
| datetime("32768") |
+-------------------+
| BAD_DATA          |
+-------------------+
Got 1 rows (time spent 1265/1800 us)


(root@nebula) [(none)]> return datetime("-32768");
+------------------------------+
| datetime("-32768")           |
+------------------------------+
| -32768-01-01T00:00:00.000000 |
+------------------------------+
Got 1 rows (time spent 1127/1800 us)


(root@nebula) [(none)]> return datetime("-32769");
+--------------------+
| datetime("-32769") |
+--------------------+
| BAD_DATA           |
+--------------------+
Got 1 rows (time spent 1084/1699 us)


How do you solve it?

year is in [-32768,32767].

Special notes for your reviewer, ex. impact of this fix, design document, etc:

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

@Shylock-Hg
Copy link
Contributor

Shylock-Hg commented Aug 16, 2022

I think it's an out of range date, so you could check range and return error. Don't modify parser (and test).

@Sophie-Xie Sophie-Xie added the ready-for-testing PR: ready for the CI test label Aug 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2022

Codecov Report

Merging #4524 (0d7e1ab) into master (c884477) will increase coverage by 0.02%.
The diff coverage is 95.50%.

@@            Coverage Diff             @@
##           master    #4524      +/-   ##
==========================================
+ Coverage   84.66%   84.68%   +0.02%     
==========================================
  Files        1357     1357              
  Lines      135081   135150      +69     
==========================================
+ Hits       114360   114456      +96     
+ Misses      20721    20694      -27     
Impacted Files Coverage Δ
src/parser/test/ParserTest.cpp 100.00% <ø> (ø)
src/clients/meta/MetaClient.cpp 76.18% <84.61%> (-0.20%) ⬇️
src/storage/test/GetPropTest.cpp 95.34% <94.59%> (-0.05%) ⬇️
src/clients/meta/MetaClient.h 92.30% <100.00%> (ø)
src/common/function/test/FunctionManagerTest.cpp 98.84% <100.00%> (ø)
src/common/time/TimeUtils.cpp 89.40% <100.00%> (ø)
src/common/time/parser/test/DateTimeParserTest.cpp 99.52% <100.00%> (+0.06%) ⬆️
src/storage/exec/QueryUtils.h 94.01% <100.00%> (+0.10%) ⬆️
src/graph/executor/StorageAccessExecutor.h 57.77% <0.00%> (-8.89%) ⬇️
src/graph/context/Result.cpp 70.00% <0.00%> (-7.78%) ⬇️
... and 38 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@caton-hpg
Copy link
Contributor Author

Fixed.

year is in [0, 9999]
month is in [1, 12]

@@ -44,6 +44,14 @@ class TimeUtils {
if ((p[date.month] - p[date.month - 1]) < date.day) {
return Status::Error("`%s' is not a valid date.", date.toString().c_str());
}
if (date.year < 0 || date.year > 9999) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check it in parser, greater than 9999 is also valid, our upper bound is int32_t::max().

Copy link
Contributor

Choose a reason for hiding this comment

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

Lower bound too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talk with @HarrisChu .
He thinks date.year should be year. Should not be int32_t::max().

Copy link
Contributor

Choose a reason for hiding this comment

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

It's obviously incorrect, we should provide time range as wide as possible for user. You could check Postgres in https://www.postgresql.org/docs/9.1/datatype-datetime.html or other databases.

Copy link
Contributor

Choose a reason for hiding this comment

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

what's your expected for below queries:

yield datetime(-1)
yield datetime(1000)
yield datetime(123456)

yield datetime("-1")
yield datetime("1000")
yield datetime("123456")

Copy link
Contributor

Choose a reason for hiding this comment

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

All valid date.

Copy link
Contributor

Choose a reason for hiding this comment

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

Negative date means B.C.

Copy link
Contributor

Choose a reason for hiding this comment

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

image

one is for epoch, the other is just year

Copy link
Contributor

Choose a reason for hiding this comment

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

datetime("-1") is unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. year is in [-32767,32767].

@caton-hpg caton-hpg force-pushed the datetime_format branch 2 times, most recently from da33162 to b114ad1 Compare August 24, 2022 09:36
@@ -25,7 +25,8 @@ constexpr int64_t kMaxTimestamp = std::numeric_limits<int64_t>::max() / 10000000
return Status::Error("Invalid value type.");
}
if (kv.first == "year") {
if (kv.second.getInt() < std::numeric_limits<int16_t>::min() ||
// year should be in [-32767, 32767] and same as parser
if (kv.second.getInt() <= std::numeric_limits<int16_t>::min() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Why less and equal?

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 max of year in paser is 32767. The min is -32767.
In order to be same as parser.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where limit this in parser?

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 year, month, day, hour and others are INTEGER.
INTEGER is a [0-9]+ and cannot be a negative int.
Negative year supports by

| NEGATIVE INTEGER NEGATIVE INTEGER NEGATIVE INTEGER {
    $$ = new nebula::Date(0-$2, $4, $6);

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't catch you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed. year is in [-32768,32767].

@caton-hpg caton-hpg force-pushed the datetime_format branch 2 times, most recently from 9c4d504 to 706b471 Compare August 25, 2022 05:31
Shylock-Hg
Shylock-Hg previously approved these changes Aug 25, 2022
@Shylock-Hg
Copy link
Contributor

We'd better avoid force-push

Copy link
Contributor

@codesigner codesigner left a comment

Choose a reason for hiding this comment

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

Nice

@Sophie-Xie Sophie-Xie merged commit 474554f into vesoft-inc:master Aug 30, 2022
@jinyingsunny
Copy link

ent-3.3 checked

@foesa-yang foesa-yang added the doc affected PR: improvements or additions to documentation label Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc affected PR: improvements or additions to documentation ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid format for datetime
8 participants