client = session.getDataClient(); } catch (IOException e) { throw new DBException("Error loading options from config: ", e); client = session.getDataClient();
@Override public AsyncTableRegionLocator getRegionLocator(TableName tableName) { return new BigtableAsyncTableRegionLocator(tableName, options, this.session.getDataClient()); }
@Override public AsyncTableRegionLocator getRegionLocator(TableName tableName) { return new BigtableAsyncTableRegionLocator(tableName, options, this.session.getDataClient()); }
/** {@inheritDoc} */ @Override public RegionLocator getRegionLocator(TableName tableName) throws IOException { RegionLocator locator = getCachedLocator(tableName); if (locator == null) { locator = new BigtableRegionLocator(tableName, getOptions(), getSession().getDataClient()) { @Override public SampledRowKeysAdapter getSampledRowKeysAdapter(TableName tableName, ServerName serverName) { return createSampledRowKeysAdapter(tableName, serverName); } }; locatorCache.add(locator); } return locator; }
/** {@inheritDoc} */ @Override public RegionLocator getRegionLocator(TableName tableName) throws IOException { RegionLocator locator = getCachedLocator(tableName); if (locator == null) { locator = new BigtableRegionLocator(tableName, getOptions(), getSession().getDataClient()) { @Override public SampledRowKeysAdapter getSampledRowKeysAdapter(TableName tableName, ServerName serverName) { return createSampledRowKeysAdapter(tableName, serverName); } }; locatorCache.add(locator); } return locator; }
@Override public List<HRegionInfo> getAllRegionInfos(TableName tableName) throws IOException { ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); SampleRowKeysRequest.Builder request = SampleRowKeysRequest.newBuilder(); request.setTableName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())); List<SampleRowKeysResponse> sampleRowKeyResponse = this.session.getDataClient().sampleRowKeys(request.build()); return getSampledRowKeysAdapter(tableName, serverName).adaptResponse(sampleRowKeyResponse) .stream() .map(location -> location.getRegionInfo()) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); }
@Override public List<HRegionInfo> getAllRegionInfos(TableName tableName) throws IOException { ServerName serverName = ServerName.valueOf(options.getDataHost(), options.getPort(), 0); SampleRowKeysRequest.Builder request = SampleRowKeysRequest.newBuilder(); request.setTableName(options.getInstanceName().toTableNameStr(tableName.getNameAsString())); List<SampleRowKeysResponse> sampleRowKeyResponse = this.session.getDataClient().sampleRowKeys(request.build()); return getSampledRowKeysAdapter(tableName, serverName).adaptResponse(sampleRowKeyResponse) .stream() .map(location -> location.getRegionInfo()) .collect(Collectors.toCollection(CopyOnWriteArrayList::new)); }
@Before public void setup() { MockitoAnnotations.initMocks(this); BigtableOptions options = new BigtableOptions.Builder().setProjectId("project").setInstanceId("instance").build(); when(mockSession.getOptions()).thenReturn(options); when(mockSession.createBulkMutation(eq(TABLE_NAME))).thenReturn(mockBulkMutation); when(mockSession.getDataClient()).thenReturn(mockBigtableDataClient); }
public BigtableAsyncTable(BigtableAsyncConnection asyncConnection, HBaseRequestAdapter hbaseAdapter) { this.asyncConnection = asyncConnection; BigtableSession session = asyncConnection.getSession(); this.client = new BigtableDataClient(session.getDataClient()); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); // Once the IBigtableDataClient interface is implemented this will be removed this.requestContext = RequestContext.create(hbaseAdapter.getBigtableTableName().toGcbInstanceName(), ""); }
public BigtableAsyncTable(BigtableAsyncConnection asyncConnection, HBaseRequestAdapter hbaseAdapter) { this.asyncConnection = asyncConnection; BigtableSession session = asyncConnection.getSession(); this.client = new BigtableDataClient(session.getDataClient()); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); // Once the IBigtableDataClient interface is implemented this will be removed this.requestContext = RequestContext.create(hbaseAdapter.getBigtableTableName().toGcbInstanceName(), ""); }
@Override public List<SampleRowKeysResponse> getSampleRowKeys(BigtableSource source) throws IOException { try (BigtableSession session = new BigtableSession(options)) { SampleRowKeysRequest request = SampleRowKeysRequest.newBuilder() .setTableName(options.getInstanceName().toTableNameStr(source.getTableId().get())) .build(); return session.getDataClient().sampleRowKeys(request); } } }
/** * Constructed by BigtableConnection * * @param bigtableConnection a {@link org.apache.hadoop.hbase.client.AbstractBigtableConnection} object. * @param hbaseAdapter a {@link com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter} object. */ public AbstractBigtableTable(AbstractBigtableConnection bigtableConnection, HBaseRequestAdapter hbaseAdapter) { this.bigtableConnection = bigtableConnection; BigtableSession session = bigtableConnection.getSession(); this.options = session.getOptions(); this.client = session.getDataClient(); this.clientWrapper = session.getClientWrapper(); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); this.requestContext = RequestContext.create( InstanceName.of(options.getProjectId(), options.getInstanceId()), options.getAppProfileId()); }
/** * Constructed by BigtableConnection * * @param bigtableConnection a {@link org.apache.hadoop.hbase.client.AbstractBigtableConnection} object. * @param hbaseAdapter a {@link com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter} object. */ public AbstractBigtableTable(AbstractBigtableConnection bigtableConnection, HBaseRequestAdapter hbaseAdapter) { this.bigtableConnection = bigtableConnection; BigtableSession session = bigtableConnection.getSession(); this.options = session.getOptions(); this.client = session.getDataClient(); this.clientWrapper = session.getClientWrapper(); this.hbaseAdapter = hbaseAdapter; this.tableName = hbaseAdapter.getTableName(); this.requestContext = RequestContext.create( InstanceName.of(options.getProjectId(), options.getInstanceId()), options.getAppProfileId()); }
@Override public boolean start() throws IOException { RowSet.Builder rowSetBuilder = RowSet.newBuilder(); for (ByteKeyRange sourceRange : source.getRanges()) { rowSetBuilder = rowSetBuilder.addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFrom(sourceRange.getStartKey().getValue())) .setEndKeyOpen(ByteString.copyFrom(sourceRange.getEndKey().getValue()))); } RowSet rowSet = rowSetBuilder.build(); String tableNameSr = session.getOptions().getInstanceName().toTableNameStr(source.getTableId().get()); ReadRowsRequest.Builder requestB = ReadRowsRequest.newBuilder().setRows(rowSet).setTableName(tableNameSr); if (source.getRowFilter() != null) { requestB.setFilter(source.getRowFilter()); } results = session.getDataClient().readRows(requestB.build()); return advance(); }
/** Helper function to get a table's data. */ private List<KV<ByteString, ByteString>> getTableData(String tableName) throws IOException { // Add empty range to avoid TARGET_NOT_SET error RowRange range = RowRange.newBuilder() .setStartKeyClosed(ByteString.EMPTY) .setEndKeyOpen(ByteString.EMPTY) .build(); RowSet rowSet = RowSet.newBuilder().addRowRanges(range).build(); ReadRowsRequest.Builder readRowsRequestBuilder = ReadRowsRequest.newBuilder().setTableName(tableName).setRows(rowSet); ResultScanner<Row> scanner = session.getDataClient().readRows(readRowsRequestBuilder.build()); Row currentRow; List<KV<ByteString, ByteString>> tableData = new ArrayList<>(); while ((currentRow = scanner.next()) != null) { ByteString key = currentRow.getKey(); ByteString value = currentRow.getFamilies(0).getColumns(0).getCells(0).getValue(); tableData.add(KV.of(key, value)); } scanner.close(); return tableData; }