Java Code Examples for org.apache.hadoop.hbase.client.BufferedMutator#mutate()
The following examples show how to use
org.apache.hadoop.hbase.client.BufferedMutator#mutate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Data2HBase1.java From BigData with GNU General Public License v3.0 | 6 votes |
/** * 利用BufferedMutator批量导入 * * @param connection * @throws IOException */ private static void bmImport(Connection connection) throws IOException { BufferedMutator bufferedMutator = connection.getBufferedMutator(TableName.valueOf("t3")); byte[] columnFamily = "f1".getBytes(); long startTime = System.currentTimeMillis(); ArrayList<Put> puts = new ArrayList<Put>(); for (int i = 0; i < 999999; i++) { puts.add(HBaseUtil.createPut(i + "", columnFamily, "c1", i + "")); //每10000条导入一次 if (i % 10000 == 0) { bufferedMutator.mutate(puts); puts.clear(); } } //批量调用 bufferedMutator.mutate(puts); bufferedMutator.close(); System.out.println("共耗时:" + (System.currentTimeMillis() - startTime) + "ms"); }
Example 2
Source File: MultiTableOutputFormat.java From hbase with Apache License 2.0 | 6 votes |
/** * Writes an action (Put or Delete) to the specified table. * * @param tableName * the table being updated. * @param action * the update, either a put or a delete. * @throws IllegalArgumentException * if the action is not a put or a delete. */ @Override public void write(ImmutableBytesWritable tableName, Mutation action) throws IOException { BufferedMutator mutator = getBufferedMutator(tableName); // The actions are not immutable, so we defensively copy them if (action instanceof Put) { Put put = new Put((Put) action); put.setDurability(useWriteAheadLogging ? Durability.SYNC_WAL : Durability.SKIP_WAL); mutator.mutate(put); } else if (action instanceof Delete) { Delete delete = new Delete((Delete) action); mutator.mutate(delete); } else throw new IllegalArgumentException( "action must be either Delete or Put"); }
Example 3
Source File: IntegrationTestSendTraceRequests.java From hbase with Apache License 2.0 | 6 votes |
private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException { LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<>(25000); BufferedMutator ht = util.getConnection().getBufferedMutator(this.tableName); byte[] value = new byte[300]; TraceUtil.addSampler(Sampler.ALWAYS); for (int x = 0; x < 5000; x++) { try (TraceScope traceScope = TraceUtil.createTrace("insertData")) { for (int i = 0; i < 5; i++) { long rk = random.nextLong(); rowKeys.add(rk); Put p = new Put(Bytes.toBytes(rk)); for (int y = 0; y < 10; y++) { random.nextBytes(value); p.addColumn(familyName, Bytes.toBytes(random.nextLong()), value); } ht.mutate(p); } if ((x % 1000) == 0) { admin.flush(tableName); } } } admin.flush(tableName); return rowKeys; }
Example 4
Source File: HBaseIndex.java From hudi with Apache License 2.0 | 5 votes |
/** * Helper method to facilitate performing mutations (including puts and deletes) in Hbase. */ private void doMutations(BufferedMutator mutator, List<Mutation> mutations) throws IOException { if (mutations.isEmpty()) { return; } mutator.mutate(mutations); mutator.flush(); mutations.clear(); sleepForTime(SLEEP_TIME_MILLISECONDS); }
Example 5
Source File: HBaseIOTest.java From beam with Apache License 2.0 | 5 votes |
/** Helper function to create a table and return the rows that it created. */ private static void writeData(String tableId, int numRows) throws Exception { Connection connection = admin.getConnection(); TableName tableName = TableName.valueOf(tableId); BufferedMutator mutator = connection.getBufferedMutator(tableName); List<Mutation> mutations = makeTableData(numRows); mutator.mutate(mutations); mutator.flush(); mutator.close(); }
Example 6
Source File: TestExpiredMobFileCleaner.java From hbase with Apache License 2.0 | 5 votes |
private void putKVAndFlush(BufferedMutator table, byte[] row, byte[] value, long ts) throws Exception { Put put = new Put(row, ts); put.addColumn(Bytes.toBytes(family), qf, value); table.mutate(put); table.flush(); admin.flush(tableName); }
Example 7
Source File: WritePerfTest.java From cloud-bigtable-examples with Apache License 2.0 | 4 votes |
protected static void doPut(BufferedMutator mutator, byte[] value) throws IOException { byte[] key = Bytes.toBytes(RandomStringUtils.randomAlphanumeric(10)); mutator.mutate(new Put(key, System.currentTimeMillis()).addColumn(BigtableUtilities.FAMILY, BigtableUtilities.QUALIFIER, value)); }