Search code examples
javascalahbasebigtablegoogle-cloud-bigtable

BigtableConfiguration v BigtableOptions when running Bigtable emulator


I have some working code. It uses a BigtableConfiguration object to return to get a connection to Bigtable, like so:

var connection = BigtableConfiguration.connect("myProject", "myCluster")

The connection returned is of type com.google.cloud.bigtable.hbase.Connection.

I understand that there is now a Bigtable emulator for use locally and I wish to use it in my tests. So I'm trying to understand how to leverage it.

It seems that in order to take advantage of auto-configuration based on the emulator env var, you need to use another config-type class called BigtableOptions, like so:

  val options = new BigtableOptions.Builder()
    .setProjectId("myProject")
    .setInstanceId("myCluster")
    .setUserAgent("whatever")
    .build()

This class has the logic to detect the emulator. However, I can't pass it to my existing BigtableConfiguration.connect() method.

So I'm confused as to how I can use this new BigtableOptions class with my existing code. I can go down the route of using a BigtableSession object, but this means a re-write.

I want to leverage the auto-configuration promised by the emulator if the env var is set, but right now I'm considering abandoning that in favour of an answer like this one.

Thanks in advance!


Solution

  • The Cloud Bigtable 0.9.4 client should just work with the emulator if the environment variable is set. See here, in the BigtableOptions source code, for the implementation details.

    If that doesn't work for you, let's please continue the discussion on a github issue.