对于cassandra的数据存储结构最主要的就是key-value的结构化存储,cassandra中有两种表的类型,一种是SuperColumnFamily,另一种是StandColumnFamily
今天学习了一下cassandra1.1里面的standCF的compositeName
rowey | compositeName1+columnName1 | value | compositeName1+columnName2 | value | compositeName1+columnName3 | value |
compositeName2+columnName1 | value | compositeName2+columnName2 | value | compositeName2+columnName3 | value | |
... | ... | ... | ... | ... | ... |
public Builder add(Term t, Relation.Type op, List
{
if (current >= composite.types.size())
throw new IllegalStateException("Composite column is already fully constructed");
AbstractType currentType = composite.types.get(current++);
ByteBuffer buffer = t.getByteBuffer(currentType, variables);
ByteBufferUtil.writeWithShortLength(buffer, out);
/*
* Given the rules for eoc (end-of-component, see AbstractCompositeType.compare()),
* We can select:
* - = 'a' by using <'a'><0>
* - < 'a' by using <'a'><-1>
* - <= 'a' by using <'a'><1>
* - > 'a' by using <'a'><1>
* - >= 'a' by using <'a'><0>
*/
switch (op)
{
case LT:
out.write((byte) -1);
break;
case GT:
case LTE:
out.write((byte) 1);
break;
default:
out.write((byte) 0);
break;
}
return this;
}
以0为间隔的好处在于当rowkey下有数据为A0a,A0b,A0c,A0d的时候,
如果是composite字段=A,则构造的查询范围为name为A0,
如果是composite字段<=A,则构造的查询范围为finish=A1,
如果是composite字段>A,则构造的查询范围为start=A1,
如果是composite字段>=A,则构造的查询范围为start=A0,