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(clickhouse): use DateTime64(6) type in incremental time filter #3268

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

treysp
Copy link
Contributor

@treysp treysp commented Oct 18, 2024

Clickhouse background

Clickhouse has two datetime types:

  • DateTime: fixed one second precision
  • DateTime64: user-specified precision (default of 3/millisecond when bare type passed)

Clickhouse errors if you try to cast a string containing fractional seconds to DateTime.

Current PR

SQLMesh time intervals are sometimes calculated as [datetime - 1 microsecond], returning values containing fractional seconds.

This PR prevents fractional second casting errors by always using DateTime64 in incremental time filters. It uses a default precision of 6 unless the user explicitly passed DateTime64.

The returned type is non-nullable by default. In SCD models, however, we generate statements like CAST(NULL AS DateTime64) that require a nullable type. Therefore, we force nullable types when calling to_time_column() in the SCD adapter method.

@treysp treysp force-pushed the trey/ch-dt64 branch 2 times, most recently from 2dcff3b to 9885590 Compare October 18, 2024 22:57
@treysp treysp changed the title Trey/ch dt64 Fix(clickhouse): use DateTime64(6) type in incremental time filter Oct 18, 2024
@erindru
Copy link
Collaborator

erindru commented Oct 20, 2024

LGTM, were you meant to leave this as Draft?

@treysp
Copy link
Contributor Author

treysp commented Oct 21, 2024

I thought this could be affected by how we go in tobymao/sqlglot#4269, so was holding it until that is resolved

@treysp treysp marked this pull request as ready for review October 22, 2024 15:04
@treysp treysp merged commit 5220324 into main Oct 22, 2024
23 checks passed
@treysp treysp deleted the trey/ch-dt64 branch October 22, 2024 19:39
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.

2 participants