Skip to content

Fix(clickhouse): specify DateTime64 precision for model partitioning expression#3582

Merged
treysp merged 2 commits intomainfrom
trey/fix-ch-dt64-prec
Jan 7, 2025
Merged

Fix(clickhouse): specify DateTime64 precision for model partitioning expression#3582
treysp merged 2 commits intomainfrom
trey/fix-ch-dt64-prec

Conversation

@treysp
Copy link
Contributor

@treysp treysp commented Jan 3, 2025

SQLMesh automatically partitions Clickhouse incremental by time range models, aggregating timestamps to week. If the timestamp data type is not a datetime variant, SQLMesh automatically casts it to DateTime64 in the aggregation expression.

In Clickhouse, casting to DateTime64 type requires specifying a numeric precision.

This PR specifies a precision of 9/nanoseconds (using max precision to prevent accidental truncation of timestamp digits).

@swt30
Copy link

swt30 commented Jan 5, 2025

👍 only caveat I can see is that the maximum date representable in a DateTime64(9) is 2262-04-11 23:47:16. But I won't be around to see the Y2K bug caused by that 😆 so using the maximum supported precision feels like the way to go.

This only applies when you pass a non-conformable type like a string or an integer anyway, right?

@treysp treysp force-pushed the trey/fix-ch-dt64-prec branch from a2aa0a3 to d0e8400 Compare January 6, 2025 23:26
@treysp
Copy link
Contributor Author

treysp commented Jan 6, 2025

This only applies when you pass a non-conformable type like a string or an integer anyway, right?

Yep, if time column is non-conformable AND you don't include the time column in the model partitioning expression

@treysp treysp merged commit f1a2bb0 into main Jan 7, 2025
@treysp treysp deleted the trey/fix-ch-dt64-prec branch January 7, 2025 14:09
treysp added a commit to mesmith027/sqlmesh that referenced this pull request Jan 7, 2025
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.

3 participants