for (StaticBuffer buf : mutation.getDeletions()) { Deletion d = new Deletion(); SlicePredicate sp = new SlicePredicate(); sp.addToColumn_names(buf.as(StaticBuffer.BB_FACTORY)); d.setPredicate(sp);
@Override public void setConf(final Configuration config) { super.setConf(config); // Copy some Titan configuration keys to the Hadoop Configuration keys used by Cassandra's ColumnFamilyInputFormat ConfigHelper.setInputInitialAddress(config, titanConf.get(GraphDatabaseConfiguration.STORAGE_HOSTS)[0]); if (titanConf.has(GraphDatabaseConfiguration.STORAGE_PORT)) ConfigHelper.setInputRpcPort(config, String.valueOf(titanConf.get(GraphDatabaseConfiguration.STORAGE_PORT))); if (titanConf.has(GraphDatabaseConfiguration.AUTH_USERNAME)) ConfigHelper.setInputKeyspaceUserName(config, titanConf.get(GraphDatabaseConfiguration.AUTH_USERNAME)); if (titanConf.has(GraphDatabaseConfiguration.AUTH_PASSWORD)) ConfigHelper.setInputKeyspacePassword(config, titanConf.get(GraphDatabaseConfiguration.AUTH_PASSWORD)); // Copy keyspace, force the CF setting to edgestore, honor widerows when set final boolean wideRows = config.getBoolean(INPUT_WIDEROWS_CONFIG, false); // Use the setInputColumnFamily overload that includes a widerows argument; using the overload without this argument forces it false ConfigHelper.setInputColumnFamily(config, titanConf.get(AbstractCassandraStoreManager.CASSANDRA_KEYSPACE), mrConf.get(TitanHadoopConfiguration.COLUMN_FAMILY_NAME), wideRows); log.debug("Set keyspace: {}", titanConf.get(AbstractCassandraStoreManager.CASSANDRA_KEYSPACE)); // Set the column slice bounds via Faunus's vertex query filter final SlicePredicate predicate = new SlicePredicate(); final int rangeBatchSize = config.getInt(RANGE_BATCH_SIZE_CONFIG, Integer.MAX_VALUE); predicate.setSlice_range(getSliceRange(TitanHadoopSetupCommon.DEFAULT_SLICE_QUERY, rangeBatchSize)); // TODO stop slicing the whole row ConfigHelper.setInputSlicePredicate(config, predicate); }
new SlicePredicate() .setSlice_range(sliceRange), keyRange,
SlicePredicate predicate = new SlicePredicate(); SliceRange range = new SliceRange(); range.setCount(query.getLimit() + (query.hasLimit()?1:0)); //Add one for potentially removed last column
SlicePredicate predicate = new SlicePredicate().setSlice_range(columnSlice);
@Override public Map<ByteBuffer, SuperColumn> multigetSuperColumn(List<ByteBuffer> keys, ColumnPath columnPath, boolean reversed, int size) throws HectorException { //valideSuperColumnPath(columnPath); // only can get supercolumn by multigetSuperSlice ColumnParent clp = new ColumnParent(columnPath.getColumn_family()); clp.setSuper_column(columnPath.getSuper_column()); SliceRange sr = new SliceRange(ByteBuffer.wrap(new byte[0]), ByteBuffer.wrap(new byte[0]), reversed, size); SlicePredicate sp = new SlicePredicate(); sp.setSlice_range(sr); Map<ByteBuffer, List<SuperColumn>> sclist = multigetSuperSlice(keys, clp, sp); if (sclist == null || sclist.isEmpty()) { return Collections.emptyMap(); } Map<ByteBuffer, SuperColumn> result = new HashMap<ByteBuffer, SuperColumn>(keys.size() * 2); for (Map.Entry<ByteBuffer, List<SuperColumn>> entry : sclist.entrySet()) { List<SuperColumn> sclistByKey = entry.getValue(); if (sclistByKey.size() > 0) { result.put(entry.getKey(), sclistByKey.get(0)); } } return result; }
public static SlicePredicate create(Range range, Limit limit) { SliceRange slice = new SliceRange( range.start(), range.end(), false, limit.value()); SlicePredicate predicate = new SlicePredicate(); predicate.setSlice_range(slice); return predicate; }
@Override public <N> Mutator<K> addCounterDeletion(K key, String cf, N counterColumnName, Serializer<N> nameSerializer) { Deletion d; if ( counterColumnName != null ) { SlicePredicate sp = new SlicePredicate(); sp.addToColumn_names(nameSerializer.toByteBuffer(counterColumnName)); d = new Deletion().setPredicate(sp); } else { d = new Deletion(); } getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
@Test public void getSizeForMutationWithDeletionContainingNonEmptySlicePredicate() { long deletionSize = (Long.BYTES) + NULL_SIZE + (TEST_NAME.getBytes().length + NULL_SIZE); assertThat(ThriftObjectSizeUtils .getMutationSize(new Mutation() .setDeletion(new Deletion() .setPredicate(new SlicePredicate() .setColumn_names(ImmutableList.of(ByteBuffer.wrap(TEST_NAME.getBytes()))))))) .isEqualTo(NULL_SIZE + deletionSize); }
@Override public SuperColumn execute(Cassandra.Client cassandra) throws HectorException { ColumnParent clp = new ColumnParent(columnPath.getColumn_family()); clp.setSuper_column(columnPath.getSuper_column()); SlicePredicate sp = new SlicePredicate(); sp.setSlice_range(sliceRange); try { List<ColumnOrSuperColumn> cosc = cassandra.get_slice(key, clp, sp, getThriftCl(OperationType.READ)); if (cosc == null || cosc.isEmpty()) { return null; } return new SuperColumn(ByteBuffer.wrap(columnPath.getSuper_column()), getColumnList(cosc)); } catch (Exception e) { throw xtrans.translate(e); } } };
@Override public <SN, N> Mutator<K> addSubDelete(K key, String cf, SN sColumnName, N columnName, Serializer<SN> sNameSerializer, Serializer<N> nameSerializer, long clock) { Deletion d = new Deletion().setTimestamp(clock); SlicePredicate predicate = new SlicePredicate(); predicate.addToColumn_names(nameSerializer.toByteBuffer(columnName)); d.setPredicate(predicate); d.setSuper_column(sNameSerializer.toByteBuffer(sColumnName)); getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
/** * {@inheritDoc} */ @Override public <N> Mutator<K> addDeletion(K key, String cf, N columnNameStart, N columnNameFinish, Serializer<N> nameSerializer, long clock) { SlicePredicate sp = new SlicePredicate(); sp.setSlice_range(new SliceRange(nameSerializer.toByteBuffer(columnNameStart), nameSerializer.toByteBuffer(columnNameFinish), false, Integer.MAX_VALUE)); Deletion d = new Deletion().setTimestamp(clock).setPredicate(sp); getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
@Test public void handlesNullMultigetSliceResponseFromDelegate() throws TException { ByteBuffer byteBuffer = ByteBuffer.wrap(PtBytes.toBytes("foo")); List<ColumnOrSuperColumn> columns = ImmutableList.of( new ColumnOrSuperColumn().setColumn(new Column(byteBuffer))); ImmutableMap<ByteBuffer, List<ColumnOrSuperColumn>> resultMap = ImmutableMap.of(byteBuffer, columns); when(delegate.multiget_slice(any(), any(), any(), any(), any())).thenReturn(resultMap); assertThat(delegate.multiget_slice( "getRows", TableReference.createFromFullyQualifiedName("a.b"), ImmutableList.of(byteBuffer), new SlicePredicate(), ConsistencyLevel.QUORUM)).isEqualTo(resultMap); verify(delegate).multiget_slice( "getRows", TableReference.createFromFullyQualifiedName("a.b"), ImmutableList.of(byteBuffer), new SlicePredicate(), ConsistencyLevel.QUORUM); }
/** * {@inheritDoc} */ @Override public <N> Mutator<K> addDeletion(K key, String cf, N columnName, Serializer<N> nameSerializer, long clock) { Deletion d; if ( columnName != null ) { SlicePredicate sp = new SlicePredicate(); sp.addToColumn_names(nameSerializer.toByteBuffer(columnName)); d = new Deletion().setTimestamp(clock).setPredicate(sp); } else { d = new Deletion().setTimestamp(clock); } getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
@Test public void getSizeForMutationWithDeletionContainingEmptySlicePredicate() { long deletionSize = Long.BYTES + NULL_SIZE + NULL_SIZE * 2; assertThat(ThriftObjectSizeUtils.getMutationSize(new Mutation() .setDeletion(new Deletion().setPredicate(new SlicePredicate())))) .isEqualTo(NULL_SIZE + deletionSize); }
@Override public <SN, N> Mutator<K> addCounterSubDeletion(K key, String cf, HCounterSuperColumn<SN, N> sc) { Deletion d = new Deletion(); if ( sc.getColumns() != null ) { SlicePredicate pred = new SlicePredicate(); for (HCounterColumn<N> col : sc.getColumns()) { pred.addToColumn_names(col.getNameSerializer().toByteBuffer(col.getName())); } d.setPredicate(pred); } d.setSuper_column(sc.getNameByteBuffer()); getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
public <SN,N,V> Mutator<K> addSubDelete(K key, String cf, HSuperColumn<SN,N,V> sc, long clock) { Deletion d = new Deletion().setTimestamp(clock); if ( sc.getColumns() != null ) { SlicePredicate pred = new SlicePredicate(); for (HColumn<N, V> col : sc.getColumns()) { pred.addToColumn_names(col.getNameSerializer().toByteBuffer(col.getName())); } d.setPredicate(pred); } d.setSuper_column(sc.getNameByteBuffer()); getPendingMutations().addDeletion(key, Arrays.asList(cf), d); return this; }
@Test public void testAddDeletion() { Deletion deletion = new Deletion().setTimestamp(System.currentTimeMillis()); SlicePredicate slicePredicate = new SlicePredicate(); slicePredicate.addToColumn_names(StringSerializer.get().toByteBuffer("c_name")); deletion.setPredicate(slicePredicate); batchMutate.addDeletion("key1", columnFamilies, deletion); assertEquals(1,batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).size()); deletion = new Deletion().setTimestamp(System.currentTimeMillis()); slicePredicate = new SlicePredicate(); slicePredicate.addToColumn_names(StringSerializer.get().toByteBuffer("c_name2")); deletion.setPredicate(slicePredicate); batchMutate.addDeletion("key1", columnFamilies, deletion); assertEquals(2,batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
@Test public void testAddCounterDeletion() { Deletion counterDeletion = new Deletion(); SlicePredicate slicePredicate = new SlicePredicate(); slicePredicate.addToColumn_names(StringSerializer.get().toByteBuffer("c_name")); counterDeletion.setPredicate(slicePredicate); batchMutate.addDeletion("key1", columnFamilies, counterDeletion); assertEquals(1, batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).size()); counterDeletion = new Deletion(); slicePredicate = new SlicePredicate(); slicePredicate.addToColumn_names(StringSerializer.get().toByteBuffer("c_name2")); counterDeletion.setPredicate(slicePredicate); batchMutate.addDeletion("key1", columnFamilies, counterDeletion); assertEquals(2,batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
SlicePredicate sp = new SlicePredicate(); sp.setSlice_range(sr); List<SuperColumn> cols = keyspace.getSuperSlice("testGetSuperSlice", clp, sp);