org.apache.hadoop.hbase.client.Row Java Examples
The following examples show how to use
org.apache.hadoop.hbase.client.Row.
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: SimpleHbaseEventSerializer.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public List<Row> getActions() throws FlumeException { List<Row> actions = new LinkedList<Row>(); if(plCol != null){ byte[] rowKey; try { if (keyType == KeyType.TS) { rowKey = SimpleRowKeyGenerator.getTimestampKey(rowPrefix); } else if(keyType == KeyType.RANDOM) { rowKey = SimpleRowKeyGenerator.getRandomKey(rowPrefix); } else if(keyType == KeyType.TSNANO) { rowKey = SimpleRowKeyGenerator.getNanoTimestampKey(rowPrefix); } else { rowKey = SimpleRowKeyGenerator.getUUIDKey(rowPrefix); } Put put = new Put(rowKey); put.add(cf, plCol, payload); actions.add(put); } catch (Exception e){ throw new FlumeException("Could not get row key!", e); } } return actions; }
Example #2
Source File: BasicFraudHBaseService.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
public void logInProfileInHBase(long userId, String ipAddress) throws IOException, Exception { HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE); ArrayList<Row> actions = new ArrayList<Row>(); byte[] profileRowKey = generateProfileRowKey(userId); Delete delete = new Delete(profileRowKey); delete.deleteColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL); delete.deleteColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL); actions.add(delete); Increment increment = new Increment(profileRowKey); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL, 1); actions.add(increment); Put put = new Put(profileRowKey); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL, Bytes.toBytes(System.currentTimeMillis())); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(ipAddress)); actions.add(put); profileTable.batch(actions); }
Example #3
Source File: AbstractHBaseConnectionHelper.java From datacollector with Apache License 2.0 | 6 votes |
public static void handleHBaseException( RetriesExhaustedWithDetailsException rex, Record record, Map<String, Record> rowKeyToRecord, ErrorRecordHandler errorRecordHandler ) throws StageException { for (int i = 0; i < rex.getNumExceptions(); i++) { if (rex.getCause(i) instanceof NoSuchColumnFamilyException) { Row r = rex.getRow(i); Record errorRecord = record != null ? record : rowKeyToRecord.get(Bytes.toString(r.getRow())); OnRecordErrorException exception = new OnRecordErrorException(errorRecord, Errors.HBASE_10, getErrorDescription(rex.getCause(i), r, rex.getHostnamePort(i)) ); errorRecordHandler.onError(exception); } else { // If at least 1 non NoSuchColumnFamilyException exception, // consider as stage exception throw new StageException(Errors.HBASE_02, rex); } } }
Example #4
Source File: TestWALEntrySinkFilter.java From hbase with Apache License 2.0 | 6 votes |
@Override public AsyncTable<AdvancedScanResultConsumer> getTable(TableName tableName) { return new DummyAsyncTable<AdvancedScanResultConsumer>() { @Override public <T> CompletableFuture<List<T>> batchAll(List<? extends Row> actions) { List<T> list = new ArrayList<>(actions.size()); for (Row action : actions) { // Row is the index of the loop above where we make WALEntry and Cells. int row = Bytes.toInt(action.getRow()); assertTrue("" + row, row > BOUNDARY); UNFILTERED.incrementAndGet(); list.add(null); } return CompletableFuture.completedFuture(list); } }; }
Example #5
Source File: MockHTable.java From metron with Apache License 2.0 | 6 votes |
/** * @param actions * @deprecated */ @Deprecated @Override public Object[] batch(List<? extends Row> actions) throws IOException, InterruptedException { List<Result> results = new ArrayList<Result>(); for (Row r : actions) { if (r instanceof Delete) { delete((Delete) r); continue; } if (r instanceof Put) { put((Put) r); continue; } if (r instanceof Get) { results.add(get((Get) r)); } } return results.toArray(); }
Example #6
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private List<? extends Row> transactionalizeActions(List<? extends Row> actions) throws IOException { List<Row> transactionalizedActions = new ArrayList<>(actions.size()); for (Row action : actions) { if (action instanceof Get) { transactionalizedActions.add(transactionalizeAction((Get) action)); } else if (action instanceof Put) { transactionalizedActions.add(transactionalizeAction((Put) action)); } else if (action instanceof Delete) { transactionalizedActions.add(transactionalizeAction((Delete) action)); } else { transactionalizedActions.add(action); } } return transactionalizedActions; }
Example #7
Source File: TTable.java From phoenix-omid with Apache License 2.0 | 6 votes |
/** * Transactional version of {@link Table#batch(List<? extends Row> rows)} * * @param transaction an instance of transaction to be used * @param rows List of rows that must be instances of Put or Delete * @param addShadowCell denotes whether to add the shadow cell * @throws IOException if a remote or network exception occurs */ public void batch(Transaction transaction, List<? extends Row> rows, boolean addShadowCells) throws IOException { List<Mutation> mutations = new ArrayList<>(rows.size()); for (Row row : rows) { if (row instanceof Put) { mutations.add(putInternal(transaction, (Put)row, addShadowCells)); } else if (row instanceof Delete) { Put deleteP = deleteInternal(transaction, (Delete)row); if (!deleteP.isEmpty()) { mutations.add(deleteP); } } else { throw new UnsupportedOperationException("Unsupported mutation: " + row); } } addMutations(mutations); }
Example #8
Source File: BasicFraudHBaseService.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
public void updateProfileCountsForSaleInHBase(Long buyerId, Long sellerId, ItemSaleEvent event) throws IOException, InterruptedException { HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE); ArrayList<Row> actions = new ArrayList<Row>(); Increment buyerValueIncrement = new Increment(generateProfileRowKey(buyerId)); buyerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL, event.getItemValue()); buyerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, event.getItemValue()); actions.add(buyerValueIncrement); Increment sellerValueIncrement = new Increment(generateProfileRowKey(sellerId)); sellerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL, event.getItemValue()); sellerValueIncrement.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, event.getItemValue()); actions.add(sellerValueIncrement); profileTable.batch(actions); }
Example #9
Source File: BasicFraudHBaseService.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
@Override public void createProfile(long userId, ProfilePojo pojo, String ipAddress) throws Exception { HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE); ArrayList<Row> actions = new ArrayList<Row>(); byte[] rowKey = generateProfileRowKey(userId); Put put = new Put(rowKey); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL, Bytes.toBytes(pojo.getUsername() + "|" + pojo.getAge() + "|" + System.currentTimeMillis())); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(ipAddress)); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL, Bytes.toBytes(System.currentTimeMillis())); actions.add(put); Increment increment = new Increment(rowKey); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL, 1); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL, 0); actions.add(increment); profileTable.batch(actions); }
Example #10
Source File: ReplicationSink.java From hbase with Apache License 2.0 | 6 votes |
/** * Do the changes and handle the pool * @param tableName table to insert into * @param allRows list of actions */ private void batch(TableName tableName, Collection<List<Row>> allRows) throws IOException { if (allRows.isEmpty()) { return; } AsyncTable<?> table = getConnection().getTable(tableName); List<Future<?>> futures = allRows.stream().map(table::batchAll).collect(Collectors.toList()); for (Future<?> future : futures) { try { FutureUtils.get(future); } catch (RetriesExhaustedException e) { if (e.getCause() instanceof TableNotFoundException) { throw new TableNotFoundException("'" + tableName + "'"); } throw e; } } }
Example #11
Source File: TestIncrementTimeRange.java From hbase with Apache License 2.0 | 5 votes |
private void checkHTableInterfaceMethods() throws Exception { long time = EnvironmentEdgeManager.currentTime(); mee.setValue(time); hTableInterface.put(new Put(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, Bytes.toBytes(1L))); checkRowValue(ROW_A, Bytes.toBytes(1L)); time = EnvironmentEdgeManager.currentTime(); mee.setValue(time); TimeRange range10 = new TimeRange(1, time+10); hTableInterface.increment(new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 10L) .setTimeRange(range10.getMin(), range10.getMax())); checkRowValue(ROW_A, Bytes.toBytes(11L)); assertEquals(MyObserver.tr10.getMin(), range10.getMin()); assertEquals(MyObserver.tr10.getMax(), range10.getMax()); time = EnvironmentEdgeManager.currentTime(); mee.setValue(time); TimeRange range2 = new TimeRange(1, time+20); List<Row> actions = Arrays.asList(new Row[] { new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()), new Increment(ROW_A).addColumn(TEST_FAMILY, qualifierCol1, 2L) .setTimeRange(range2.getMin(), range2.getMax()) }); Object[] results3 = new Object[actions.size()]; Object[] results1 = results3; hTableInterface.batch(actions, results1); assertEquals(MyObserver.tr2.getMin(), range2.getMin()); assertEquals(MyObserver.tr2.getMax(), range2.getMax()); for (Object r2 : results1) { assertTrue(r2 instanceof Result); } checkRowValue(ROW_A, Bytes.toBytes(15L)); hTableInterface.close(); }
Example #12
Source File: TestIncrementAndAppendWithNullResult.java From hbase with Apache License 2.0 | 5 votes |
private void testAppend(Append append) throws Exception { checkResult(table.append(append)); List<Row> actions = Arrays.asList(append, append); Object[] results = new Object[actions.size()]; table.batch(actions, results); checkResult(results); }
Example #13
Source File: TestIncrementAndAppendWithNullResult.java From hbase with Apache License 2.0 | 5 votes |
private void testAppend(Increment inc) throws Exception { checkResult(table.increment(inc)); List<Row> actions = Arrays.asList(inc, inc); Object[] results = new Object[actions.size()]; table.batch(actions, results); checkResult(results); }
Example #14
Source File: HBaseSink.java From mt-flume with Apache License 2.0 | 5 votes |
@Override public Status process() throws EventDeliveryException { Status status = Status.READY; Channel channel = getChannel(); Transaction txn = channel.getTransaction(); List<Row> actions = new LinkedList<Row>(); List<Increment> incs = new LinkedList<Increment>(); txn.begin(); long i = 0; for(; i < batchSize; i++) { Event event = channel.take(); if(event == null){ status = Status.BACKOFF; if (i == 0) { sinkCounter.incrementBatchEmptyCount(); } else { sinkCounter.incrementBatchUnderflowCount(); } break; } else { serializer.initialize(event, columnFamily); actions.addAll(serializer.getActions()); incs.addAll(serializer.getIncrements()); } } if (i == batchSize) { sinkCounter.incrementBatchCompleteCount(); } sinkCounter.addToEventDrainAttemptCount(i); putEventsAndCommit(actions, incs, txn); return status; }
Example #15
Source File: BasicFraudHBaseService.java From hadoop-arch-book with Apache License 2.0 | 5 votes |
@Override public void createBulkProfile(ArrayList<ProfileCreatePojo> pojoList) throws Exception { HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE); ArrayList<Row> actions = new ArrayList<Row>(); for (ProfileCreatePojo pojo: pojoList) { byte[] rowKey = generateProfileRowKey(pojo.getUserId()); Put put = new Put(rowKey); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL, Bytes.toBytes(pojo.getPojo().getUsername() + "|" + pojo.getPojo().getAge() + "|" + System.currentTimeMillis())); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES, Bytes.toBytes(pojo.getIpAddress())); put.add(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL, Bytes.toBytes(System.currentTimeMillis())); actions.add(put); Increment increment = new Increment(rowKey); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL, 1); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL, 0); increment.addColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL, 0); actions.add(increment); } profileTable.batch(actions); }
Example #16
Source File: MetaTableMetrics.java From hbase with Apache License 2.0 | 5 votes |
private void opMetricRegisterAndMark(Row op) { // Mark access type ["get", "put", "delete"] metric String opMeterName = opMeterName(op); if (opMeterName == null || opMeterName.isEmpty()) { return; } registerAndMarkMeter(opMeterName); }
Example #17
Source File: MetaTableMetrics.java From hbase with Apache License 2.0 | 5 votes |
private void tableMetricRegisterAndMark(Row op) { // Mark table metric String tableName = getTableNameFromOp(op); if (tableName == null || tableName.isEmpty()) { return; } String tableRequestMeter = tableMeterName(tableName); registerAndMarkMeter(tableRequestMeter); }
Example #18
Source File: ThriftTable.java From hbase with Apache License 2.0 | 5 votes |
@Override public void batch(List<? extends Row> actions, Object[] results) throws IOException { throw new IOException("Batch not supported in ThriftTable, use put(List<Put> puts), " + "get(List<Get> gets) or delete(List<Delete> deletes) respectively"); }
Example #19
Source File: DynamicColumnIT.java From phoenix with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private static void initTableValues() throws Exception { ConnectionQueryServices services = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)); HTableInterface hTable = services.getTable(SchemaUtil.getTableNameAsBytes(HBASE_DYNAMIC_COLUMNS_SCHEMA_NAME,HBASE_DYNAMIC_COLUMNS)); try { // Insert rows using standard HBase mechanism with standard HBase "types" List<Row> mutations = new ArrayList<Row>(); byte[] dv = Bytes.toBytes("DV"); byte[] first = Bytes.toBytes("F"); byte[] f1v1 = Bytes.toBytes("F1V1"); byte[] f1v2 = Bytes.toBytes("F1V2"); byte[] f2v1 = Bytes.toBytes("F2V1"); byte[] f2v2 = Bytes.toBytes("F2V2"); byte[] key = Bytes.toBytes("entry1"); Put put = new Put(key); put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, dv, Bytes.toBytes("default")); put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, first, Bytes.toBytes("first")); put.add(FAMILY_NAME, f1v1, Bytes.toBytes("f1value1")); put.add(FAMILY_NAME, f1v2, Bytes.toBytes("f1value2")); put.add(FAMILY_NAME2, f2v1, Bytes.toBytes("f2value1")); put.add(FAMILY_NAME2, f2v2, Bytes.toBytes("f2value2")); mutations.add(put); hTable.batch(mutations); } finally { hTable.close(); } // Create Phoenix table after HBase table was created through the native APIs // The timestamp of the table creation must be later than the timestamp of the data ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS); }
Example #20
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void batch(List<? extends Row> actions, Object[] results) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } hTable.batch(transactionalizeActions(actions), results); }
Example #21
Source File: MetaTableMetrics.java From hbase with Apache License 2.0 | 5 votes |
/** * Get regionId from Ops such as: get, put, delete. * @param op such as get, put or delete. */ private String getRegionIdFromOp(Row op) { final String tableRowKey = Bytes.toString(op.getRow()); if (StringUtils.isEmpty(tableRowKey)) { return null; } final String[] splits = tableRowKey.split(","); return splits.length > 2 ? splits[2] : null; }
Example #22
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> Object[] batchCallback(List<? extends Row> actions, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } return hTable.batchCallback(transactionalizeActions(actions), callback); }
Example #23
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> void batchCallback(List<? extends Row> actions, Object[] results, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } hTable.batchCallback(transactionalizeActions(actions), results, callback); }
Example #24
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public Object[] batch(List<? extends Row> actions) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } return hTable.batch(transactionalizeActions(actions)); }
Example #25
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> Object[] batchCallback(List<? extends Row> actions, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } return hTable.batchCallback(transactionalizeActions(actions), callback); }
Example #26
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public Object[] batch(List<? extends Row> actions) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } return hTable.batch(transactionalizeActions(actions)); }
Example #27
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
private List<? extends Row> transactionalizeActions(List<? extends Row> actions) throws IOException { List<Row> transactionalizedActions = new ArrayList<>(actions.size()); for (Row action : actions) { if (action instanceof Get) { transactionalizedActions.add(transactionalizeAction((Get) action)); } else if (action instanceof Put) { transactionalizedActions.add(transactionalizeAction((Put) action)); } else if (action instanceof Delete) { transactionalizedActions.add(transactionalizeAction((Delete) action)); } else { transactionalizedActions.add(action); } } return transactionalizedActions; }
Example #28
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> Object[] batchCallback(List<? extends Row> actions, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } return hTable.batchCallback(transactionalizeActions(actions), callback); }
Example #29
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> void batchCallback(List<? extends Row> actions, Object[] results, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } hTable.batchCallback(transactionalizeActions(actions), results, callback); }
Example #30
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public <R> void batchCallback(List<? extends Row> actions, Object[] results, Batch.Callback<R> callback) throws IOException, InterruptedException { if (tx == null) { throw new IOException("Transaction not started"); } hTable.batchCallback(transactionalizeActions(actions), results, callback); }