-
Notifications
You must be signed in to change notification settings - Fork 110
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
How to do partial deserialization #1146
Comments
@wprzytula this sounds like we should add |
Thanks for fast reply! How often do you release? And how long can I expect to see a new version with this feature? |
What I can't understand is that write!(f, "wrong column count: the statement operates on {cql_cols} columns, but the given rust type contains {rust_cols}") Looking at your struct, I'd expect |
It may be a simple error when copying and pasting the error. Is that really relevant to the issue? |
It is, because I don't understand what's the underlying problem. If I understand the case correctly, |
The way I understand it the user want's to dynamically select a subset of columns for select statement. So if the API user sends
then the query will be
and if the API user sends
then the query will be:
Now the problem is how to deserialize it. Creating a separate struct for each subset of column is infeasible. Using something like |
Makes sense. Then, implementing |
Yeah, look like my terminal displays Here is a real struct: #[derive(DeserializeRow, Debug)]
#[scylla(flavor = "enforce_order", skip_name_checks)] // https://docs.rs/scylla/latest/scylla/derive.DeserializeRow.html#struct-attributes
pub struct VideoMetaRow {
pub video_id: Uuid,
#[scylla(skip)]
pub channel_id: Option<String>,
#[scylla(skip)]
pub origin_type: Option<String>,
#[scylla(skip)]
pub created_ts_utc: Option<DateTime<Utc>>,
#[scylla(skip)]
pub tv_id: Option<String>,
#[scylla(skip)]
pub season: Option<i32>,
#[scylla(skip)]
pub episode: Option<i32>,
#[scylla(skip)]
pub category_id: Option<i32>,
#[scylla(skip)]
pub title: Option<String>,
#[scylla(skip)]
pub publication_ts_utc: Option<DateTime<Utc>>,
#[scylla(skip)]
pub is_active: Option<bool>,
#[scylla(skip)]
pub is_adult: Option<bool>,
#[scylla(skip)]
pub duration_sec: Option<i32>,
#[scylla(skip)]
pub has_high_quality: Option<bool>,
#[scylla(skip)]
pub has_preview: Option<bool>,
} Here is a two requests to my API, first is returning correct result and second is not: curl -X 'POST' \
'http://0.0.0.0:8000/feature_set/video_meta' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"features": ["video_id"],
"keys": [["k1"], ["k2"], ["k3"], ["k4"]]
}' curl -X 'POST' \
'http://0.0.0.0:8000/feature_set/video_meta' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"features": ["video_id", "channel_id"],
"keys": [["k1"], ["k2"], ["k3"], ["k4"]]
}' And the SQL statements which is generated for the first and second requests: SELECT video_id FROM video_meta WHERE video_id IN (?); SELECT video_id, channel_id FROM video_meta WHERE video_id IN (?); And my responses from API:
As you can see Also i have to mention that I'm using I tried to:
And nothing helped to me. Also, found no info in docs about macro attributes like My service is a simple Axum application. You can think about it as a layer between ScyllaDB and my other microservices. It maps incoming request into SQL statement and then returns deserialized result in a response as only values, a.k.a records, e.g. Of course my code can be not the best example of Rust programming, but still i think ScyllaDB driver should give an opportunity of partial deserialization, maybe marking fields as Hope now i provided enough context to you. If any other questions, feel free to ask. |
The attributes are described here: https://docs.rs/scylla/latest/scylla/derive.DeserializeValue.html, https://docs.rs/scylla/latest/scylla/derive.DeserializeRow.html |
Yep, thats right, I found them exactly in crate docs, thats not very obvious, because the first link in Google leads to website i mentioned earlier ;). For me thats fine, but for simple users i guess thats not obvious to check macro attributes somewhere in crate docs, it's like finding Rust docstrings in source code at GitHub repo I think, only experienced users do that. But that only my opinion, not the real problem. |
Hmm, that's surprising. For us it's been intuitive that crate docs are a basic source of knowledge about a Rust crate. |
We are currently focusing our efforts on stabilizing the library and releasing 1.0 version. |
I would love to try to contribute in this lib, but I think my skills are not enough for this :) Btw after all known languages I am becoming a fun of Rust lang |
Yeah, it's obvious for me too, but for example I have some colleagues for whom this was not obvious, probably because they are like jun-middle level. So i guess people who are going deep dive into the Rust not gonna realize immediately what he has to look at crate docs instead of official db docs. It's looks like a holywar about where should be the source of truth for libs and services, in some Confluence, some local wiki or something like that or in the code and docstrings itself. Personally i prefer it in both places, but with links to source code docs in Confluence for example. |
Overall if I will have some time in non-working hours, maybe I will try to contribute, but I am not 100% sure about it |
Hey, I'm struggling with deserialization.
I'm making a API with Axum that, upon request, can return records from a ScyllaDB based on some criteria and with certain fields. for example I can request records with specific IDs and fields, let's say request to my API would look like
And my rust struct look like
So my select query would be like
And i will get an error, something like
I understand error, which says that columns I selected doesn't match with struct, and something like following not working too.
#[scylla(flavor = "enforce_order", skip_name_checks)]
Making struct fields optional doesn't working, also as
#[scylla(skip)]
So how do i properly handle partial deserialization?
The text was updated successfully, but these errors were encountered: