@Override public void run() throws Exception { remoteTable.put(new Put(Bytes.toBytes("Row"))); } });
@Override public void run() throws Exception { Put[] puts = { new Put(Bytes.toBytes("Row1")), new Put(Bytes.toBytes("Row2")) }; remoteTable.put(Arrays.asList(puts)); } });
public void run() throws Exception { Cluster cluster = new Cluster(); cluster.add(host, port); Client restClient = new Client(cluster, conf.getBoolean(Constants.REST_SSL_ENABLED, false)); try (RemoteHTable remoteTable = new RemoteHTable(restClient, conf, "example")) { // Write data to the table String rowKey = "row1"; Put p = new Put(rowKey.getBytes()); p.addColumn("family1".getBytes(), "qualifier1".getBytes(), "value1".getBytes()); remoteTable.put(p); // Get the data from the table Get g = new Get(rowKey.getBytes()); Result result = remoteTable.get(g); Preconditions.checkArgument(result != null, Bytes.toString(remoteTable.getTableName()) + " should have a row with key as " + rowKey); System.out.println("row = " + new String(result.getRow())); for (Cell cell : result.rawCells()) { System.out.print("family = " + Bytes.toString(CellUtil.cloneFamily(cell)) + "\t"); System.out.print("qualifier = " + Bytes.toString(CellUtil.cloneQualifier(cell)) + "\t"); System.out.print("value = " + Bytes.toString(CellUtil.cloneValue(cell)) + "\t"); System.out.println("timestamp = " + Long.toString(cell.getTimestamp())); } } }
/** * Test RemoteHable.Scanner.iterator method */ @Test public void testIteratorScaner() throws IOException { List<Put> puts = new ArrayList<>(4); Put put = new Put(ROW_1); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_2); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_3); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_4); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); remoteTable.put(puts); ResultScanner scanner = remoteTable.getScanner(new Scan()); Iterator<Result> iterator = scanner.iterator(); assertTrue(iterator.hasNext()); int counter = 0; while (iterator.hasNext()) { iterator.next(); counter++; } assertEquals(4, counter); }
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); remoteTable.put(puts);
@Test public void testCheckAndDelete() throws IOException { Get get = new Get(ROW_1); Result result = remoteTable.get(get); byte[] value1 = result.getValue(COLUMN_1, QUALIFIER_1); byte[] value2 = result.getValue(COLUMN_2, QUALIFIER_2); assertNotNull(value1); assertTrue(Bytes.equals(VALUE_1, value1)); assertNull(value2); assertTrue(remoteTable.exists(get)); assertEquals(1, remoteTable.existsAll(Collections.singletonList(get)).length); Delete delete = new Delete(ROW_1); remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenDelete(delete); assertFalse(remoteTable.exists(get)); Put put = new Put(ROW_1); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); remoteTable.put(put); assertTrue(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenPut(put)); assertFalse(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_2).thenPut(put)); }
put.addColumn(COLUMN_3, QUALIFIER_1, VALUE_1); put.addColumn(COLUMN_3, QUALIFIER_2, VALUE_2); remoteTable.put(put);
@Override public void run() throws Exception { remoteTable.put(new Put(Bytes.toBytes("Row"))); } });
@Override public void run() throws Exception { Put[] puts = { new Put(Bytes.toBytes("Row1")), new Put(Bytes.toBytes("Row2")) }; remoteTable.put(Arrays.asList(puts)); } });
@Override public void addOrUpdateRows(String tableName, List<Row> rows) { RemoteHTable table = null; synchronized (mutex) { table = new RemoteHTable(client, tableName); } try { table.put(convertRowsToPuts(rows)); } catch (IOException e) { throw new ModifyTableException(e); } finally { try { table.close(); } catch (IOException e) { LOGGER.warn(EXCEPTION_DURING_CLOSING_H_BASE_TABLE, e); } } }
@Override public void addOrUpdateRow(String tableName, Row row) { Put p = Row2HBasePut.translate(row); RemoteHTable table = null; synchronized (mutex) { table = new RemoteHTable(client, tableName); } try { table.put(p); } catch (IOException e) { throw new ModifyTableException(e); } finally { try { table.close(); } catch (IOException e) { LOGGER.warn(EXCEPTION_DURING_CLOSING_H_BASE_TABLE, e); } } }
public static void main(String[] args) throws IOException { RemoteHTable table = new RemoteHTable( new Client( new Cluster().add("localhost", 8080)), "test"); Person john = Person.newBuilder().setId(1234).setName("John Doe").setEmail("jdoe@example.com").addPhone( Person.PhoneNumber.newBuilder().setNumber("555-4321").setType(Person.PhoneType.HOME)).build(); byte[] row = Bytes.toBytes("row3"); table.delete(new Delete(row)); Put put = new Put(row); byte[] family = Bytes.toBytes("data"); byte[] qualifier = Bytes.toBytes("3"); byte[] value = john.toByteArray(); put.add(family, qualifier, value); table.put(put); table.close(); } }
public static void importBwmetaAndSendToHBase(String zipDirPath, String collectionName, String remoteHost, int remotePort, String remoteTable) throws IOException { RemoteHTable table = new RemoteHTable(new Client(new Cluster().add(remoteHost, remotePort)), remoteTable); ZipDirToDocumentDTOIterator zdtp = new ZipDirToDocumentDTOIterator(zipDirPath, collectionName); for (DocumentDTO doc : zdtp) { try { table.put(DocumentDTO2HBasePut.translate(doc)); } catch (IOException e) { LOGGER.error(ERROR_STRING, e); } } table.close(); } }
/** * Test RemoteHable.Scanner.iterator method */ @Test public void testIteratorScaner() throws IOException { List<Put> puts = new ArrayList<>(4); Put put = new Put(ROW_1); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_2); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_3); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); put = new Put(ROW_4); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); remoteTable.put(puts); ResultScanner scanner = remoteTable.getScanner(new Scan()); Iterator<Result> iterator = scanner.iterator(); assertTrue(iterator.hasNext()); int counter = 0; while (iterator.hasNext()) { iterator.next(); counter++; } assertEquals(4, counter); }
public static void importBwmetaAndSendToHBase(String zipDirPath, String remoteHost, int remotePort, String remoteTable, String collectionName) throws IOException { RemoteHTable table = new RemoteHTable( new Client( new Cluster().add(remoteHost, remotePort)), remoteTable); Iterable<DocumentDTO> zdtp = new PdfZipDirToDocumentDTOIterable(zipDirPath, collectionName); for (DocumentDTO doc : zdtp) { try { table.put(DocumentDTO2HBasePut.translate(doc)); } catch (IOException e) { LOGGER.error(ERROR_STRING, e); } } table.close(); } }
public static void importBwmetaAndSendToHBase(String dirPath, String remoteHost, int remotePort, String remoteTable, String collectionName) throws IOException { RemoteHTable table = new RemoteHTable( new Client( new Cluster().add(remoteHost, remotePort)), remoteTable); Iterable<DocumentDTO> zdtp; if (collectionName != null) { zdtp = new OAIPMHDirToDocumentDTOIterator(dirPath, collectionName); } else { zdtp = new OAIPMHDirToDocumentDTOIterator(dirPath); } for (DocumentDTO doc : zdtp) { try { table.put(DocumentDTO2HBasePut.translate(doc)); } catch (IOException e) { LOGGER.error(ERROR_STRING, e); } } table.close(); } }
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); puts.add(put); remoteTable.put(puts);
@Test public void testCheckAndDelete() throws IOException { Get get = new Get(ROW_1); Result result = remoteTable.get(get); byte[] value1 = result.getValue(COLUMN_1, QUALIFIER_1); byte[] value2 = result.getValue(COLUMN_2, QUALIFIER_2); assertNotNull(value1); assertTrue(Bytes.equals(VALUE_1, value1)); assertNull(value2); assertTrue(remoteTable.exists(get)); assertEquals(1, remoteTable.existsAll(Collections.singletonList(get)).length); Delete delete = new Delete(ROW_1); remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenDelete(delete); assertFalse(remoteTable.exists(get)); Put put = new Put(ROW_1); put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1); remoteTable.put(put); assertTrue(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenPut(put)); assertFalse(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1) .ifEquals(VALUE_2).thenPut(put)); }