Netflix / astyanax

Cassandra Java Client
Apache License 2.0
1.04k stars 355 forks source link

astyanax-cql support for collections set, list and map #592

Open kontact-chan opened 8 years ago

kontact-chan commented 8 years ago

Dear Engineers,

We are trying to read the SET using cql java driver. We are getting this exception: datastax.driver.core.exceptions.InvalidTypeException: Value paths is of type set

Code here:

Column<String> column = columns.getColumnByName(LabelVerticesFieldEnum.PATHS.getFieldStr());
SetSerializer<String> serializer = new SetSerializer<>(UTF8Type.instance);
if (!CommonUtils.isNullOrBlank(column.getValue(serializer))) {
    labelVertices.setPaths(column.getValue(serializer));
}

The datastax row has a method to access the SET values, but there is no way from the CqlColumnImpl i could access it.

Here is the datastax row method:

public class Row { 
    public <T> Set<T> getSet(int i, Class<T> elementsClass) 
}

Instead the column.getValue(serializer) hits this method in the datastax driver:

 public ByteBuffer getBytes(int i) {
        metadata.checkType(i, DataType.Name.BLOB);
        return getBytesUnsafe(i);
    }

that throws this exception - datastax.driver.core.exceptions.InvalidTypeException: Value paths is of type set

Any idea when this would be supported?

Is there anything we are doing wrong? Please let me know.

We wanted to move away from ThriftFamilyFactory and use the CqlFamilyFactory.

Thanks, Chandran.

kontact-chan commented 8 years ago

I added a quick fix for astyanax-cql to work for collection set:

https://gist.github.com/7032ced375bedb9b81b3

If you like this, i would like to submit a patch for all the collections - set, list and map.

Please let me know.