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

Chrono support #188

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

Conversation

dean-shaff
Copy link

Summary

Add support for chrono.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided so that we can include it in CHANGELOG later
  • For significant changes, documentation in README and https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Dean Shaff seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

serprex
serprex previously approved these changes Dec 11, 2024
@serprex
Copy link
Member

serprex commented Dec 12, 2024

https://docs.rs/chrono/latest/chrono/serde/ts_microseconds/index.html should give microsecond precision, fixing CI

Copy link
Collaborator

@loyd loyd left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

@@ -69,17 +69,29 @@ watch = ["dep:sha-1", "dep:serde_json", "serde/derive"]
uuid = ["dep:uuid"]
time = ["dep:time"]
lz4 = ["dep:lz4_flex", "dep:cityhash-rs"]

chrono = ["dep:chrono", "dep:serde_json"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

It shouldn't require the serde_json crate.

// or if you prefer chrono:
#[derive(Row, Serialize, Deserialize)]
struct MyRow {
ts: u32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ts and dt are shown in one struct MyRow, so let's show chrono also in that one row; it seems redundant to copy-paste the ts variant here.

Same for other examples

```
</details>
* `Date32` maps to/from `i32` or a newtype around it and represents a number of days elapsed since `1970-01-01`. Also, [`time::Date`](https://docs.rs/time/latest/time/struct.Date.html) is supported by using `serde::time::date32`, that requires the `time` feature.
* `Date32` maps to/from `i32` or a newtype around it and represents a number of days elapsed since `1970-01-01`. Also, [`time::Date`](https://docs.rs/time/latest/time/struct.Date.html) is supported by using `serde::time::date32`, that requires the `time` feature. `chrono::NaiveDate` is supported by using `serde::chrono::date`, requiring the `chrono` feature.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's rephrase it using a list with all variants.

Also, to be consistent, we need to provide a link to these types (as for time-based types).

@@ -138,6 +138,25 @@ pub struct Row {
pub datetime64_9: OffsetDateTime,
#[serde(with = "clickhouse::serde::time::datetime64::nanos")]
pub datetime64_9_tz: OffsetDateTime,

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about adding the time_ prefix to the lines above?

@@ -106,6 +106,355 @@ pub mod uuid {
}
}

#[cfg(feature = "chrono")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic should be tested in the same way as the time feature (via integration tests with a real CH server without serde_json)
https://github.com/ClickHouse/clickhouse-rs/blob/main/tests/it/time.rs

This unit tests are useless with more reliable integration tests.

S: Serializer,
{
let ts = dt.timestamp_nanos_opt().ok_or_else(|| {
S::Error::custom(format!("Can't create a timestamp from {dt}"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

These messages aren't consistent with time variants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants