-
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
Allow serialization of "columns" that are not valid rust identifiers #1137
Conversation
|
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.
@piodul I don't see anything wrong with this change, but you wrote those macros so it would be good if you took a look - maybe I missed something.
@wprzytula Do we need the same change for deserialization?
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, but I believe we have exactly the same issue in SerializeValue as well. @nrxus could you fix it in this PR, too? The fix should be very similar to what you did in the first commit.
Is it possible to have UDT field names that are not correct Rust identifiers? |
Apparently, yes:
|
fixes cases where the "column name" is not a valid rust identifier; such as trying to pass in a dynamic TTL
this adds support for UDTs that have fields that are not valid rust idents but are valid scylla field names
97cfd99
to
8b579e6
Compare
This is how fn visited_flag_variable(field: &Field) -> syn::Ident {
quote::format_ident!("visited_{}", field.ident.as_ref().unwrap().unraw())
} So it should be free of the mentioned limitation. |
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.
💯 Thank you for this contribution, @nrxus!
Thanks for the contribution! We plan to release 0.15.1 this or next week, it will contain your patch. |
Allow serialization of "columns" that are not valid rust identifiers (cherry picked from commit 4b6ad84)
Fixes
When trying to serialize a row that isn't a valid rust identifier, the macro fails to expand due to the invalid rust identifier being used when creating variables for the derived implementation. This PR fixes that such that those variables are driven by the field identifier rather than the column name.
In particular, this occurs when trying to serialize a dynamic TTL that would be using in a query such as:
The struct desired for serialization is:
However, in the current version of the driver this fails because it tries to create a variable called
visited_flag_[ttl]
which is not a valid rust identifier. As far as I could tell there is no reason for this variable to be based on the column name rather than the field name so I switched it to be based off the field name since that already has to be a valid identifier.I added a test to verify that the serialization works but I didn't add any integration tests to make sure that the TTL insert actually works. I have tested it locally however.
For context: I am using this dynamic TTL to allow moving of rows to different "buckets" (which drive partitions in my schema). I want the re-bucketing to not affect the existing TTL so I am reading the existing TTL in one query and then applying it to the new row in the new bucket in an insert.
I also fixed a doc typo that was missing an ending square bracket.
Pre-review checklist
./docs/source/
.Fixes:
annotations to PR description.