1

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?

  • You refer to this https://stackoverflow.com/questions/15446187/astyanax-simple-write-throwing-this-exception-not-enough-bytes-to-read-value-o. – tiennv Oct 27 '19 at 14:29

1 Answers1

1

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.

Richard
  • 11,050
  • 2
  • 46
  • 33
  • I am a bit confused here over Composite row keys Vs Composite columns. Can you provide some good link on these? – Gireesh Puthumana Jun 19 '13 at 11:16
  • The main difference is you can do range queries across columns but not rows. So all queries need to know the full row key (whether a composite or not) but don't need to specify exact columns. – Richard Jun 19 '13 at 12:49
  • Thanks Richard, one more question. In my case, I have around 100 keys (or say TYPEs). Under each, there can be tens of thousands of SUB-TYPES. And each sub type will have 5-6 columns against it. How should I model my column family? Thanks in advance.. – Gireesh Puthumana Jun 20 '13 at 04:59