Hector inserting only part of the primary key

32 Views Asked by At

I have a query in some legacy code that I want to understand. The Cassandra table is this:

 cqlsh:mykeyspace> desc table "logTable"

CREATE TABLE mykeyspace."logTable" (
    key text,
    key2 text,
    column1 text,
    column2 text,
    column3 text,
    column4 text,
    value blob,
    PRIMARY KEY ((key, key2), column1, column2, column3, column4)
)

I'm not kidding, the columns really are named like that, so that each column can be used in any way. This makes the code very difficult to read. Now, there's some code in Java I don't understand:

private static final StringSerializer ss = StringSerializer.get();

public void logProgressMetadata(String affiliationId, String datasetId, String jobId, ProgressMetadata metadata) {
        Composite rowKey = new Composite();
        rowKey.addComponent("JOB_PROGRESS", ss);

        Composite column = new Composite();
        column.addComponent(affiliationId, ss);
        column.addComponent(datasetId, ss);
        column.addComponent(jobId, ss);

        Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
        mutator.addInsertion(rowKey, LOG_CF, HFactory.createColumn(column, metadata.toJson(), CompositeSerializer.get(), ss));

        mutator.execute();
    }

My question about this code is regarding rowKey: what is placed in "key" and "key2"? If I try to make a Query in CQL specifying just key and not key2, then I get an error. If I query without any restrictions (select * from "logTable"), then I cannot find any column containing "JOB_PROGRESS" as an example, so I have to figure this out only from code.

Thanks, Serban

0

There are 0 best solutions below