-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add basic query feature #1
Conversation
It accepts all formats and it integrates with Explorer if the `:explorer` format is used.
This PR also don't tackle the CI workflow. I should create that infra in another PR as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! As I mentioned in the comment in hindsight this is probably not the best design but I think that's ok and we can improve this wholesale in the future (alongside req_athena) while we have bigger fish to fry in the meantime.
@@ -1,12 +1,167 @@ | |||
defmodule ReqCh do | |||
@moduledoc """ | |||
A Req plugin for ClickHouse. | |||
|
|||
By default, `ReqCh` will use TSV as the default output format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I'd would call it ReqCH
, we shorten GitHub to GH so we should shorten ClickHouse to CH.
iex> req = Req.new() |> ReqCh.attach() | ||
iex> Req.post!(req, clickhouse: "SELECT number from system.numbers LIMIT 3").body | ||
"0\\n1\\n2\\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so similar to ReqAthena discussion, this really feels like better achieved with:
iex> ReqCH.query!("SELECT ...")
iex> req = ReqCH.new(hostname: "clickhouse.cloud", retry: :transient)
iex> ReqCH.query!(req, "SELECT ...", retry: false)
Below is intentionally bizarre and unfair to this plugin because it is true for any plugin, but like, isn't it weird we can make this call?
req = Req.new() |> ReqCh.attach()
Req.get!(req, url: "https://httpbin.org", scheme: "http")
Just to be clear, this is totally on me FWIW.
url_parts = [ | ||
get_option(request, :scheme, "http"), | ||
"://", | ||
maybe_credentials(request), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of sending the credentials in the URL (which could show up in logs and stuff) I wonder if we can use the auth: {:basic, "user:pass"}
feature.
Req.Request.halt(request, %{ | ||
response | ||
| body: Explorer.DataFrame.load_parquet!(response.body) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also be:
Req.Request.halt(request, update_in(response.body, &Explorer.DataFrame.load_parquet!/1))
* Apply some suggestions from Wojtek #1 (review) * ReqCh -> ReqCH * Add missing ReqCH.attach/1 * Update lib/req_ch.ex Co-authored-by: Wojtek Mach <[email protected]> --------- Co-authored-by: Wojtek Mach <[email protected]>
This still don't support params - I should tackle that in another PR.