ColumnOrSuperColumn cosc = new ColumnOrSuperColumn(); Column column = new Column(ent.getColumnAs(StaticBuffer.BB_FACTORY)); column.setValue(ent.getValueAs(StaticBuffer.BB_FACTORY));
@Override public HColumn<N, V> setValue(V value) { notNull(value, "value is null"); this.column.setValue(valueSerializer.toByteBuffer(value)); this.cachedValue = null; return this; }
private Column makeColumn(long ts) { Column col = new Column(); col.setName(getColumnName()); col.setValue(PtBytes.toBytes(ts)); col.setTimestamp(CASSANDRA_TIMESTAMP); return col; }
/** * Prepare column. * * @param value * the value * @param name * the name * @param timestamp * the timestamp * @param ttl * TODO * @return the column */ private Column prepareColumn(byte[] value, byte[] name, long timestamp, int ttl) { Column column = new Column(); column.setName(name); column.setValue(value); column.setTimestamp(timestamp); if (ttl != 0) { column.setTtl(ttl); } return column; }
public HColumnImpl(N name, V value, long clock, Serializer<N> nameSerializer, Serializer<V> valueSerializer) { this(nameSerializer, valueSerializer); notNull(name, "name is null"); notNull(value, "value is null"); this.column = new Column(nameSerializer.toByteBuffer(name)); this.column.setValue(valueSerializer.toByteBuffer(value)); this.column.setTimestamp(clock); }
/** * Populates foreign key as column. * * @param rlName * relation name * @param rlValue * relation value * @param timestamp * the timestamp * @return the column * @throws PropertyAccessException * the property access exception */ protected Column populateFkey(String rlName, Object rlValue, long timestamp) throws PropertyAccessException { Column col = new Column(); col.setName(PropertyAccessorFactory.STRING.toBytes(rlName)); col.setValue(PropertyAccessorHelper.getBytes(rlValue)); col.setTimestamp(timestamp); return col; }
private static Column createColumnAtSpecificCassandraTimestamp(Cell cell, Value value, long cassandraTimestamp) { byte[] contents = value.getContents(); long atlasTimestamp = value.getTimestamp(); ByteBuffer colName = makeCompositeBuffer(cell.getColumnName(), atlasTimestamp); Column col = new Column(); col.setName(colName); col.setValue(contents); col.setTimestamp(cassandraTimestamp); return col; }
private static Column createColumn(String name, byte[] value) { Column column = new Column(); column.setName(PtBytes.toBytes(name)); column.setValue(value); return column; } }
@Test public void testMultiCallOnByteBuffer() { List<Column> tColumns = new ArrayList<Column>(); Column column = new Column(se.toByteBuffer("1")); column.setValue(ByteBuffer.wrap("colvalue".getBytes())); column.setTimestamp(0L); tColumns.add(column); ColumnSlice<String, ByteBuffer> slice = new ColumnSliceImpl<String, ByteBuffer>(tColumns, se, ByteBufferSerializer.get()); ByteBuffer value = slice.getColumnByName("1").getValue(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); } }
@Override public void insert(String key, ColumnPath columnPath, ByteBuffer value, long timestamp) throws HectorException { // valideColumnPath(columnPath); ColumnParent columnParent = new ColumnParent(columnPath.getColumn_family()); if (columnPath.isSetSuper_column()) { columnParent.setSuper_column(columnPath.getSuper_column()); } Column column = new Column(ByteBuffer.wrap(columnPath.getColumn())); column.setValue(value); column.setTimestamp(timestamp); insert(StringSerializer.get().toByteBuffer(key), columnParent, column); }
@Test public void testConstruction() { List<Column> tColumns = new ArrayList<Column>(); ColumnSlice<String, Long> slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertTrue(slice.getColumns().isEmpty()); Column column = new Column(ByteBuffer.wrap(new byte[]{})); column.setValue(ByteBuffer.wrap(new byte[]{})); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals(1, slice.getColumns().size()); tColumns = new ArrayList<Column>(); column = new Column(se.toByteBuffer("1")); column.setValue(le.toByteBuffer(1L)); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals((Long) 1L, slice.getColumnByName("1").getValue()); }
@Test public void testAddInsertionWithHint() { BatchMutation<String> batchMutate = new BatchMutation<String>(StringSerializer.get(), new BatchSizeHint(1, 50)); Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, column); Map<ByteBuffer, Map<String, List<Mutation>>> mutMap = batchMutate.getMutationMap(); assertEquals(1, mutMap.size()); assertEquals(ByteBuffer.wrap("key1".getBytes()), mutMap.keySet().iterator().next()); Map<String, List<Mutation>> cfMutMap = mutMap.values().iterator().next(); assertEquals(1, cfMutMap.size()); List<Mutation> cfMutList = cfMutMap.values().iterator().next(); assertTrue(cfMutList instanceof ArrayList); }
@Override public void insert(String key, ColumnPath columnPath, ByteBuffer value) throws HectorException { // valideColumnPath(columnPath); ColumnParent columnParent = new ColumnParent(columnPath.getColumn_family()); if (columnPath.isSetSuper_column()) { columnParent.setSuper_column(columnPath.getSuper_column()); } Column column = new Column(ByteBuffer.wrap(columnPath.getColumn())); column.setValue(value); column.setTimestamp(connectionManager.createClock()); insert(StringSerializer.get().toByteBuffer(key), columnParent, column); }
@Test public void testConstruction() { LongSerializer le = LongSerializer.get(); StringSerializer se = StringSerializer.get(); ByteBufferSerializer be = ByteBufferSerializer.get(); // empty one List<SuperColumn> tColumns = new ArrayList<SuperColumn>(); SuperSlice<String, Long, ByteBuffer> slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertTrue(slice.getSuperColumns().isEmpty()); // non-empty one Column c = new Column(le.toByteBuffer(5L)); c.setValue(be.toByteBuffer(ByteBuffer.wrap(new byte[] { 1 }))); c.setTimestamp(2L); tColumns.add(new SuperColumn(se.toByteBuffer("super"), Arrays.asList(c))); slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertEquals(1, slice.getSuperColumns().size()); Assert.assertEquals((Long) 5L, slice.getColumnByName("super").get(0).getName()); } }
@Test public void testAddInsertion() { Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, column); // assert there is one outter map row with 'key' as the key Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = batchMutate.getMutationMap(); assertEquals(1, mutationMap.get(StringSerializer.get().toByteBuffer("key1")).size()); // add again with a different column and verify there is one key and two mutations underneath // for "standard1" Column column2 = new Column(StringSerializer.get().toByteBuffer("c_name2")); column2.setValue(StringSerializer.get().toByteBuffer("c_val2")); column2.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1",columnFamilies, column2); assertEquals(2, mutationMap.get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
@Test public void testAddSuperInsertion() { Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); SuperColumn sc = new SuperColumn(StringSerializer.get().toByteBuffer("c_name"), Arrays.asList(column)); batchMutate.addSuperInsertion("key1", columnFamilies, sc); // assert there is one outter map row with 'key' as the key assertEquals(1, batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).size()); // add again with a different column and verify there is one key and two mutations underneath // for "standard1" column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); SuperColumn sc2 = new SuperColumn(StringSerializer.get().toByteBuffer("c_name2"), Arrays.asList(column)); batchMutate.addSuperInsertion("key1", columnFamilies, sc2); assertEquals(2, batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
thriftColumn.setValue(ecValue.getBytes()); thriftColumn.setTimestamp(generator.getTimestamp());
@Test public void testIsEmpty() { assertTrue(batchMutate.isEmpty()); // Insert a column Column c1 = new Column(StringSerializer.get().toByteBuffer("c_name")); c1.setValue(StringSerializer.get().toByteBuffer("c_val")); c1.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, c1); assertFalse(batchMutate.isEmpty()); // Insert a Counter. CounterColumn cc1 = new CounterColumn(StringSerializer.get().toByteBuffer("c_name"), 13); batchMutate.addCounterInsertion("key1", columnFamilies, cc1); assertFalse(batchMutate.isEmpty()); }
/** * Test insertion of a supercolumn using insert */ @Test public void testInsertSuper() throws IllegalArgumentException, NoSuchElementException, IllegalStateException, HNotFoundException, Exception { // insert value ColumnParent columnParent = new ColumnParent("Super1"); columnParent.setSuper_column(StringSerializer.get().toByteBuffer("testInsertSuper_super")); Column column = new Column(StringSerializer.get().toByteBuffer("testInsertSuper_column")); column.setValue(StringSerializer.get().toByteBuffer("testInsertSuper_value")); column.setTimestamp(connectionManager.createClock()); keyspace.insert(StringSerializer.get().toByteBuffer("testInsertSuper_key"), columnParent, column); column.setName(StringSerializer.get().toByteBuffer("testInsertSuper_column2")); keyspace.insert(StringSerializer.get().toByteBuffer("testInsertSuper_key"), columnParent, column); // get value and assert ColumnPath cp2 = new ColumnPath("Super1"); cp2.setSuper_column(bytes("testInsertSuper_super")); SuperColumn sc = keyspace.getSuperColumn("testInsertSuper_key", cp2); assertNotNull(sc); assertEquals("testInsertSuper_super", string(sc.getName())); assertEquals(2, sc.getColumns().size()); assertEquals("testInsertSuper_value", string(sc.getColumns().get(0).getValue())); // remove value keyspace.remove("testInsertSuper_super", cp2); }
col.setValue(StringSerializer.get().toByteBuffer("testBatchMutateColumn_value_" + j)); col.setTimestamp(connectionManager.createClock()); batchMutation.addInsertion("testBatchMutateColumn_" + i, columnFamilies, col);