【问题标题】:How to get composite column name components如何获取复合列名组件
【发布时间】:2013-07-23 16:03:59
【问题描述】:

如何从 ByteBuffer 中获取 A 复合列组件?

我问this question

但没有得到回应。我现在正试图从字节缓冲区中获取列名作为

        Composite start = new Composite();
    start.addComponent(System.currentTimeMillis(), LS);
    List<HColumn<Composite, String>> columns = cs.setRange(start, null, true, 10).execute().get().getColumns();

    for (HColumn<Composite, String> column : columns) {
        ByteBuffer bf = column.getNameBytes();
        Serializer<Composite> ns = column.getNameSerializer();
        Composite composite = ns.fromByteBuffer(bf);
// I get an exception from above line
        String value = column.getValue();
    }

我的问题是我有一个包含两个 LongType 的复合比较器的列族 然后我在其中一个行上进行列切片,并从列列表中获取列名称并从中获取各个组件。请有人帮助我,我被卡住了

【问题讨论】:

    标签: java cassandra hector


    【解决方案1】:
    for (HColumn<Composite, String> column : columns) {
            for(Component<?> compositeComponent: column.getName().getComponents()) {
                    Serializer<?> srz = compositeComponent.getSerializer();
                    Object value = compositeComponent.getValue(srz);
            }
    }
    

    【讨论】:

    • 在好的方面,我感谢您的回复先生,很高兴知道有人真正阅读并试图帮助我。另一方面,您的解决方案无济于事,因为调用 column.getName() 时程序会中断。现在发布我找到的解决方案。显然,自从被问到 8 小时后,我无法回答自己的问题。当我在 Java EE 7 中运行我的项目时,我注意到了这个问题,即带有 netbeans 7.3.1 的 Glassfish 4.0 但是当我改回 Java EE 6 时,相同的代码可以工作。如果是,请您对此进行调查并提交错误报告。
    • 通常column.getName() 应该返回一个 AbstractComposite 实例。如果它坏了,你应该放一个调试器并检查 Hector 里面发生了什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    相关资源
    最近更新 更多