Reputation: 11
I face a problem inserting some number values into column family with composite column (Cassandra 1.1.6 using Astyanax 1.0.6 client).
AnnotatedCompositeSerializer<DailyPersonal> dailyPersonalSerializer
= new AnnotatedCompositeSerializer<DailyPersonal>(DailyPersonal.class);
ColumnFamily<Long, DailyPersonal> CF_DAILY_PERSONAL
= new ColumnFamily<Long, DailyPersonal>("daily_personal",
LongSerializer.get(), dailyPersonalSerializer);
DailyPersonal dailyPersonalSteps = new DailyPersonal(new LocalDate(2012, 1, 1).toDate(), 12348L, "steps");
DailyPersonal dailyPersonalDistance = new DailyPersonal(new LocalDate(2012, 1, 1).toDate(), 12348L, "distance");
MutationBatch m = keyspace.prepareMutationBatch();
m.withRow(CF_DAILY_PERSONAL, 1L)
.putColumn(dailyPersonalSteps, 333, null)
;
m.withRow(CF_DAILY_PERSONAL, 1L)
.putColumn(dailyPersonalDistance, 444, null)
;
DailyPersonal is defined as:
public class DailyPersonal {
@Component(ordinal = 0)
private Date logDate;
@Component(ordinal = 1)
private Long userId;
@Component(ordinal = 2)
private String field;
...
}
Column family definition:
CREATE TABLE daily_personal (
program_id bigint,
log_date timestamp,
user_id bigint,
distance int,
steps int,
PRIMARY KEY (program_id, log_date, user_id)
);
The problem arises during inserting some values: i.e. 444 fails, while 333 works fine. I can't figure the dependency, but looks like it fails for a lot of values [0; 1500]. Error message looks like:
com.netflix.astyanax.connectionpool.exceptions.BadRequestException: BadRequestException: [host=127.0.0.1(127.0.0.1):9160, latency=19(40), attempts=1] InvalidRequestException(why:(String didn't validate.) [demodb][daily_personal][2012-01-01 00:00:00+0300:12348:distance] failed validation)
I do not see any obvious reasons why it fails. Could someone tell if my code is correct or there any environment/libraries issue?
Upvotes: 1
Views: 1227
Reputation: 11
I've just run into the same problem. WIth a dynamic column that is NOT a composite column, if you use the correct MutationBatch putColumn method for your data the correct validator will be used. However, with composite columns regardless of the MutationBatch putColumn method you choose, the column family's default validation class will be used.
To my mind, this is not consistent. However, there are two workarounds. The first is to simply set the default validation class in your column family to the data type that will be stored in your composite columns. Based on the output that you posted I would assume that it is currently UTF8Type and you are attempting to store integers.
The second workaround is the set the default validation class to BytesType. This will allow any data type to be stored and is my preferred solution. This solution also enables you to have multiple composite columns in the same row storing different value types.
Upvotes: 1
Reputation: 26
Please take a look at the following wiki page on github for an example on how to use CQL3 with astyanax. https://github.com/Netflix/astyanax/wiki/Cql-and-cql3.
Upvotes: 0