mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes("0")), writeToWal)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(bytes("FOO")), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); m.value = ByteBuffer.wrap(bytes("-1")); mutations.add(m); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes(Integer.toString(i))), writeToWal)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:sqr")), ByteBuffer.wrap(bytes(Integer.toString(i * i))), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
mutations.add(new Mutation(false, ByteBuffer.wrap(COLUMN2), ByteBuffer.wrap(VALUE), true)); client.mutateRow(ByteBuffer.wrap(TABLE), ByteBuffer.wrap(ROW), // co ThriftExample-4-Row Insert a test row. mutations, null);
mutations.add(new Mutation(false, ByteBuffer.wrap(COLUMN2), ByteBuffer.wrap(VALUE), true)); client.mutateRow(ByteBuffer.wrap(TABLE), ByteBuffer.wrap(ROW), mutations, null);
mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(invalid), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(bytes("foo")), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(valid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(invalid), mutations, dummyAttributes); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); client.deleteAllRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes("0")), writeToWal)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:foo")), ByteBuffer.wrap(bytes("FOO")), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); m.value = ByteBuffer.wrap(bytes("-1")); mutations.add(m); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:num")), ByteBuffer.wrap(bytes(Integer.toString(i))), writeToWal)); mutations.add(new Mutation(false, ByteBuffer.wrap(bytes("entry:sqr")), ByteBuffer.wrap(bytes(Integer.toString(i * i))), writeToWal)); client.mutateRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), mutations, dummyAttributes); printRow(client.getRow(ByteBuffer.wrap(t), ByteBuffer.wrap(row), dummyAttributes));
private void addOrUpdateRow(String tableName, Row row, List<Mutation> mutations) { int size=0; if (row!=null) { for (Column c: row.getColumns()) { size+=(c.getValue().length); } } try { synchronized (mutex) { client.mutateRow(ByteBuffer.wrap(tableName.getBytes()), ByteBuffer.wrap(row.getId()), mutations, Collections.<ByteBuffer, ByteBuffer> emptyMap()); } } catch (IOError e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } catch (IllegalArgument e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } catch (TException e) { log.error("Problem with row : "+((row==null || row.getId()==null)?"null" :new String(row.getId()))+" size : "+ size); throw new ModifyTableException(e); } }
@Test(timeout = TestConstants.ITEST_TIMEOUT) public void test() throws Exception { ArrayList<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>(); ColumnDescriptor cd = new ColumnDescriptor(); cd.name = FAMILY1; columns.add(cd); cd = new ColumnDescriptor(); cd.name = FAMILY2; columns.add(cd); Hbase.Client client = controller.getThriftClient(); client.createTable(TABLE, columns); ArrayList<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(new Mutation(false, COLUMN, VALUE, true)); client.mutateRow(TABLE, ROW, mutations, null); int scan1 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY1), null); List<TRowResult> rows = client.scannerGet(scan1); assertThat(rows.size(), is(1)); assertThat(Bytes.toString(rows.get(0).getRow()), is("testRow")); assertTrue("No more rows", client.scannerGet(scan1).isEmpty()); client.scannerClose(scan1); int scan2 = client.scannerOpen(TABLE, FIRST, Lists.newArrayList(FAMILY2), null); assertTrue("No more rows", client.scannerGet(scan2).isEmpty()); client.scannerClose(scan2); }