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

refactor(types): spilt timestamp to timestamp and timestampnano #20192

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

xxhZs
Copy link
Contributor

@xxhZs xxhZs commented Jan 17, 2025

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

in #19827, we support timestamp with nano, but we can't support interval with nano in a similar way. So we have to introduce the new type, and correspondingly, we should implement the new type timestamp_nano, so we distinguish between timestamp_nano and timestamp in this pr

Checklist

  • I have written necessary rustdoc comments.
  • I have added necessary unit tests and integration tests.
  • I have added test labels as necessary.
  • I have added fuzzing tests or opened an issue to track them.
  • My PR contains breaking changes.
  • My PR changes performance-critical code, so I will run (micro) benchmarks and present the results.
  • My PR contains critical fixes that are necessary to be merged into the latest release.

Documentation

  • My PR needs documentation updates.
Release note

@xxhZs xxhZs marked this pull request as ready for review January 17, 2025 05:42
@xxhZs xxhZs requested review from xiangjinwu and chenzl25 January 23, 2025 06:41
Copy link

gru-agent bot commented Jan 23, 2025

This pull request has been modified. If you want me to regenerate unit test for any of the files related, please find the file in "Files Changed" tab and add a comment @gru-agent. (The github "Comment on this file" feature is in the upper right corner of each file in "Files Changed" tab.)

Copy link
Contributor

@chenzl25 chenzl25 left a comment

Choose a reason for hiding this comment

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

After this PR, what's the precision of the timestamp type?

@xxhZs
Copy link
Contributor Author

xxhZs commented Jan 23, 2025

After this PR, what's the precision of the timestamp type?

timestamp -> 6 us
timestampnano -> 9 ns

@chenzl25
Copy link
Contributor

After this PR, what's the precision of the timestamp type?

timestamp -> 6 us timestampnano -> 9 ns

I remembered timestamp should already be nano precision. Does it mean this is a breaking change?

@xiangjinwu
Copy link
Contributor

I remembered timestamp should already be nano precision. Does it mean this is a breaking change?

It was also a breaking change regarding the extract function when we upgraded the precision in #19827 - same expression returns different value in different version: 1.234567 vs 1.234567000.

@xxhZs
Copy link
Contributor Author

xxhZs commented Jan 24, 2025

It was also a breaking change regarding the extract function when we upgraded the precision in #19827 - same expression returns different value in different version: 1.234567 vs 1.234567000.

Yes. There should be no compatibility issues with this pr, but it will make some user behavior changes

@chenzl25
Copy link
Contributor

I remembered timestamp should already be nano precision. Does it mean this is a breaking change?

It was also a breaking change regarding the extract function when we upgraded the precision in #19827 - same expression returns different value in different version: 1.234567 vs 1.234567000.

I am ok with this PR to keep the timestamp with us precision and introduce a new timestampnano type to introduce nano precision timestamp. It can make the code clearer and it doesn't make too much sense to let timestamp and timestampnano have the same precision. What do you think @xiangjinwu

@xiangjinwu
Copy link
Contributor

I agree. I meant this breaking change is acceptable and can actually "fix"/revert a previous breaking change.

Copy link
Contributor

@chenzl25 chenzl25 left a comment

Choose a reason for hiding this comment

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

Considering other system nano timestamp type naming conventions, I think it's better to use timestamp_ns instead of timestampnano
https://arc.net/l/quote/xaiqjmve
https://duckdb.org/docs/sql/data_types/timestamp.html

@xxhZs xxhZs force-pushed the xxh/nanotimestamp-spilt branch from 5492b34 to 776bb4a Compare February 10, 2025 08:46
@xxhZs xxhZs force-pushed the xxh/nanotimestamp-spilt branch from 61df181 to 3258b9e Compare February 10, 2025 09:48
Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

Summary:

  • Stick to timestamp_ns. Avoid using timestampns, timestampnano, timestamp_nano simultaneously.
  • We may support operators on timestamp_ns in future PRs. A lot of them are missing in this PR, or incorrect, or requires timestamptz_ns/time_ns/interval_ns before they can be properly implemented. The minimal ones are: being able to write and read (thus from and into string), and cast from/into timestamp, and generic operators that applies to most datatypes (e.g. is null / case-when / coalesce / count / = / is distinct from ... See top 2 sections in Tracking: Basic Built-in Functions #112).
  • For source and sink, either test each case (can be time consuming) or leave them unimplemented.

Comment on lines +182 to +184
if subsec_nanosecond % 1_000 != 0 {
return Err(ErrorKind::ParseTimestamp.into());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

PostgreSQL tolerates such lossy parsing, and rounds to even:

test=# select '2020-01-01 12:34:56.123456500'::timestamp;
         timestamp          
----------------------------
 2020-01-01 12:34:56.123456
(1 row)

test=# select '2020-01-01 12:34:56.123457500'::timestamp;
         timestamp          
----------------------------
 2020-01-01 12:34:56.123458
(1 row)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, what's being considered here is restoring rw's very first setting, not sure we want to correct it to pg consistency

@@ -58,6 +58,7 @@ v_bool boolean,
v_date date,
v_timestamp timestamptz,
v_ts_ntz timestamp,
v_timestamp_ns timestamp_ns,
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this test pass?

fix ci
@xxhZs xxhZs force-pushed the xxh/nanotimestamp-spilt branch from e0b60d6 to da71941 Compare February 19, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants