【问题标题】:InvalidRequestException(why:Too many bytes for comparator) on execute query to composite columns using Asytanax使用 Asytanax 对复合列执行查询时出现 InvalidRequestException(为什么:比较器的字节数过多)
【发布时间】:2012-09-11 10:40:04
【问题描述】:

我正在尝试使用 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());
    }
}

编译正常,但在执行()期间失败:

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,但得到了同样的错误。

任何建议我做错了什么?

谢谢 查克

【问题讨论】:

    标签: cassandra astyanax


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢乔纳森。我正在使用 Maven 来构建我的春季项目,而且我是 cassandra 的新手。你能告诉我哪个 java CQL 客户端最好吗?我用谷歌搜索了一下,看到 cassandra-jdbc:code.google.com/a/apache-extras.org/p/cassandra-jdbc 和 Hector 的 CQL:hector-client.github.com/hector/build/html/content/…。但不确定它们是否可以通过 maven 存储库获得。
    • 刚试过cassandra-jdbc,好像不喜欢复合键,只返回行键列。这段代码出错了:` ... String attrName = rs.getString(2); ...` java.sql.SQLSyntaxErrorException: index must be a positive number less or equal to the count of returned columns: 2 1 at org.apache.cassandra.cql.jdbc.CassandraResultSet.checkIndex(CassandraResultSet.java:182) at org .apache.cassandra.cql.jdbc.CassandraResultSet.getString(CassandraResultSet.java:762)
    • 这是我在调试输出中看到的: rs CassandraResultSet (id=8426) ... indexMap HashMap (id=1277) has value: {user_id=1} ...类似的代码确实从没有组合的 2 列表中获得结果。有什么解决办法吗?
    • @jbellis :该错误似乎已在 1.2.0 中修复。我仍然可以在 1.2.5 中重现它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2014-06-27
    • 2019-02-07
    • 1970-01-01
    • 2017-06-16
    相关资源
    最近更新 更多