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

Pillar eats up milliseconds #72

Open
zhabinka opened this issue Dec 1, 2023 · 5 comments
Open

Pillar eats up milliseconds #72

zhabinka opened this issue Dec 1, 2023 · 5 comments

Comments

@zhabinka
Copy link

zhabinka commented Dec 1, 2023

Greetings!

We encountered unexpected behavior. The data type DateTime64 allows milliseconds, but Pillar rounds it to seconds.

For example input data:

created_1 = "2023-11-30T13:45:00.500000Z"
created_2 = "2023-11-30T13:45:00.750000Z"
created_3 = "2023-11-30T13:45:00.850000Z"
created_4 = "2023-11-30T13:45:01.200000Z"

In ClickHouse it saved like:

uid created_at
t1 2023-11-30 13:45:00.000
t2 2023-11-30 13:45:00.000
t3 2023-11-30 13:45:00.000
t4 2023-11-30 13:45:01.000

There are may be a reason for this behavior. Can you explain why it works this way?

We have problem to build pagination based on date when we insert more than 1 records per second.

@yzh44yzh
Copy link

yzh44yzh commented Dec 4, 2023

Actually, we know why it happens. It is because of this:
https://github.com/balance-platform/pillar/blob/master/lib/pillar/type_convert/to_clickhouse.ex#L40

And we what to know the reasoning behind this code. It is unclear why you decided to drop milliseconds.

@sofakingworld
Copy link
Member

sofakingworld commented Dec 4, 2023

@yzh44yzh @zhabinka Hello!

The answer is quite simple, the DateTime64 type was added to clickhouse later than the convert function in this library.

https://github.com/balance-platform/pillar/blob/master/lib/pillar/type_convert/to_clickhouse.ex#L40 (March 2020)
ClickHouse/ClickHouse#11512 (June 2020)

What workaround I can suggest:

  1. Pre-convertation of "created_at" into String, Clickhouse should eat it
  2. Upgrage query builder to work with "hints" or special data_structure

For Example:

Pillar.query(conn, 
  "INSERT INTO table (id, created_at) SELECT {id}, {created_at}",
  %{id: 123, created_at: %Pillar.Arg{value: DateTime.utc_now(), target_type: :DateTime64}
)

@yzh44yzh
Copy link

yzh44yzh commented Dec 5, 2023

Ok, thank you. We did number 1 and it works for us.

However, may be it is time to change something in pillar )

@sofakingworld
Copy link
Member

Okay, glad it helped!

We are not actively using clickhouse right now, so the library is not actively developing. In any case, we do not refuse support, if there are people willing to contribute, we will help, merge and publish an updated version on hex)

@yzh44yzh
Copy link

ok, got it

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

No branches or pull requests

3 participants