Giter VIP home page Giter VIP logo

Comments (10)

calvinfo avatar calvinfo commented on May 28, 2024

I'd also like to see this.

Currently most of the driver seems to work fine but I'm having a problem when loading a composite column name with Integer and Long components. The Integer and Long Serializers have problems now that the byte buffer returned is a variable number of bytes, I think due to a change in libthrift.

from astyanax.

ivolo avatar ivolo commented on May 28, 2024

+1

from astyanax.

ivolo avatar ivolo commented on May 28, 2024

any update on this?

from astyanax.

elandau avatar elandau commented on May 28, 2024

I will look into this later this week.

from astyanax.

elandau avatar elandau commented on May 28, 2024

calvinfo, can you provide more details about the problems you are seeing and perhaps some code to replicate the problem. So far I have not seeing any issues upgrading to libthrift 0.7

from astyanax.

calvinfo avatar calvinfo commented on May 28, 2024

My mistake, my problem is happening in Cassandra 1.0 as well, so probably unrelated! There seems to be a bug with how the buffers on composites are returned versus how the serializers expect the data to come back.

My column family is set up in the following way:

ColumnFamily: Test
   Key Validation Class: org.apache.cassandra.db.marshal.IntegerType
   Default column value validator: org.apache.cassandra.db.marshal.BytesType
   Columns sorted by: org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.LongType,org.apache.cassandra.db.marshal.IntegerType)

And here's some code to demonstrate the problem, when inserted to a new row.

Keyspace keyspace = connection.get();

ColumnFamily<Integer, Composite> cf = 
    new ColumnFamily<>("Test", IntegerSerializer.get(), CompositeSerializer.get());

try {

    int key = 1;

    keyspace.prepareColumnMutation(cf, key, new Composite(2012L, 2012))
            .putValue("test", null)
            .execute();

    OperationResult<ColumnList<Composite>> result = keyspace.prepareQuery(cf)
                                                            .getKey(key)
                                                            .execute();

    ColumnList<Composite> columns = result.getResult();
    Column<Composite> col = columns.getColumnByIndex(0);

    Composite name = col.getName();
    Long prefix = (Long) name.getComponent(0)
                             .getValue(LongSerializer.get()); // 2012L

    Integer suffix = (Integer) name.getComponent(1)
                                   .getValue(IntegerSerializer.get()); // null
}

The values seem to write properly to cassandra, as seen from the CLI. The problem seems to be happening at com.netflix.astyanax.serializers.IntegerSerializer.fromByteBuffer.

Depending upon the numeric size of the integer, a variable number of bytes seems to be returned. For example, any number less than 256 needs only one byte. This causes the check for 4 bytes remaining to fail unless the returned int actually uses all 4 bytes in its full representation.

from astyanax.

andlaz avatar andlaz commented on May 28, 2024

seeing the same problem as @calvinfo

from astyanax.

elandau avatar elandau commented on May 28, 2024

The problem here is that the IntegerType in cassandra is NOT a 4 byte integer. It is a variable length BigInteger. This has always been a source of confusion with cassandra. Interestingly the Composite class actually does serialize ints as BigInteger so you should be fine here.

My recommendation would first be to fix the column family definition to be,

ColumnFamily: Test
   Key Validation Class: org.apache.cassandra.db.marshal.Int32Type
   Default column value validator: org.apache.cassandra.db.marshal.BytesType
   Columns sorted by: org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.LongType,org.apache.cassandra.db.marshal.IntegerType)

The only change here is to change the key validation class to Int32Type since the ints you are serializing for the key are actually 32 bit ints.

For reading the data all you need to do is change the code for reading the suffix to read a big integer.

    BigInteger suffix = (BigInteger) name.getComponent(1)
                                   .getValue(BigIntegerSerializer.get()); // 2012

You could also use the AnnotatedCompositeSerializer but make sure the suffix part is a BigInteger.

from astyanax.

calvinfo avatar calvinfo commented on May 28, 2024

Great, thanks for the help! I hadn't realized composites serialize as BigInteger rather than Integer.

from astyanax.

elandau avatar elandau commented on May 28, 2024

Version 1.0.4 now uses cassandra 1.1.0

from astyanax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.