Skip to content

Experiment to simplify the API#140

Closed
ruslandoga wants to merge 2 commits intomasterfrom
new-api
Closed

Experiment to simplify the API#140
ruslandoga wants to merge 2 commits intomasterfrom
new-api

Conversation

@ruslandoga
Copy link
Copy Markdown
Collaborator

@ruslandoga ruslandoga commented Dec 16, 2023

Changes:

  • improve timezone / datetime support

For RowBinary:

clickhouse tz app tz value result
any any %DateTime{time_zone: "Etc/UTC"} dump to unix timestamp
any any %DateTime{time_zone: "Asia/Taipei"} conversion into unix timestamp (this is slow)
UTC UTC %NaiveDateTime{} dump to seconds = unix timestamp (correct)
Europe/Berlin UTC %NaiveDateTime{} dump to seconds = unix timestamp (still correct)
Europe/Berlin Asia/Taipei %NaiveDateTime{} dump to seconds != unix timestamp (incorrect, should raise?)

For queries:

clickhouse tz app tz datetime
  • automatically decode streams
# decode by default (format=RowBinaryWithNamesAndTypes)
DBConnection.run(conn, fn conn ->
  Ch.stream(conn, "select * from numbers limit {limit:UInt64}", %{"limit" => 1_000_000})
  |> Stream.each(&IO.inspect/1)
  |> Stream.run()
end)
# %Ch.Result{rows: [[]], data: <<>>}
# %Ch.Result{rows: [[]], data: <<>>}
# %Ch.Result{rows: [[]], data: <<>>}

# don't decode unknown format
DBConnection.run(conn, fn conn ->
  Ch.stream(conn, "select * from numbers limit {limit:UInt64} format CSV", %{"limit" => 1_000_000})
  |> Stream.each(&IO.inspect/1)
  |> Stream.run()
end)
# %Ch.Result{rows: nil, data: ''}

# don't decode if `decode: false`
DBConnection.run(conn, fn conn ->
  Ch.stream(conn, "select * from numbers limit {limit:UInt64}", %{"limit" => 1_000_000}, decode: false)
  |> Stream.each(&IO.inspect/1)
  |> Stream.run()
end)
# %Ch.Result{rows: nil, data: <<>>}

@ruslandoga ruslandoga changed the title Experiment to simplify the API. Experiment to simplify the API Dec 16, 2023
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.

1 participant