From 61895b918d17f44301c0d19a10a6500a0b8e953a Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Fri, 1 Nov 2024 18:34:10 -0400 Subject: [PATCH] extract all table related request params extractors Change-Id: I22910ebd8024eecf623fee595596fa53e4ec59f5 --- .../data/v2/stub/EnhancedBigtableStub.java | 85 +++---------------- 1 file changed, 12 insertions(+), 73 deletions(-) diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java index 2b2ca38540..7dcc8dc318 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java @@ -603,22 +603,9 @@ private ServerStreamingCallable createReadRo GrpcCallSettings.newBuilder() .setMethodDescriptor(BigtableGrpc.getReadRowsMethod()) .setParamsExtractor( - new RequestParamsExtractor() { - @Override - public Map extract(ReadRowsRequest readRowsRequest) { - String tableName = readRowsRequest.getTableName(); - String authorizedViewName = readRowsRequest.getAuthorizedViewName(); - if (tableName.isEmpty()) { - tableName = - NameUtil.extractTableNameFromAuthorizedViewName(authorizedViewName); - } - return ImmutableMap.of( - "table_name", - tableName, - "app_profile_id", - readRowsRequest.getAppProfileId()); - } - }) + r -> + composeRequestParams( + r.getAppProfileId(), r.getTableName(), r.getAuthorizedViewName())) .build(), readRowsSettings.getRetryableCodes()); @@ -742,25 +729,9 @@ public ApiFuture> futureCall(String s, ApiCallContext apiCallCon newBuilder() .setMethodDescriptor(BigtableGrpc.getSampleRowKeysMethod()) .setParamsExtractor( - new RequestParamsExtractor() { - @Override - public Map extract( - com.google.bigtable.v2.SampleRowKeysRequest sampleRowKeysRequest) { - String tableName = sampleRowKeysRequest.getTableName(); - String authorizedViewName = - sampleRowKeysRequest.getAuthorizedViewName(); - if (tableName.isEmpty()) { - tableName = - NameUtil.extractTableNameFromAuthorizedViewName( - authorizedViewName); - } - return ImmutableMap.of( - "table_name", - tableName, - "app_profile_id", - sampleRowKeysRequest.getAppProfileId()); - } - }) + r -> + composeRequestParams( + r.getAppProfileId(), r.getTableName(), r.getAuthorizedViewName())) .build(), settings.sampleRowKeysSettings().getRetryableCodes()); @@ -823,22 +794,9 @@ private UnaryCallable createMutateRowsBas GrpcCallSettings.newBuilder() .setMethodDescriptor(BigtableGrpc.getMutateRowsMethod()) .setParamsExtractor( - new RequestParamsExtractor() { - @Override - public Map extract(MutateRowsRequest mutateRowsRequest) { - String tableName = mutateRowsRequest.getTableName(); - String authorizedViewName = mutateRowsRequest.getAuthorizedViewName(); - if (tableName.isEmpty()) { - tableName = - NameUtil.extractTableNameFromAuthorizedViewName(authorizedViewName); - } - return ImmutableMap.of( - "table_name", - tableName, - "app_profile_id", - mutateRowsRequest.getAppProfileId()); - } - }) + r -> + composeRequestParams( + r.getAppProfileId(), r.getTableName(), r.getAuthorizedViewName())) .build(), settings.bulkMutateRowsSettings().getRetryableCodes()); @@ -1075,18 +1033,7 @@ private UnaryCallable createReadModifyWriteRowCallable( .setMethodDescriptor( BigtableGrpc.getGenerateInitialChangeStreamPartitionsMethod()) .setParamsExtractor( - new RequestParamsExtractor() { - @Override - public Map extract( - GenerateInitialChangeStreamPartitionsRequest - generateInitialChangeStreamPartitionsRequest) { - return ImmutableMap.of( - "table_name", - generateInitialChangeStreamPartitionsRequest.getTableName(), - "app_profile_id", - generateInitialChangeStreamPartitionsRequest.getAppProfileId()); - } - }) + r -> composeRequestParams(r.getAppProfileId(), r.getTableName(), "")) .build(), settings.generateInitialChangeStreamPartitionsSettings().getRetryableCodes()); @@ -1155,15 +1102,7 @@ public Map extract( GrpcCallSettings.newBuilder() .setMethodDescriptor(BigtableGrpc.getReadChangeStreamMethod()) .setParamsExtractor( - new RequestParamsExtractor() { - @Override - public Map extract( - ReadChangeStreamRequest readChangeStreamRequest) { - return ImmutableMap.of( - "table_name", readChangeStreamRequest.getTableName(), - "app_profile_id", readChangeStreamRequest.getAppProfileId()); - } - }) + r -> composeRequestParams(r.getAppProfileId(), r.getTableName(), "")) .build(), settings.readChangeStreamSettings().getRetryableCodes()); @@ -1313,7 +1252,7 @@ private UnaryCallable createUserFacin private Map composeRequestParams( String appProfileId, String tableName, String authorizedViewName) { - if (tableName.isEmpty()) { + if (tableName.isEmpty() && !authorizedViewName.isEmpty()) { tableName = NameUtil.extractTableNameFromAuthorizedViewName(authorizedViewName); } return ImmutableMap.of("table_name", tableName, "app_profile_id", appProfileId);