Skip to content
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

Serialization error when incrementing a counter #1099

Closed
prk3 opened this issue Oct 21, 2024 · 6 comments · Fixed by #1100
Closed

Serialization error when incrementing a counter #1099

prk3 opened this issue Oct 21, 2024 · 6 comments · Fixed by #1100
Assignees

Comments

@prk3
Copy link

prk3 commented Oct 21, 2024

I'm trying to increment a counter column with a query like this:

UPDATE monthly_counters SET action_counter = action_counter + ? WHERE ...;

My code is proving a value of type i64:

session.execute_unpaged(&increment_by_statement, (100i64,)).await?;

Execution fails at serialization of parameters:

Serializing values failed: SerializationError: Failed to serialize query arguments (i64,): failed to serialize column sent_activations: SerializationError: Failed to type check Rust type i64 against CQL type Counter: expected one of the CQL types: [BigInt]

It seems that i64 can't be used to increment a counter. I tried providing CqlValue::BigInt(100) and num_bingint::BigInt, none of those worked. How would I provide a value to that query?

@Lorak-mmk
Copy link
Collaborator

Lorak-mmk commented Oct 21, 2024

We have a section of documentation about Counter type: https://rust-driver.docs.scylladb.com/stable/data-types/counter.html

It sadly doesn't have an update example, but it does show what type to use: use scylla::frame::value::Counter;

So you example would be:

use scylla::frame::value::Counter;
session.execute_unpaged(&increment_by_statement, (Counter(100i64),)).await?;

@Lorak-mmk
Copy link
Collaborator

@wprzytula possible minor issue: I see there is i64 deserialization for Counter: impl_fixed_numeric_type!(i64, [BigInt | Counter]);. For the sake of type safety and consistency with serialization shouldn't only the Counter type be able to deserialize Counter column?

@prk3
Copy link
Author

prk3 commented Oct 21, 2024

We have a section of documentation about Counter type: https://rust-driver.docs.scylladb.com/stable/data-types/counter.html

It sadly doesn't have an update example, but it does show what type to use: use scylla::frame::value::Counter;

So you example would be:

use scylla::frame::value::Counter;
session.execute_unpaged(&increment_by_statement, (Counter(100i64),)).await?;

I missed that doc. Your solution works like a charm. Thank you! Fell free to close this issue one you figure out what to do with serialization vs deserialization type discrepancy.

@Lorak-mmk Lorak-mmk self-assigned this Oct 21, 2024
@Lorak-mmk
Copy link
Collaborator

For completeness, I opened a PR that adds an example snippet that updates the counter value: #1100

@wprzytula
Copy link
Collaborator

@wprzytula possible minor issue: I see there is i64 deserialization for Counter: impl_fixed_numeric_type!(i64, [BigInt | Counter]);. For the sake of type safety and consistency with serialization shouldn't only the Counter type be able to deserialize Counter column?

Agreed. I encourage you to fix that.

@Lorak-mmk
Copy link
Collaborator

@wprzytula possible minor issue: I see there is i64 deserialization for Counter: impl_fixed_numeric_type!(i64, [BigInt | Counter]);. For the sake of type safety and consistency with serialization shouldn't only the Counter type be able to deserialize Counter column?

Agreed. I encourage you to fix that.

#1106

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 a pull request may close this issue.

3 participants