static Map<ByteBuffer, List<ColumnOrSuperColumn>> getColsByKey(List<KeySlice> firstPage) { Map<ByteBuffer, List<ColumnOrSuperColumn>> ret = Maps.newHashMapWithExpectedSize(firstPage.size()); for (KeySlice e : firstPage) { ret.put(ByteBuffer.wrap(e.getKey()), e.getColumns()); } return ret; } }
/** * Transform thrift result. * * @param <T> the generic type * @param columnFamilyType the column family type * @param keySlices the key slices * @param row the row * @return the map */ public static <T> Map<ByteBuffer, List<T>> transformThriftResult(ColumnFamilyType columnFamilyType, List<KeySlice> keySlices, ThriftRow row) { Map<ByteBuffer, List<T>> output = new HashMap<ByteBuffer, List<T>>(); for (KeySlice keySlice : keySlices) { output.put(ByteBuffer.wrap(keySlice.getKey()), (List<T>) transformThriftResult(keySlice.getColumns(), columnFamilyType, row)); } return output; }
@Override public Map<ByteBuffer, List<CounterColumn>> execute(Cassandra.Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_range_slices(columnParent, predicate, keyRange, getThriftCl(OperationType.READ)); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<CounterColumn>>(0); } LinkedHashMap<ByteBuffer, List<CounterColumn>> ret = new LinkedHashMap<ByteBuffer, List<CounterColumn>>( keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), getCounterColumnList(keySlice.getColumns())); } return ret; } catch (Exception e) { throw xtrans.translate(e); } }; };
@Override public Map<ByteBuffer, List<CounterSuperColumn>> execute(Cassandra.Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_range_slices(columnParent, predicate, keyRange, getThriftCl(OperationType.READ)); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<CounterSuperColumn>>(); } LinkedHashMap<ByteBuffer, List<CounterSuperColumn>> ret = new LinkedHashMap<ByteBuffer, List<CounterSuperColumn>>( keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), getCounterSuperColumnList(keySlice.getColumns())); } return ret; } catch (Exception e) { throw xtrans.translate(e); } } };
@Override public Map<ByteBuffer, List<Column>> execute(Cassandra.Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_range_slices(columnParent, predicate, keyRange, getThriftCl(OperationType.READ)); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<Column>>(0); } LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>( keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), getColumnList(keySlice.getColumns())); } return ret; } catch (Exception e) { throw xtrans.translate(e); } }; };
@Override public Map<ByteBuffer, List<SuperColumn>> execute(Cassandra.Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_range_slices(columnParent, predicate, keyRange, getThriftCl(OperationType.READ)); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<SuperColumn>>(); } LinkedHashMap<ByteBuffer, List<SuperColumn>> ret = new LinkedHashMap<ByteBuffer, List<SuperColumn>>( keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), getSuperColumnList(keySlice.getColumns())); } return ret; } catch (Exception e) { throw xtrans.translate(e); } } };
@Override public Map<ByteBuffer, List<Column>> execute(Cassandra.Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_indexed_slices(columnParent, indexClause, predicate, getThriftCl(OperationType.READ)); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<Column>>(0); } LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>( keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), getColumnList(keySlice.getColumns())); } return ret; } catch (Exception e) { throw xtrans.translate(e); } }; };
@Override public Map<ByteBuffer, List<ColumnOrSuperColumn>> execute(Client cassandra) throws HectorException { try { List<KeySlice> keySlices = cassandra.get_indexed_slices( columnParent, predicate.toThrift(), workingSlicePredicate.toThrift(), ThriftConverter.consistencyLevel(consistencyLevelPolicy.get(operationType, columnFamily))); if (keySlices == null || keySlices.isEmpty()) { return new LinkedHashMap<ByteBuffer, List<ColumnOrSuperColumn>>(0); } LinkedHashMap<ByteBuffer, List<ColumnOrSuperColumn>> ret = new LinkedHashMap<ByteBuffer, List<ColumnOrSuperColumn>>(keySlices.size()); for (KeySlice keySlice : keySlices) { ret.put(ByteBuffer.wrap(keySlice.getKey()), keySlice.getColumns()); } return ret; } catch (Exception e) { throw exceptionsTranslator.translate(e); } } });
public static long getKeySliceSize(KeySlice keySlice) { if (keySlice == null) { return getNullSize(); } return getByteArraySize(keySlice.getKey()) + getCollectionSize(keySlice.getColumns(), ThriftObjectSizeUtils::getColumnOrSuperColumnSize); }
/** * Fetches Row keys from a {@link List} of {@link KeySlice}. * * @param keySlices the key slices * @param metadata the metadata * @return the row keys */ public static List<Object> getRowKeys(List<KeySlice> keySlices, EntityMetadata metadata) { PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor((Field) metadata.getIdAttribute() .getJavaMember()); List<Object> rowKeys = new ArrayList<Object>(); for (KeySlice keySlice : keySlices) { byte[] key = keySlice.getKey(); Object rowKey = accessor.fromBytes(metadata.getIdAttribute().getJavaType(), key); rowKeys.add(rowKey); } return rowKeys; }
byte[] key = keySlice.getKey(); List<ColumnOrSuperColumn> coscList = keySlice.getColumns();
List<ColumnOrSuperColumn> columns = key.getColumns(); byte[] rowKey = key.getKey();
public Object getFieldValue(_Fields field) { switch (field) { case KEY: return getKey(); case COLUMNS: return getColumns(); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case KEY: return getKey(); case COLUMNS: return getColumns(); } throw new IllegalStateException(); }
static Map<ByteBuffer, List<ColumnOrSuperColumn>> getColsByKey(List<KeySlice> firstPage) { Map<ByteBuffer, List<ColumnOrSuperColumn>> ret = Maps.newHashMapWithExpectedSize(firstPage.size()); for (KeySlice e : firstPage) { ret.put(ByteBuffer.wrap(e.getKey()), e.getColumns()); } return ret; } }
public Object getFieldValue(_Fields field) { switch (field) { case KEY: return getKey(); case COLUMNS: return getColumns(); } throw new IllegalStateException(); }
public ThriftRowsSliceImpl(List<KeySlice> rows, Serializer<K> keySer, Serializer<C> colSer) { this.rows = Lists.newArrayListWithCapacity(rows.size()); for (KeySlice row : rows) { Row<K,C> thriftRow = new ThriftRowImpl<K, C>( keySer.fromBytes(row.getKey()), ByteBuffer.wrap(row.getKey()), new ThriftColumnOrSuperColumnListImpl<C>(row.getColumns(), colSer)); this.rows.add(thriftRow); } }
public static <T> Map<Bytes, List<T>> transformThriftResult(ColumnFamilyType columnFamilyType, List<KeySlice> keySlices, ThriftRow row) { Map<Bytes, List<T>> output = new HashMap<Bytes, List<T>>(); for (KeySlice keySlice : keySlices) { output.put(Bytes.fromByteArray(keySlice.getKey()), (List<T>) transformThriftResult(keySlice.getColumns(), columnFamilyType, row)); } return output; }
@Override public Row<K, C> next() { org.apache.cassandra.thrift.KeySlice row = iter.next(); return new ThriftRowImpl<K, C>(columnFamily.getKeySerializer().fromBytes(row.getKey()), ByteBuffer.wrap(row.getKey()), new ThriftColumnOrSuperColumnListImpl<C>(row.getColumns(), columnFamily.getColumnSerializer())); }