1

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?

4

2 回答 2

1

我刚刚遇到了同样的问题。对于不是复合列的动态列,如果您对数据使用正确的 MutationBatch putColumn 方法,则将使用正确的验证器。但是,对于复合列,无论您选择哪种 MutationBatch putColumn 方法,都将使用列族的默认验证类。

在我看来,这并不一致。但是,有两种解决方法。第一种是简单地将列族中的默认验证类设置为将存储在复合列中的数据类型。根据您发布的输出,我假设它当前是 UTF8Type 并且您正在尝试存储整数。

第二种解决方法是将默认验证类设置为 BytesType。这将允许存储任何数据类型,并且是我的首选解决方案。此解决方案还使您能够在同一行中拥有多个复合列,以存储不同的值类型。

于 2012-12-20T20:28:53.900 回答
0

请查看 github 上的以下 wiki 页面,以获取有关如何将 CQL3 与 astyanax 一起使用的示例。 https://github.com/Netflix/astyanax/wiki/Cql-and-cql3

于 2012-12-04T09:57:11.807 回答