public ColumnFamilyUpdater<K, N> createUpdater(K key) { ColumnFamilyUpdater<K, N> updater = new ColumnFamilyUpdater<K, N>(this, columnFactory); updater.addKey(key); return updater; }
public <V> void setColumn(HColumn<N, V> column) { mutator.addInsertion(getCurrentKey(), template.getColumnFamily(), column); } }
public void update(ColumnFamilyUpdater<K, N> updater) { updater.update(); executeIfNotBatched(updater); }
updater.setString("column1","string value"); updater.setUUID("column2", UUID.fromString("cf316d50-f7c0-11e1-a21f-0800200c9a66")); updater.setLong("column3", 829398278497234L); updater.setInteger("column4", 27344); updater.setFloat("column5",3.14159265f); updater.setDouble("column6",3.14159265358979323846264338327950288); updater.setBoolean("column7", true); updater.setByteArray("column8", new byte[] {97, 91, 99}); Date date = new Date(); updater.setDate("column9", date);
@Test public void testQueryMultiget() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("mg_key1"); updater.setString("column1","value1"); updater.addKey("mg_key2"); updater.setString("column1","value2"); updater.addKey("mg_key3"); updater.setString("column1","value3"); template.update(updater); template.addColumn("column1", se); ColumnFamilyResult<String,String> wrapper = template.queryColumns(Arrays.asList("mg_key1", "mg_key2", "mg_key3")); assertEquals("value1",wrapper.getString("column1")); wrapper.next(); assertEquals("value2",wrapper.getString("column1")); wrapper.next(); assertEquals("value3",wrapper.getString("column1")); }
@Test public void testCompareClocks() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); long ts1 = 1001; long ts2 = 1002; long ts3 = 1003; ColumnFamilyUpdater<String,String> updater = template.createUpdater("compare_clock_key1"); updater.setClock(ts1); updater.setString("stringval","value1"); Date date = new Date(); updater.setClock(ts2); updater.setDate("curdate", date); updater.setClock(ts3); updater.setLong("longval", 5L); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult wrapper = template.queryColumns("compare_clock_key1"); assertEquals(ts1,wrapper.getColumn("stringval").getClock()); assertEquals(ts2,wrapper.getColumn("curdate").getClock()); assertEquals(ts3,wrapper.getColumn("longval").getClock()); assertEquals(3,wrapper.getColumnNames().size()); }
public <V> void setValue(N columnName, V value, Serializer<V> serializer) { addInsertion(columnName, value, serializer, globalTtl); }
ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Indexed1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("index_key1"); updater.setLong("birthyear", 1974L); updater.setLong("birthmonth", 4L); updater.addKey("index_key2"); updater.setLong("birthyear", 1975L); updater.setLong("birthmonth", 4L); updater.addKey("index_key3"); updater.setLong("birthyear", 1975L); updater.setLong("birthmonth", 5L); updater.addKey("index_key4"); updater.setLong("birthyear", 1975L); updater.setLong("birthmonth", 6L); updater.addKey("index_key5"); updater.setLong("birthyear", 1975L); updater.setLong("birthmonth", 7L); updater.addKey("index_key6"); updater.setLong("birthyear", 1976L); updater.setLong("birthmonth", 6L); template.update(updater);
@Test public void testCreateSelectMultiColumn() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("cskey1"); updater.setString("stringval","value1"); Date date = new Date(); updater.setDate("curdate", date); updater.setLong("longval", 5L); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult<String,String> wrapper = template.queryColumns("cskey1"); assertEquals("value1",wrapper.getString("stringval")); assertEquals(date,wrapper.getDate("curdate")); assertEquals(new Long(5),wrapper.getLong("longval")); assertEquals(3,wrapper.getColumnNames().size()); }
@Test public void testCreateSelectSpecifiedColumn() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("csskey1"); updater.setString("col1","value1"); updater.setString("col2","value2"); updater.setString("col3","value3"); updater.setString("col4","value4"); updater.setString("col5","value5"); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult<String,String> wrapper = template.queryColumns("csskey1", Arrays.asList("col1", "col3", "col5")); assertEquals("value1",wrapper.getString("col1")); assertNull(wrapper.getString("col2")); assertEquals("value3",wrapper.getString("col3")); assertNull(wrapper.getString("col4")); assertEquals("value5",wrapper.getString("col5")); assertEquals(3,wrapper.getColumnNames().size()); }
@Test public void testTtl() throws InterruptedException { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace,"Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("test_ttl_key1"); updater.setString("expired_string", "value1",1); updater.setString("unexpired_string", "value2"); updater.setBoolean("unexpired_bool", true); updater.setBoolean("expired_bool", true, 1); template.update(updater); Thread.sleep(1000); ColumnFamilyResult<String,String> wrapper = template.queryColumns("test_ttl_key1"); HColumn<String,ByteBuffer> col = wrapper.getColumn("unexpired_string"); assertNotNull(col); assertNotNull(col.getValue()); HColumn<String,ByteBuffer> expiredStringCol = wrapper.getColumn("expired_string"); assertNull(expiredStringCol); HColumn<String,ByteBuffer> expiredBooleanCol = wrapper.getColumn("expired_bool"); assertNull(expiredBooleanCol); }
public ColumnFamilyUpdater<K, N> createUpdater() { ColumnFamilyUpdater<K, N> updater = new ColumnFamilyUpdater<K, N>(this, columnFactory); return updater; }
@Override public void multiPut(List<List<Object>> keys, List<T> vals) { for(int i=0; i<keys.size(); i++) { List<Object> keyCol = keys.get(i); checkKeyCol(keyCol); T val = vals.get(i); byte[] ser = _valueSer.serialize(val); ColumnFamilyUpdater updater = _template.createUpdater(keyCol.get(0)); updater.setByteArray(getCol(keyCol), ser); _template.update(updater); } }
updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().getTime() ); updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().getTime() ); updater.setLong( SIZE.toString(), artifactMeta.getSize() ); addUpdateStringValue( updater, MD5.toString(), artifactMeta.getMd5() ); addUpdateStringValue( updater, SHA1.toString(), artifactMeta.getSha1() );
ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("mgs_key1"); updater.setString("column1","value1-1"); updater.setString("column2","value2-1"); updater.setString("column3","value3-1"); updater.addKey("mgs_key2"); updater.setString("column1","value1-2"); updater.setString("column2","value2-2"); updater.setString("column3","value3-2"); updater.addKey("mgs_key3"); updater.setString("column1","value1-3"); updater.setString("column2","value2-3"); updater.setString("column3","value3-3"); template.update(updater);
public <V> void setValue(N columnName, V value, Serializer<V> serializer, int ttl) { addInsertion(columnName, value, serializer, ttl); }
/** * null check on the value to prevent {@link java.lang.IllegalArgumentException} * @param updater * @param columnName * @param value */ public static void addUpdateStringValue(ColumnFamilyUpdater<String,String> updater, String columnName, String value ) { if (value == null) { return; } updater.setString( columnName, value ); }
public ColumnFamilyUpdater<K, N> createUpdater() { ColumnFamilyUpdater<K, N> updater = new ColumnFamilyUpdater<K, N>(this, columnFactory); return updater; }
@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String url = tuple.getString(1); int bucket = tuple.getInteger(2); PersonID user = (PersonID) tuple.getValue(3); HColumn<Integer, byte[]> hcol = _template.querySingleColumn( url, bucket, BytesArraySerializer.get()); HyperLogLog hll; try { if(hcol==null) hll = new HyperLogLog(14); else hll = HyperLogLog.Builder.build(hcol.getValue()); hll.offer(user); ColumnFamilyUpdater<String, Integer> updater = _template.createUpdater(url); updater.setByteArray(bucket, hll.getBytes()); _template.update(updater); } catch(IOException e) { throw new RuntimeException(e); } }
public ColumnFamilyUpdater<K, N> createUpdater(K key, Mutator<K> mutator) { ColumnFamilyUpdater<K, N> updater = new ColumnFamilyUpdater<K, N>(this, columnFactory, mutator); updater.addKey(key); return updater; }