/** * 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(); }
@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); } }
@ReadOnly @Nullable @Override public byte[] get(byte[] key) { try { Result result = table.get(tableUtil.buildGet(key).build()); return result.isEmpty() ? null : result.getValue(DATA_COLUMN_FAMILY, DEFAULT_COLUMN); } catch (IOException e) { throw Throwables.propagate(e); } }
@Override public TopicMetadata getMetadata(TopicId topicId) throws IOException, TopicNotFoundException { Get get = tableUtil.buildGet(MessagingUtils.toMetadataRowKey(topicId)) .addFamily(columnFamily) .build(); try { Result result = hTable.get(get); byte[] value = result.getValue(columnFamily, COL); if (value == null) { throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic()); } Map<String, String> properties = GSON.fromJson(Bytes.toString(value), MAP_TYPE); TopicMetadata topicMetadata = new TopicMetadata(topicId, properties); if (!topicMetadata.exists()) { throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic()); } return topicMetadata; } catch (IOException e) { throw exceptionHandler.handle(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); } }
@ReadOnly @Nullable @Override public byte[] get(byte[] key) { try { Result result = table.get(tableUtil.buildGet(key).build()); return result.isEmpty() ? null : result.getValue(DATA_COLUMN_FAMILY, DEFAULT_COLUMN); } catch (IOException e) { throw Throwables.propagate(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(); }
@Override public TopicMetadata getMetadata(TopicId topicId) throws IOException, TopicNotFoundException { Get get = tableUtil.buildGet(MessagingUtils.toMetadataRowKey(topicId)) .addFamily(columnFamily) .build(); try { Result result = hTable.get(get); byte[] value = result.getValue(columnFamily, COL); if (value == null) { throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic()); } Map<String, String> properties = GSON.fromJson(Bytes.toString(value), MAP_TYPE); TopicMetadata topicMetadata = new TopicMetadata(topicId, properties); if (!topicMetadata.exists()) { throw new TopicNotFoundException(topicId.getNamespace(), topicId.getTopic()); } return topicMetadata; } catch (IOException e) { throw exceptionHandler.handle(e); } }
table.delete(delete); Get get = tableUtil.buildGet(row1).build(); Result result = table.get(get); LOG.info("Get after delete returned " + result); get = tableUtil.buildGet(row1).build(); result = table.get(get); LOG.info("Get after delete returned " + result); table.delete(delete); get = tableUtil.buildGet(row1).build(); result = table.get(get); LOG.info("Get after delete returned " + result);