-
Notifications
You must be signed in to change notification settings - Fork 111
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 support for Duration type #363
Add support for Duration type #363
Conversation
e85dcdc
to
a08989a
Compare
@Ponewor I have no idea why Cassandra decided to encode duration as a custom type instead of a native type, but it is legal in CQL v4. Here's an excerpt from https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v4.spec:
So this is actually a mild compatibility bug - not a serious one, because our driver should be free to not recognize specific custom types, but perhaps we should have a map of handlers for a few known ones - e.g. I created #364 to track the problem. For now, either make the test optional or add a Cassandra-specific bypass - namely, let the test pass either when it returns a correct duration, or when it fails because it received a custom type. If you decide to go with the latter, please also add a comment about it in the test case. |
@Ponewor The Duration type was introduced in v5 of the CQL protocol. There was a need for this type to be supported in Scylla - however, Scylla only supports v4 so the support for it was backported to the older version of the protocol. If you look at the protocol specifications as defined in the Cassandra repository, you can see that in v4 there is no concept of Duration (see here), it is only introduced in v5 (here). In order to be compatible with the protocol v4, I guess that Cassandra decides to encode Durations as a "Custom" type. I'm not aware of how the encoding looks, though. I agree with @psarna on how to handle this for Cassandra. |
scylla/src/frame/value.rs
Outdated
|
||
fn vint_encode(v: i64, buf: &mut Vec<u8>) { | ||
let mut v = zig_zag_encode(v); | ||
let number_of_bytes = 8 - v.leading_zeros() / 8; |
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.
The other drivers (Gocql and the Datastax Java Driver) seem to calculate this in a clever, branchless way - look here.
scylla/src/frame/response/result.rs
Outdated
months: months as i32, | ||
days: days as i32, |
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.
It would be good to check that the decoded i64
's do not overflow.
Ah, makes sense. Btw, we could consider allowing the user to declare the version explicitly to allow "version spoofing". That would allow users to set v5 here, e.g. if they know that they'll only use the subset of v5 that's actually implemented. It would act as a trivial workaround for issues like this.
|
CQL protocol allows sending custom types identified by their string representation. One of the cases in which the trick is used is when Cassandra returns duration columns to a CQLv4 client, which is not supposed to know this type. WIP: the actual implementation will be done once #363 is merged. Refs #364
any updates on this one? |
CQL protocol allows sending custom types identified by their string representation. One of the cases in which the trick is used is when Cassandra returns duration columns to a CQLv4 client, which is not supposed to know this type. WIP: the actual implementation will be done once #363 is merged. Refs #364
185d862
to
ac262e9
Compare
ac262e9
to
7df1daf
Compare
Fixes: #320
This works great with Scylla but for some reason it fails with Cassandra (at least with 4.0.1). The column type code that Cassandra is sending for Duration is 0 instead of 0x15 and it is followed with type's name: "org.apache.cassandra.db.marshal.DurationType". How should we deal with it?
Apart from that (and a few missing tests or docstrings), is there anything serious missing here?
Pre-review checklist
Fixes:
annotations to PR description.