Skip to content

Commit

Permalink
Add withAppProfileId to BigtableIO Read and Write
Browse files Browse the repository at this point in the history
  • Loading branch information
iht committed Oct 6, 2023
1 parent 03741c0 commit 41b07c0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,25 @@ public Read withTableId(String tableId) {
return withTableId(StaticValueProvider.of(tableId));
}

/**
* Returns a new {@link BigtableIO.Read} that will read using the specified app profile id.
*
* <p>Does not modify this object.
*/
public Read withAppProfileId(ValueProvider<String> appProfileId) {
BigtableConfig config = getBigtableConfig();
return toBuilder().setBigtableConfig(config.withAppProfileId(appProfileId)).build();
}

/**
* Returns a new {@link BigtableIO.Read} that will read using the specified app profile id.
*
* <p>Does not modify this object.
*/
public Read withAppProfileId(String appProfileId) {
return withAppProfileId(StaticValueProvider.of(appProfileId));
}

/**
* WARNING: Should be used only to specify additional parameters for connection to the Cloud
* Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link
Expand Down Expand Up @@ -837,6 +856,31 @@ public Write withTableId(String tableId) {
return withTableId(StaticValueProvider.of(tableId));
}

/**
* Returns a new {@link BigtableIO.Write} that will write using the specified app profile id.
*
* <p>Remember that in order to use single-row transactions, this must use a single-cluster
* routing policy.
*
* <p>Does not modify this object.
*/
public Write withAppProfileId(ValueProvider<String> appProfileId) {
BigtableConfig config = getBigtableConfig();
return toBuilder().setBigtableConfig(config.withAppProfileId(appProfileId)).build();
}

/**
* Returns a new {@link BigtableIO.Write} that will write using the specified app profile id.
*
* <p>Remember that in order to use single-row transactions, this must use a single-cluster
* routing policy.
*
* <p>Does not modify this object.
*/
public Write withAppProfileId(String appProfileId) {
return withAppProfileId(StaticValueProvider.of(appProfileId));
}

/**
* WARNING: Should be used only to specify additional parameters for connection to the Cloud
* Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ public void testReadBuildsCorrectly() {
.withTableId("table")
.withInstanceId("instance")
.withProjectId("project")
.withAppProfileId("app-profile")
.withBigtableOptionsConfigurator(PORT_CONFIGURATOR);
assertEquals("options_project", read.getBigtableOptions().getProjectId());
assertEquals("options_instance", read.getBigtableOptions().getInstanceId());
assertEquals("instance", read.getBigtableConfig().getInstanceId().get());
assertEquals("project", read.getBigtableConfig().getProjectId().get());
assertEquals("app-profile", read.getBigtableConfig().getAppProfileId().get());
assertEquals("table", read.getTableId());
assertEquals(PORT_CONFIGURATOR, read.getBigtableConfig().getBigtableOptionsConfigurator());
}
Expand Down Expand Up @@ -373,12 +375,14 @@ public void testWriteBuildsCorrectly() {
.withBigtableOptions(BIGTABLE_OPTIONS)
.withTableId("table")
.withInstanceId("instance")
.withProjectId("project");
.withProjectId("project")
.withAppProfileId("app-profile");
assertEquals("table", write.getBigtableWriteOptions().getTableId().get());
assertEquals("options_project", write.getBigtableOptions().getProjectId());
assertEquals("options_instance", write.getBigtableOptions().getInstanceId());
assertEquals("instance", write.getBigtableConfig().getInstanceId().get());
assertEquals("project", write.getBigtableConfig().getProjectId().get());
assertEquals("app-profile", write.getBigtableConfig().getAppProfileId().get());
}

@Test
Expand Down

0 comments on commit 41b07c0

Please sign in to comment.