【问题标题】:Cassandra 2 Hector: range slice query on composite row key return empty rowsCassandra 2 Hector:复合行键上的范围切片查询返回空行
【发布时间】:2014-07-24 09:47:49
【问题描述】:

我们正在使用 ByteOrderedPartitioner 存储新项目的时间序列,cql3 对我们来说还不错,然后我们选择 Hector 继续前进,但现在我们的范围查询不起作用。

C* 版本:2.0.7

赫克托版本:1.0-5

架构:

        ColumnFamilyDefinition cfd = HFactory.createColumnFamilyDefinition(
                keyspaceName, columnFamilyName,
                ComparatorType.UTF8TYPE);
        cfd.setComparatorTypeAlias("(IntegerType,IntegerType,IntegerType)");
        cfd.setKeyValidationClass("CompositeType(IntegerType,IntegerType,IntegerType)");
        cfd.setDefaultValidationClass(ComparatorType.UTF8TYPE.getClassName());

行键:100:20:11

=>(名称=column1,值=AAL,时间戳=1401745673543000)

=>(名称=column2,值=NYC,时间戳=1401745673543002)

行键:100:20:12

=>(名称=column1,值=AAL,时间戳=1401745673543000)

=>(名称=column2,值=TXA,时间戳=1401745673543002)

等等..

查询遍历 cassandra 列族的所有行

    Composite startComposite = new Composite();
    startComposite.addComponent(0,100,EQUAL);
    startComposite.addComponent(1,20,EQUAL);
    startComposite.addComponent(2,11,EQUAL);

    Composite endComposite = new Composite();
    endComposite.addComponent(0,100,EQUAL);
    endComposite.addComponent(1,20, EQUAL);
    endComposite.addComponent(2,18,GREATER_THAN_EQUAL);

    int rowCount = 100;
    RangeSlicesQuery<Composite, String, String> rangeSlicesQuery = HFactory
            .createRangeSlicesQuery(ksp, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
            .setColumnFamily(columnFamilyName)
            .setRange("", "", false, rowCount);

    rangeSlicesQuery.setKeys(startComposite, endComposite);
    QueryResult<OrderedRows<Composite, String, String>> result = rangeSlicesQuery.execute();

    System.out.println(result.get());

获取空行:

行({})

【问题讨论】:

    标签: java cassandra hector


    【解决方案1】:

    这是一个 Cassandra 反模式。使用 ByteOrderedPartitioner 的充分理由很少,而且这种模式不是其中之一。您最终会导致所有写入和查询基本上命中一个节点(或少数节点,具体取决于您的集群大小)。

    Cassandra 中有许多很好的时间序列数据模型示例。 Here is one from Datastax.

    【讨论】:

    • 你说得对,我一直在分析一个可以与 Murmur3Partitioner 一起运行的新模式,我得到了新的东西,我们改变了它,因为我们的 CQL3 查询使用令牌函数来遍历所有请求的行键:令牌( year_month, day) >= token(201404,20) AND token(year_month, day)
    • Check out this article 了解如何对所有行进行分页。您不能使用随机分区器对范围进行分页,因为键没有排序。如果要执行此操作,您需要使用SELECT * FROM ks.table WHERE mykey IN (v1, v2, v3) 编写一个包含范围内所有已知键的查询。由于您的密钥是月/日/年,因此计算起来应该很简单。
    猜你喜欢
    • 1970-01-01
    • 2014-11-17
    • 2012-03-13
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 2014-09-15
    相关资源
    最近更新 更多