【问题标题】:Do I need to create a special column family for counter columns?我需要为计数器柱创建一个特殊的柱族吗?
【发布时间】:2011-06-10 06:24:59
【问题描述】:

我的问题涉及 Cassandra 0.8 和 Pelops。我发现 Pelops 使用相同的 Thrift 命令来读取列切片和计数器列切片。然后,它遍历检索到的 Thrift ColumnOrSuperColumn 对象集合,断言该列(或 counter_column)字段不为空。似乎很明显,对于混合列族,执行这些方法中的任何一个都会失败。

那么,Cassandra 是否要求列族中的所有列都必须属于同一类型?

以下代码是来自 Pelops 的 Selector 类的片段。

private List<Column> getColumnsFromRow(final ColumnParent colParent, final Bytes rowKey, final SlicePredicate colPredicate, final ConsistencyLevel cLevel) throws PelopsException {
    IOperation<List<Column>> operation = new IOperation<List<Column>>() {
        @Override
        public List<Column> execute(IPooledConnection conn) throws Exception {
            List<ColumnOrSuperColumn> apiResult = conn.getAPI().get_slice(safeGetRowKey(rowKey), colParent, colPredicate, cLevel);
            return toColumnList(apiResult);
        }
    };
    return tryOperation(operation);
}

private List<CounterColumn> getCounterColumnsFromRow(final ColumnParent colParent, final Bytes rowKey, final SlicePredicate colPredicate, final ConsistencyLevel cLevel) throws PelopsException {
    IOperation<List<CounterColumn>> operation = new IOperation<List<CounterColumn>>() {
        @Override
        public List<CounterColumn> execute(IPooledConnection conn) throws Exception {
            List<ColumnOrSuperColumn> apiResult = conn.getAPI().get_slice(safeGetRowKey(rowKey), colParent, colPredicate, cLevel);
            return toCounterColumnList(apiResult);
        }
    };
    return tryOperation(operation);
}

private static List<Column> toColumnList(List<ColumnOrSuperColumn> coscList) {
    List<Column> columns = new ArrayList<Column>(coscList.size());
    for (ColumnOrSuperColumn cosc : coscList) {
        assert cosc.column != null : "The column should not be null";
        columns.add(cosc.column);
    }
    return columns;
}

private static List<CounterColumn> toCounterColumnList(List<ColumnOrSuperColumn> coscList) {
    List<CounterColumn> columns = new ArrayList<CounterColumn>(coscList.size());
    for (ColumnOrSuperColumn cosc : coscList) {
        assert cosc.counter_column != null : "The column should not be null";
        columns.add(cosc.counter_column);
    }
    return columns;
}

【问题讨论】:

    标签: api cassandra thrift


    【解决方案1】:

    那么,Cassandra 是否要求所有 列族中的列将 是同一类型的吗?

    是的,目前它确实要求 CF 包含所有计数器或所有非计数器。不过,

    • This will change,可能最快 0.8.1
    • 非计数器绝对不必是相同的数据类型(bytes、long、utf8 等都可以混合在同一行中)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-08
      • 2015-01-27
      • 1970-01-01
      相关资源
      最近更新 更多