goccy / bigquery-emulator

BigQuery emulator server implemented in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`TIMESTAMP_TRUNC` gives incorrect results for `SECOND` and `MILLISECOND`

Zherdev opened this issue · comments

What happened?

TIMESTAMP_TRUNC gives incorrect results for SECOND and MILLISECOND

it truncates all seconds for SECOND. It truncates all milliseconds for MILLISECOND

What did you expect to happen?

select current_timestamp(), timestamp_trunc(current_timestamp(), millisecond), timestamp_trunc(current_timestamp(), second),timestamp_trunc(current_timestamp(), minute)

Expected (Google BQ):

| 2024-06-28 10:45:58.321682 UTC | 2024-06-28 10:45:58.321000 UTC | 2024-06-28 10:45:58 UTC | 2024-06-28 10:45:00 UTC |

Actual (bigquery-emulator):

| 2024-06-28 08:24:56 |   2024-06-28 08:24:56   | 2024-06-28 08:24:00 | 2024-06-28 08:24:00 |

You can see missing seconds in the col3. For col2 in fact it truncates milliseconds up to integer seconds, so it is also not OK

How can we reproduce it (as minimally and precisely as possible)?

Request:

$ bq query --project_id my_project --api http://localhost:9050/ "select current_timestamp(), timestamp_trunc(current_timestamp(), millisecond), timestamp_trunc(current_timestamp(), second),timestamp_trunc(current_timestamp(), minute)"

Anything else we need to know?

$ go version                                     
go version go1.21.5 darwin/amd64

macOS Sonoma 14.4 Apple chip

I am pretty sure this issue is caused by bug in go-zetasqlite

See the issue goccy/go-zetasqlite#218