使用Asytanax对复合列执行查询时出现InvalidRequestException(原因:比较器的字节太多)

时间:2012-09-10 22:00:48

标签: cassandra astyanax

我正在尝试使用Astyanax 1.0.9从复合列中取出并获得“InvalidRequestException(原因:比较器的字节太多)”

这是我的CF:

CREATE TABLE user_attributes (
user_id bigint,
attr_name ascii,
attr_value text,
last_sync_timestamp bigint,
last_sync_digest text,
PRIMARY KEY (user_id, attr_name)
);

我可以用CQL读取数据:

select * from user_attributes where user_id = 1 and attr_name = 'mock';

这是我的复合柱POJO:

public static class UserAttributeCassandraTuple implements Comparable {
    public @Component(ordinal = 0) String attrName;
    public @Component(ordinal = 1) String attrValue;
    public @Component(ordinal = 2) long lastSyncTimeStamp;
    public @Component(ordinal = 3) String lastSyncDigest;

    public int compareTo(Object o) { /* impl omitted here */ }
    public int hashCode() { /* impl omitted here */ }
    public boolean equals(Object o) { /* impl omitted here */ }
}

这是我的测试驱动程序:(键空间在junit @before中设置,适用于非复合列)

@Test
public void test_user_attributes() throws Exception {

    ColumnFamily<BigInteger, UserAttributeCassandraTuple> CF_USER_ATTR = new ColumnFamily<BigInteger, UserAttributeCassandraTuple>(
        "user_attributes", // Column Family Name
        BigIntegerSerializer.get(), // Key Serializer
        userAttributeSerializer); // Column Serializer

    // proto column for "mock"
    UserAttributeCassandraTuple mockColumn = new UserAttributeCassandraTuple();
    mockColumn.attrName = "mock";

    OperationResult<ColumnList<UserAttributeCassandraTuple>> result = keyspace.prepareQuery(CF_USER_ATTR)
    .getKey(BigInteger.valueOf(1))
    .withColumnSlice(mockColumn, mockColumn)
    .execute();
    ColumnList<UserAttributeCassandraTuple> columns = result.getResult();

    for (Column<UserAttributeCassandraTuple> c : columns) {
        System.out.println(c.getName() + "=" + c.getStringValue());
    }
}

它编译得很好,但在execute()期间失败了:

com.netflix.astyanax.connectionpool.exceptions.BadRequestException: BadRequestException: [host=127.0.0.1(127.0.0.1):9160, latency=22(44), attempts=1] InvalidRequestException(why:Too many bytes for comparator)
at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:159)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:60)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:196)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.execute(ThriftColumnFamilyQueryImpl.java:188)
at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$1.execute(ThriftSyncConnectionFactoryImpl.java:132)
at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:52)
at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:229)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1.execute(ThriftColumnFamilyQueryImpl.java:186)
at com.ebay.raptor.search.test.srp.domain.cassandra.CassandraTest.test_user_attributes(CassandraTest.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: InvalidRequestException(why:Too many bytes for comparator)
at org.apache.cassandra.thrift.Cassandra$get_slice_result.read(Cassandra.java:7196)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_get_slice(Cassandra.java:543)
at org.apache.cassandra.thrift.Cassandra$Client.get_slice(Cassandra.java:527)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.internalExecute(ThriftColumnFamilyQueryImpl.java:201)
at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1$2.internalExecute(ThriftColumnFamilyQueryImpl.java:188)
at com.netflix.astyanax.thrift.AbstractOperationImpl.execute(AbstractOperationImpl.java:55)
... 30 more

我尝试用Long替换BigInteger,但得到了同样的错误。

有什么建议我做错了吗?

感谢 卡盘

1 个答案:

答案 0 :(得分:1)

Astyanax是一个基于Thrift的客户端,所以这不会起作用:(服务器端)Thrift验证路径不支持CQL。

我们在1.2.0中为addressing this以获得更顺畅的升级路径;否则,您需要使用CQL客户端访问CQL表,或者使用CLI为基于Thrift的客户端定义架构。