Preserve fractional seconds in to_timestamp() - #338
Conversation
|
This is not the correct solution. Switch to Postgres: ClickHouse: |
theory
left a comment
There was a problem hiding this comment.
Much better, thanks. Just needs a few tweaks.
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) IS NOT NULL; | ||
| SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) IS NOT NULL; |
There was a problem hiding this comment.
Are these not coming out the same? We want to make sure they're equivalent, not just non-NULL.
| that could corrupt memory and hang ([#296]). | ||
| * Fixed subsecond precision lost inserting timestamps over HTTP ([#300]). | ||
| * Fixed loss of subsecond precision in `to_timestamp(float8)` by mapping it | ||
| to ClickHouse's microsecond-precision `toDateTime64()` function. |
| `fromUnixTimestamp(toInt64())` in ClickHouse. | ||
| `toDateTime64(value, 6, 'UTC')` in ClickHouse. |
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(f64) IS NOT NULL; | ||
| SELECT * FROM t6 WHERE to_timestamp(f64) = to_timestamp(0); | ||
| EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM t6 WHERE to_timestamp(i64) = to_timestamp(0); |
There was a problem hiding this comment.
We still need to be sure that epoch 0 is the same. Please restore.
There was a problem hiding this comment.
Thanks, fixed the remaining tweaks. I restored the epoch-0 coverage, changed the integer and float tests to verify equality, added the PR link to the changelog, and restored the historical changelog entry. I also rebased onto main and pushed commit 221d64d.
Please take another look when you have a chance.
Map to_timestamp(float8) to ClickHouse toDateTime64 with six-digit precision and UTC so fractional Unix timestamps survive pushdown. Cover integer and float inputs at epoch zero and fractional timestamps, and document the ClickHouse mapping.
73fdceb to
221d64d
Compare
Summary
to_timestamp(float8) was pushed down as fromUnixTimestamp(toInt64(...)), which truncated fractional Unix timestamps. Leave the built-in for PostgreSQL evaluation so subsecond precision is preserved.
The regression coverage checks that 2042323443.232 does not match 2042323443, and does match the fractional value.
Testing