Вопрос

Facing an issue while reading from composite columns using hector api.

My column family:

create column family step_wise_stats_cc with key_validation_class = 'CompositeType(UTF8Type, UTF8Type)' and comparator = UTF8Type and default_validation_class = UTF8Type;

Data: Row Key:{TYPE-1,SUB-TYPE-1}
Columns:Name1:Value1

I am querying it like this:

Cluster cluster = HFactory.getOrCreateCluster("cls1", "localhost:9160");;
Keyspace keyspace = HFactory.createKeyspace("ks1",cluster);;
Serializer se = StringSerializer.get();

Composite start = new Composite();
start.addComponent(0, "TYPE-1", ComponentEquality.EQUAL);
start.addComponent(1, "SUB-TYPE-1", ComponentEquality.EQUAL);
Composite end = new Composite();
end.addComponent(0, "TYPE-1", ComponentEquality.GREATER_THAN_EQUAL);
start.addComponent(1, "SUB-TYPE-1", ComponentEquality.GREATER_THAN_EQUAL);

SliceQuery<String, Composite, String> sliceQuery = HFactory.createSliceQuery(keyspace, se, CompositeSerializer.get(), se);;
sliceQuery.setColumnFamily("cf1");
sliceQuery.setKey("TYPE-1");
sliceQuery.setRange(start, start, false, 999);

QueryResult<ColumnSlice<Composite, String>> qr = sliceQuery.execute();

But getting below exception: me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestExc eption(why:Not enough bytes to read value of component 0)

Any help?

Это было полезно?

Решение

Your row key is CompositeType, but you are setting the row key to "TYPE-1". This is why Cassandra is giving you an error.

A slice query returns a range of columns for a given row. You either need to specify a composite for your row key or change your data model by moving subtype to the column and make the column a composite.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top