1414
1515import * as grpc from '@grpc/grpc-js' ;
1616import { GoogleError } from 'google-gax' ;
17- import { getSRKRequest } from './utils/request/sampleRowKeys' ;
1817import { ClientImplMaker , normalizeCallback } from './utils' ;
1918
2019import { google } from '../protos/protos' ;
20+ import { log } from './utils/log' ;
2121type ISampleRowKeysRequest = google . bigtable . testproxy . ISampleRowKeysRequest ;
2222type ISampleRowKeysResult = google . bigtable . testproxy . ISampleRowKeysResult ;
2323
@@ -28,25 +28,32 @@ export const sampleRowKeys: ClientImplMaker<
2828 normalizeCallback ( async rawRequest => {
2929 const { request} = rawRequest ;
3030 const { clientId, request : sampleRowKeysRequest } = request ;
31- const { appProfileId , tableName} = sampleRowKeysRequest ! ;
31+ const { tableName} = sampleRowKeysRequest ! ;
3232
3333 const bigtable = clientMap . get ( clientId ! ) ;
34- bigtable . appProfileId = appProfileId ! ;
34+
35+ const [ , , , instanceId , , tableId ] = tableName ! . split ( '/' ) ;
36+ const instance = bigtable . instance ( instanceId ) ;
37+ const table = instance . table ( tableId ) ;
3538
3639 try {
37- const response = await getSRKRequest ( bigtable , { appProfileId , tableName } ) ;
40+ const response = await table . sampleRowKeys ( ) ;
3841
42+ log . info ( 'sampleRowKeys response %o' , response ) ;
3943 return {
4044 status : { code : grpc . status . OK , details : [ ] } ,
41- response,
45+ samples : response [ 0 ] . map ( sample => ( {
46+ rowKey : sample . key ,
47+ offsetBytes : sample . offset ,
48+ } ) ) ,
4249 } ;
4350 } catch ( e ) {
4451 const error = e as GoogleError ;
45- console . error ( 'Error:' , error . code ) ;
4652
4753 return {
4854 status : {
49- code : error . code ,
55+ // This might be zero/undefined if it's a disconnected client error.
56+ code : error . code || grpc . status . FAILED_PRECONDITION ,
5057 details : [ ] ,
5158 } ,
5259 } ;
0 commit comments