Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Counter column values not returning as integers #61

Closed
jamesbloomer opened this issue Jul 9, 2012 · 5 comments · Fixed by #62
Closed

Counter column values not returning as integers #61

jamesbloomer opened this issue Jul 9, 2012 · 5 comments · Fixed by #62

Comments

@jamesbloomer
Copy link

Created a table and updated the counter column using the following CQL:

CREATE TABLE testcount (key varchar PRIMARY KEY, cnt counter)
UPDATE testcount SET cnt=cnt+1 WHERE key=1

Then reading the value using:

pool.cql('SELECT cnt FROM testcount', [], function(err, results){
console.log(results[0].get('cnt'));
});

..gives the following result:

{ name: 'cnt',
value: '\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004',
timestamp: Fri, 16 Jan 1970 12:43:53 GMT,
ttl: null }

Is this as expected? I would have thought that the counter value would be returned as an integer whereas it looks like some kind of Buffer. Have tried the core buffer methods but they don't return anything sensible. Running the query in CQLSH shows an integer.

@devdazed
Copy link
Contributor

devdazed commented Jul 9, 2012

it looks like the driver didn't know how to decode the response properly, which version of C* are you running? is this using CQL 3 or CQL 2?

@calvinfo
Copy link
Contributor

Whoops, didn't check for CQL support when testing counters.

The problem seems to come from the fact that thrift returns the counter value as a plain long whereas CQL returns it as a buffer which needs deserialization. I'm not sure why this is exactly.

The simplest fix I see is to set the CounterColumn deserializer to be Deserializers.decodeLong (fixes CQL) and then add a special case for counters from Row.fromThrift() to fix the thrift client.

What are your thoughts @devdazed ?

@devdazed
Copy link
Contributor

I think this is the best course of action for now, change the CounterColumn deserializer from IDENTITY to Deserializers.decodeLong and then we can fix the thrift client to check if it is a counter column and ignore deserialization.

@calvinfo
Copy link
Contributor

I made the changes we discussed, should be fixed now. Let me know if there's any tests that I missed.

@jamesbloomer
Copy link
Author

Working great now, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants