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 toMillisecond function #60281

Merged
merged 13 commits into from Mar 1, 2024

Conversation

Blargian
Copy link
Contributor

@Blargian Blargian commented Feb 22, 2024

Closes #54746

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Added function toMillisecond which returns the millisecond component for values of typeDateTime or DateTime64.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Feb 22, 2024
@robot-clickhouse robot-clickhouse added the pr-feature Pull request with new product feature label Feb 22, 2024
@robot-clickhouse
Copy link
Member

robot-clickhouse commented Feb 22, 2024

This is an automated comment for commit 52b1fc6 with description of existing statuses. It's updated for the latest CI running

⏳ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
Docs checkBuilds and tests the documentation✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending

@yariks5s yariks5s assigned yariks5s and rschu1ze and unassigned yariks5s Feb 22, 2024
@rschu1ze rschu1ze changed the title toMillisecond function Add toMillisecond function Feb 28, 2024
@rschu1ze
Copy link
Member

@Blargian I made some fixes (including some in related code). The problem with this PR is that the millisecond calculation is wrong. Kindly see my annotations in tests/queries/0_stateless/02998_to_milliseconds.sql for the expected results (basically the millisecond component of the input, similar to what toSecond, toMinute etc. return.

@Blargian
Copy link
Contributor Author

Blargian commented Feb 28, 2024

@Blargian I made some fixes (including some in related code). The problem with this PR is that the millisecond calculation is wrong. Kindly see my annotations in tests/queries/0_stateless/02998_to_milliseconds.sql for the expected results (basically the millisecond component of the input, similar to what toSecond, toMinute etc. return.

@rschu1ze I am probably overlooking something but the Time or UInt64 type seems only to be storing the time since epoch in seconds. For instance toUInt64(toDateTime64('2023-04-21 10:20:30.123', 3)) returns 1682065230 from which the minimum time interval recoverable is only seconds. Is Time not the correct type to be working with here as the input parameter to toMillisecond as it is in toSecond?

@rschu1ze
Copy link
Member

rschu1ze commented Feb 28, 2024

That's right, Time or UInt64 isn't sufficient. I did not debug the whole thing, so I can only give some pointers:

  • ToDateTimeComponentsImpl in src/Functions/DateTimeTransforms.h shows how to get sub-second components (milliseconds) for values of (SQL) type DateTime64. One basically also needs the scale multiplier for that.
  • The code in ToStartOfMillisecondImpl (src/Functions/DateTimeTransforms.h) seems relevant. You could debug what happens in SQL function toStartOfMillisecond() (which however returns a DateTime64 instead of an integer).
  • Perhaps it is as easy as adding a new function (similar in spirit to static UInt64 execute(const DateTime64 & datetime64, Int64 scale_multiplier, const DateLUTImpl &) to ToMillisecondImpl which uses the scale_multiplier to determine the result.

@rschu1ze
Copy link
Member

rschu1ze commented Mar 1, 2024

Approved (will merge when the tests in CI are green), thanks a lot for taking care!

@rschu1ze rschu1ze merged commit 44c3de1 into ClickHouse:master Mar 1, 2024
16 of 18 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 1, 2024
@tavplubix
Copy link
Member

will merge when the tests in CI are green

Well, they are not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement toMillisecond()
6 participants