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 Extract DateTimeFromString #6300

Merged
merged 15 commits into from
Dec 1, 2022

Conversation

birdstorm
Copy link
Contributor

@birdstorm birdstorm commented Nov 11, 2022

What problem does this PR solve?

Issue number: close #6304

Support ExtractDateTimeFromString Sig.

Problem Summary:

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 11, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • mengxin9014
  • ywqzzy

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 11, 2022
Signed-off-by: birdstorm <[email protected]>
@birdstorm birdstorm force-pushed the support-extract-datetime-string branch from ac7785b to f9cadfa Compare November 16, 2022 05:26
Signed-off-by: birdstorm <[email protected]>
@birdstorm
Copy link
Contributor Author

/run-all-tests

@xzhangxian1008
Copy link
Contributor

/assign

dbms/src/Functions/FunctionsDateTime.h Outdated Show resolved Hide resolved
dbms/src/Functions/FunctionsDuration.h Show resolved Hide resolved
dbms/src/Functions/FunctionsDateTime.h Outdated Show resolved Hide resolved
dbms/src/Functions/FunctionsDateTime.h Outdated Show resolved Hide resolved
dbms/src/Functions/tests/gtest_datetime_extract.cpp Outdated Show resolved Hide resolved
{"121231113045", "2012-12-31 11:30:45"},
{"2012-02-29", "2012-02-29 00:00:00"},
{"00-00-00", "0000-00-00 00:00:00"},
// {"00-00-00 00:00:00.123", "2000-00-00 00:00:00.123"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test cases use fixed fsp; automatically calculating the fsp of a String is not implemented yet. I think we can leave these cases for later.

{" \t\r2012^12^31T11+30+45 \n ", {31113045000000, 31113045, 311130, 3111}},
{"20121231113045", {31113045000000, 31113045, 311130, 3111}},
{"121231113045", {31113045000000, 31113045, 311130, 3111}},
// {"1701020304.1", {2030401000000, 2030401, 20304, 203}},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parsing for float string is not implemented yet. It is not going to be done in this PR.

@birdstorm
Copy link
Contributor Author

/run-all-tests

fmt::format("Illegal type {} of second argument of function {}. Must be DateOrDateTime.", arguments[1]->getName(), getName()),
Errors::Coprocessor::BadRequest);
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

return std::make_shared<DataTypeInt64>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should return nullable type as some extraction may fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

consider doing it in another PR.

dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Functions/FunctionsDateTime.h Outdated Show resolved Hide resolved
dbms/src/Functions/FunctionsDateTime.h Outdated Show resolved Hide resolved
dbms/src/Common/MyTime.cpp Outdated Show resolved Hide resolved
return signMultiplier(duration) * (duration.hours() * 10000LL + duration.minutes() * 100LL + duration.seconds());
}

static Int64 extractDayMinute(Int64 nano)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about overloading this function with static Int64 extractDayMinute(const MyDuration &) so that we can directly pass MyDuration value to the function and reduce usless construction and destruction.

Not only this but all functions similar to this function

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 think this is not necessary because functions named extractDayMinute have different approaches. The DateTime and the Duration are not stored in the same format, they have different encoding formats and implementations. Moving these logics together may confuse readers.

result = ExtractMyDurationImpl::extractDayMinute(duration.nanoSecond());

Field datetime_field = parseMyDateTime(dtStr);
if (!datetime_field.isNull())
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that we prefer to return value which is parsed by parseMyDateTime, how about moving codes related with paring duration to the tail of codes that parse datetime?

Not only in this function but also all similar functions

Copy link
Contributor Author

@birdstorm birdstorm Nov 26, 2022

Choose a reason for hiding this comment

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

We prefer to return value that is equivalently parsed by parseMyDuration and parseMyDateTime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We prefer to return value that is equivalently parsed by parseMyDuration and parseMyDateTime

okk

@birdstorm
Copy link
Contributor Author

/run-all-tests

@xzhangxian1008
Copy link
Contributor

lgtm

Copy link
Contributor

@mengxin9014 mengxin9014 left a comment

Choose a reason for hiding this comment

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

Others LGTM

dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 1, 2022
Copy link
Contributor

@ywqzzy ywqzzy left a comment

Choose a reason for hiding this comment

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

Rest LGTM

dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
dbms/src/Common/StringUtils/StringUtils.h Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 1, 2022
@birdstorm
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

@birdstorm: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 367914f

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 1, 2022
@ti-chi-bot ti-chi-bot merged commit a460f48 into pingcap:master Dec 1, 2022
@birdstorm birdstorm deleted the support-extract-datetime-string branch December 1, 2022 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ScalarFuncSig_ExtractDatetimeFromString in TiFlash
5 participants