@Override @Nullable public byte[] get(byte[] row, byte[] column) { try { byte[] distributedKey = createDistributedRowKey(row); Get get = tableUtil.buildGet(distributedKey) .addColumn(columnFamily, column) .setMaxVersions(1) .build(); Result getResult = hTable.get(get); if (!getResult.isEmpty()) { return getResult.getValue(columnFamily, column); } return null; } catch (IOException e) { throw new DataSetException("Get failed on table " + tableId, e); } }
@Override @Nullable public byte[] get(byte[] row, byte[] column) { try { byte[] distributedKey = createDistributedRowKey(row); Get get = tableUtil.buildGet(distributedKey) .addColumn(columnFamily, column) .setMaxVersions(1) .build(); Result getResult = hTable.get(get); if (!getResult.isEmpty()) { return getResult.getValue(columnFamily, column); } return null; } catch (IOException e) { throw new DataSetException("Get failed on table " + tableId, e); } }
/** * Creates an {@link Get} for the specified row and columns. * * @param row the rowkey for the Get * @param columns the columns to fetch. null means to retrieve all columns. * @throws IllegalArgumentException if columns has length 0. */ private Get createGet(byte[] row, @Nullable byte[][] columns) { Preconditions.checkArgument(columns == null || columns.length != 0); GetBuilder get = tableUtil.buildGet(row); get.addFamily(columnFamily); if (columns != null) { for (byte[] column : columns) { get.addColumn(columnFamily, column); } } else { get.addFamily(columnFamily); } try { // no tx logic needed if (tx == null) { get.setMaxVersions(1); } else { get.setAttribute(TxConstants.TX_OPERATION_ATTRIBUTE_KEY, getEncodedTx()); } } catch (IOException ioe) { throw Throwables.propagate(ioe); } return get.build(); }
/** * Creates an {@link Get} for the specified row and columns. * * @param row the rowkey for the Get * @param columns the columns to fetch. null means to retrieve all columns. * @throws IllegalArgumentException if columns has length 0. */ private Get createGet(byte[] row, @Nullable byte[][] columns) { Preconditions.checkArgument(columns == null || columns.length != 0); GetBuilder get = tableUtil.buildGet(row); get.addFamily(columnFamily); if (columns != null) { for (byte[] column : columns) { get.addColumn(columnFamily, column); } } else { get.addFamily(columnFamily); } try { // no tx logic needed if (tx == null) { get.setMaxVersions(1); } else { get.setAttribute(TxConstants.TX_OPERATION_ATTRIBUTE_KEY, getEncodedTx()); } } catch (IOException ioe) { throw Throwables.propagate(ioe); } return get.build(); }