You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Paul Teasdale <te...@gmail.com> on 2011/03/14 01:36:24 UTC
Double ColumnType and comparing
I am quite new to Cassandra and am trying to model a simple Column Family
which uses Doubles as column names:
Datalines: { // ColumnFamilly
dataline-1:{ // row key
23.5: 'someValue',
23.6: 'someValue',
...
4334.99: 'someValue'
},
dataline-2:{
10.5: 'someValue',
12.6: 'someValue',
...
23334.99: 'someValue'
},
...
dataline-n:{
10.5: 'someValue',
12.6: 'someValue',
...
23334.99: 'someValue'
}
}
In declaring this column family, I need to specify a 'CompareWith' attribute
for a Double type, but the only available values I found for this attribute
are:
* BytesType
* AsciiType
* UTF8Type
* LongType
* LexicalUUIDType
* TimeUUIDType
Is there any support anywere for double values (there has to be something)?
And if not, does this mean we need to extend
org.apache.cassandra.db.marshal.AbstractType<Double>?
package com.mycom.types;
class DoubleType extends
org.apache.cassandra.db.marshal.AbstractType<Double> {
public int compare(ByteBuffer o1, ByteBuffer o2){
// trivial implementation
Double d1 = o1.getDouble(0);
Double d2 = o2.getDoube(0);
return d1.compareTo(d2);
}
//...
}
And declare the column family:
<ColumnFamily CompareWith="<com.mycom.types.DoubleType>" Name="Datalines"/>
Thanks,
Paul
Re: Double ColumnType and comparing
Posted by Eric Charles <er...@u-mangate.com>.
Or maybe convert double to long, just as hector's DoubleSerializer does
https://github.com/rantav/hector/blob/master/core/src/main/java/me/prettyprint/cassandra/serializers/DoubleSerializer.java
I was happy to use it here.
Tks,
- Eric
On 14/03/2011 02:52, aaron morton wrote:
> There is nothing in the 0.8 trunk to add double support.
>
> Could you shift the decimal point and use ints / longs ? Double is not a precise type, so there is a possibility of the value changing as it's serialised and deserialised around.
>
> You were on the right track with extending abstract type. You would also need to work out a precise binary representation for the numbers.
>
> Hope that helps.
> Aaron
> On 14 Mar 2011, at 13:36, Paul Teasdale wrote:
>
>> I am quite new to Cassandra and am trying to model a simple Column Family which uses Doubles as column names:
>>
>> Datalines: { // ColumnFamilly
>> dataline-1:{ // row key
>> 23.5: 'someValue',
>> 23.6: 'someValue',
>> ...
>> 4334.99: 'someValue'
>> },
>> dataline-2:{
>> 10.5: 'someValue',
>> 12.6: 'someValue',
>> ...
>> 23334.99: 'someValue'
>> },
>> ...
>> dataline-n:{
>> 10.5: 'someValue',
>> 12.6: 'someValue',
>> ...
>> 23334.99: 'someValue'
>> }
>> }
>>
>> In declaring this column family, I need to specify a 'CompareWith' attribute for a Double type, but the only available values I found for this attribute are:
>>
>> * BytesType
>> * AsciiType
>> * UTF8Type
>> * LongType
>> * LexicalUUIDType
>> * TimeUUIDType
>>
>> Is there any support anywere for double values (there has to be something)? And if not, does this mean we need to extend org.apache.cassandra.db.marshal.AbstractType<Double>?
>>
>> package com.mycom.types;
>>
>> class DoubleType extends org.apache.cassandra.db.marshal.AbstractType<Double> {
>> public int compare(ByteBuffer o1, ByteBuffer o2){
>> // trivial implementation
>> Double d1 = o1.getDouble(0);
>> Double d2 = o2.getDoube(0);
>> return d1.compareTo(d2);
>> }
>> //...
>> }
>>
>> And declare the column family:
>>
>> <ColumnFamily CompareWith="<com.mycom.types.DoubleType>" Name="Datalines"/>
>>
>> Thanks,
>> Paul
>>
>>
>>
>>
>>
>>
>>
Re: Double ColumnType and comparing
Posted by aaron morton <aa...@thelastpickle.com>.
There is nothing in the 0.8 trunk to add double support.
Could you shift the decimal point and use ints / longs ? Double is not a precise type, so there is a possibility of the value changing as it's serialised and deserialised around.
You were on the right track with extending abstract type. You would also need to work out a precise binary representation for the numbers.
Hope that helps.
Aaron
On 14 Mar 2011, at 13:36, Paul Teasdale wrote:
> I am quite new to Cassandra and am trying to model a simple Column Family which uses Doubles as column names:
>
> Datalines: { // ColumnFamilly
> dataline-1:{ // row key
> 23.5: 'someValue',
> 23.6: 'someValue',
> ...
> 4334.99: 'someValue'
> },
> dataline-2:{
> 10.5: 'someValue',
> 12.6: 'someValue',
> ...
> 23334.99: 'someValue'
> },
> ...
> dataline-n:{
> 10.5: 'someValue',
> 12.6: 'someValue',
> ...
> 23334.99: 'someValue'
> }
> }
>
> In declaring this column family, I need to specify a 'CompareWith' attribute for a Double type, but the only available values I found for this attribute are:
>
> * BytesType
> * AsciiType
> * UTF8Type
> * LongType
> * LexicalUUIDType
> * TimeUUIDType
>
> Is there any support anywere for double values (there has to be something)? And if not, does this mean we need to extend org.apache.cassandra.db.marshal.AbstractType<Double>?
>
> package com.mycom.types;
>
> class DoubleType extends org.apache.cassandra.db.marshal.AbstractType<Double> {
> public int compare(ByteBuffer o1, ByteBuffer o2){
> // trivial implementation
> Double d1 = o1.getDouble(0);
> Double d2 = o2.getDoube(0);
> return d1.compareTo(d2);
> }
> //...
> }
>
> And declare the column family:
>
> <ColumnFamily CompareWith="<com.mycom.types.DoubleType>" Name="Datalines"/>
>
> Thanks,
> Paul
>
>
>
>
>
>
>
Re: Double ColumnType and comparing
Posted by Norman Maurer <no...@apache.org>.
I will have a look at what it takes to implement it..
Bye,
Norman
2011/3/14 David Boxenhorn <da...@taotown.com>
> I you do it, I'd recommend BigDecimal. It's an exact type, and usually what
> you want.
>
> On Mon, Mar 14, 2011 at 3:40 PM, Jonathan Ellis <jb...@gmail.com> wrote:
>
>> We'd be happy to commit a patch contributing a DoubleType.
>>
>> On Sun, Mar 13, 2011 at 7:36 PM, Paul Teasdale <te...@gmail.com>
>> wrote:
>> > I am quite new to Cassandra and am trying to model a simple Column
>> Family
>> > which uses Doubles as column names:
>> > Datalines: { // ColumnFamilly
>> > dataline-1:{ // row key
>> > 23.5: 'someValue',
>> > 23.6: 'someValue',
>> > ...
>> > 4334.99: 'someValue'
>> > },
>> > dataline-2:{
>> > 10.5: 'someValue',
>> > 12.6: 'someValue',
>> > ...
>> > 23334.99: 'someValue'
>> > },
>> > ...
>> > dataline-n:{
>> > 10.5: 'someValue',
>> > 12.6: 'someValue',
>> > ...
>> > 23334.99: 'someValue'
>> > }
>> > }
>> > In declaring this column family, I need to specify a 'CompareWith'
>> attribute
>> > for a Double type, but the only available values I found for this
>> attribute
>> > are:
>> > * BytesType
>> > * AsciiType
>> > * UTF8Type
>> > * LongType
>> > * LexicalUUIDType
>> > * TimeUUIDType
>> > Is there any support anywere for double values (there has to be
>> something)?
>> > And if not, does this mean we need to extend
>> > org.apache.cassandra.db.marshal.AbstractType<Double>?
>> > package com.mycom.types;
>> > class DoubleType extends
>> > org.apache.cassandra.db.marshal.AbstractType<Double> {
>> > public int compare(ByteBuffer o1, ByteBuffer o2){
>> > // trivial implementation
>> > Double d1 = o1.getDouble(0);
>> > Double d2 = o2.getDoube(0);
>> > return d1.compareTo(d2);
>> > }
>> > //...
>> > }
>> > And declare the column family:
>> > <ColumnFamily CompareWith="<com.mycom.types.DoubleType>"
>> Name="Datalines"/>
>> > Thanks,
>> > Paul
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>>
>>
>> --
>> Jonathan Ellis
>> Project Chair, Apache Cassandra
>> co-founder of DataStax, the source for professional Cassandra support
>> http://www.datastax.com
>>
>
>
Re: Double ColumnType and comparing
Posted by David Boxenhorn <da...@taotown.com>.
I you do it, I'd recommend BigDecimal. It's an exact type, and usually what
you want.
On Mon, Mar 14, 2011 at 3:40 PM, Jonathan Ellis <jb...@gmail.com> wrote:
> We'd be happy to commit a patch contributing a DoubleType.
>
> On Sun, Mar 13, 2011 at 7:36 PM, Paul Teasdale <te...@gmail.com>
> wrote:
> > I am quite new to Cassandra and am trying to model a simple Column Family
> > which uses Doubles as column names:
> > Datalines: { // ColumnFamilly
> > dataline-1:{ // row key
> > 23.5: 'someValue',
> > 23.6: 'someValue',
> > ...
> > 4334.99: 'someValue'
> > },
> > dataline-2:{
> > 10.5: 'someValue',
> > 12.6: 'someValue',
> > ...
> > 23334.99: 'someValue'
> > },
> > ...
> > dataline-n:{
> > 10.5: 'someValue',
> > 12.6: 'someValue',
> > ...
> > 23334.99: 'someValue'
> > }
> > }
> > In declaring this column family, I need to specify a 'CompareWith'
> attribute
> > for a Double type, but the only available values I found for this
> attribute
> > are:
> > * BytesType
> > * AsciiType
> > * UTF8Type
> > * LongType
> > * LexicalUUIDType
> > * TimeUUIDType
> > Is there any support anywere for double values (there has to be
> something)?
> > And if not, does this mean we need to extend
> > org.apache.cassandra.db.marshal.AbstractType<Double>?
> > package com.mycom.types;
> > class DoubleType extends
> > org.apache.cassandra.db.marshal.AbstractType<Double> {
> > public int compare(ByteBuffer o1, ByteBuffer o2){
> > // trivial implementation
> > Double d1 = o1.getDouble(0);
> > Double d2 = o2.getDoube(0);
> > return d1.compareTo(d2);
> > }
> > //...
> > }
> > And declare the column family:
> > <ColumnFamily CompareWith="<com.mycom.types.DoubleType>"
> Name="Datalines"/>
> > Thanks,
> > Paul
> >
> >
> >
> >
> >
> >
> >
>
>
>
> --
> Jonathan Ellis
> Project Chair, Apache Cassandra
> co-founder of DataStax, the source for professional Cassandra support
> http://www.datastax.com
>
Re: Double ColumnType and comparing
Posted by Jonathan Ellis <jb...@gmail.com>.
We'd be happy to commit a patch contributing a DoubleType.
On Sun, Mar 13, 2011 at 7:36 PM, Paul Teasdale <te...@gmail.com> wrote:
> I am quite new to Cassandra and am trying to model a simple Column Family
> which uses Doubles as column names:
> Datalines: { // ColumnFamilly
> dataline-1:{ // row key
> 23.5: 'someValue',
> 23.6: 'someValue',
> ...
> 4334.99: 'someValue'
> },
> dataline-2:{
> 10.5: 'someValue',
> 12.6: 'someValue',
> ...
> 23334.99: 'someValue'
> },
> ...
> dataline-n:{
> 10.5: 'someValue',
> 12.6: 'someValue',
> ...
> 23334.99: 'someValue'
> }
> }
> In declaring this column family, I need to specify a 'CompareWith' attribute
> for a Double type, but the only available values I found for this attribute
> are:
> * BytesType
> * AsciiType
> * UTF8Type
> * LongType
> * LexicalUUIDType
> * TimeUUIDType
> Is there any support anywere for double values (there has to be something)?
> And if not, does this mean we need to extend
> org.apache.cassandra.db.marshal.AbstractType<Double>?
> package com.mycom.types;
> class DoubleType extends
> org.apache.cassandra.db.marshal.AbstractType<Double> {
> public int compare(ByteBuffer o1, ByteBuffer o2){
> // trivial implementation
> Double d1 = o1.getDouble(0);
> Double d2 = o2.getDoube(0);
> return d1.compareTo(d2);
> }
> //...
> }
> And declare the column family:
> <ColumnFamily CompareWith="<com.mycom.types.DoubleType>" Name="Datalines"/>
> Thanks,
> Paul
>
>
>
>
>
>
>
--
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of DataStax, the source for professional Cassandra support
http://www.datastax.com