Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

composite columns with getColumnByName not working? #25

tbee opened this Issue Mar 16, 2012 · 7 comments


None yet
3 participants

tbee commented Mar 16, 2012

I have a simple two string composite column:

static public class LicenseXPathCompositeColumn
    @Component(ordinal=0) String hash;
    @Component(ordinal=1) String id;

(I've hidden two constructors and a toString for simplicity)
The code below correctly compiles and runs:

        // get the colums 
        LicenseXPathCompositeColumn lXPathColumn = new LicenseXPathCompositeColumn(lHashcode, "xpath");
        LicenseXPathCompositeColumn lResultColumn = new LicenseXPathCompositeColumn(lHashcode, "result");
        OperationResult<ColumnList<LicenseXPathCompositeColumn>> result = keyspace.prepareQuery(cLicenseXPathColumnFamily)
            .withColumnSlice(lXPathColumn, lResultColumn)
        ColumnList<LicenseXPathCompositeColumn> lColumns = result.getResult();

        // process the columns
        for (com.netflix.astyanax.model.Column<LicenseXPathCompositeColumn> c : lColumns) { System.out.println(c.getName() + "=" + c.getStringValue()); }

Two columns are found and this is the output of the printlns:
89eb5af1fbecabc7874de697d815d4d5:xpath=count(/license/configuration/services/notification) > 0

What confuses me is that according to the API I have to provide the composite columns as the parameter to the getColumnByName, but it does not find the column.


elandau commented Mar 21, 2012

Your pojo will need to implement the Comprable interface. Columns are stored internally in maps.

tbee commented Mar 21, 2012

It seems to me that from an API perspective the comparable logic beste be done in the getColumnByName using reflection, otherwise every one using the API needs to implement a comparable.


elandau commented Mar 21, 2012

More specifically you'll need to implement hashCode, compareTo and equals. I'll modify the docs to reflect this requirement.

tbee commented Mar 21, 2012

I really think it is a better idea to try and not have the user have to do this. It will make the implementation much uglier. Can't we use the utility methods provided by Apache commons to add these methods via reflection? The Pojo would then need to extend something, but adding three methods to create a two column composite is not nice.


elandau commented Mar 21, 2012

Point taken. I'll take a look.


ash2k commented May 2, 2012

You may want to add a generic bound to enforce Comparable implementation check at compile time (with or without reflection impl. this will add safety). Also to check if hashCode() and equals() are implemented by T AnnotatedCompositeSerializer may create two instances of T in it's constructor and compare them and their hashcodes. If they are equal - methods are implemented.

public class AnnotatedCompositeSerializer<T extends Comparable<? super T>> extends AbstractSerializer<T> {

ash2k commented May 2, 2012

Also in documentation for that serializer you may add a link to Guava's wiki page with examples of how to simply implement compareTo/hashCode/equals methods.

@elandau elandau closed this Dec 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment