-
Notifications
You must be signed in to change notification settings - Fork 98
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
Fetch rows in JSON format #152
base: main
Are you sure you want to change the base?
Conversation
Could it be a more flexible approach to provide a "raw" method such as pub fn query_raw(format: DataFormat) -> Result<RawCursor> So that then it is possible to extract either raw bytes or a JSON repr from that RawCursor? This way, it will be possible to support all JSON types and streaming into files with CSV/TSV/Parquet, etc. WDYT? |
Let's extract Debug impl for Query as a separate PR as it addresses #146 (thank you!), so that it can be merged quickly, while we are discussing the rest. |
+1 on naming json fetch_json etc |
7ff222b
to
684c2ce
Compare
First of all, the only reason why this crate already contains (conditionally!) serde-json is only WA for Secondly, the initial problem is the absence of dynamic schemas, not the "I want exactly JSON" problem. Thus, we should avoid any additional formats that should be covered by basic cursor-like API (Apache Arrow can have another column-based API, for instance). I want to remember that the semantics of the current By providing such specific interfaces, we're opening a black hole: the next request will be "I want CSV format", "I want Vertical (lol) format", and so on. All these formats will be difficult to support later, because @slvrtrn's suggestion about |
Correct. I stated the original problem: it's impossible right now to get the result of Of course, If only we had a working PostgreSQL interface, we'd stick with |
Actually, I think we can implement
I totally understand your displeasure. There are several points why it wasn't resolved in time:
Although, we can use I hope both reasons become irrelevant now that ClickHouse's team members have begun working on this crate.
Maybe yes, maybe not. It's not a simple statement. I liked the SQLx-like approach much more until we (I mean, in my team) started actively using it (for PostgreSQL), and.. ok, let's say that it's full of pain for multiple nontrivial tasks. But I don't want to delve into this topic here, it's worth considering after the sqlx support by detailed comparison and benchmarking. I'll be totally fine if CH env team decides to focus on sqlx instead as the official approach. So, |
@loyd All right. Thanks for the very detailed explanation about the background of this! |
476fd1a
to
55da617
Compare
Print the source JSON string in the error message.
Allows row deserialization into a `T: Deserialize`, which eliminates the limitations of `Query::fetch`: * when the table schema is not known: `SELECT * from ?` * when the table schema is not specified: `DESCRIBE TABLE ?` * when we read less columns than we select
55da617
to
d41ac2b
Compare
Summary
This is a draft PR which adds the support for fetching rows in JSON format.
The current
Query::fetch
fetches the results usingFORMAT RowBinary
only which requires a strict 1:1 mapping between the query schema and the deserialized type.And that has a lot of limitations:
RowBinaryWithNamesAndTypes
#10This PR allows the row deserialization into a
T: Deserialize
which eliminates the limitations ofQuery::fetch
:SELECT * from ?
DESCRIBE TABLE ?
Unresolved questions
RowBinaryWithNamesAndTypes
#10 will eventually be supportedQuery::json
,Query::json_one
,Query::json_all
is very unfortunateQuery::fetch_json
,Query::fetch_json_one
would be better albeit verboseQuery::json
requires thewatch
feature which is a bit misleading - we can improve thisChecklist
Delete items not relevant to your PR: