in java/dataflow-connector-examples/src/main/java/com/google/cloud/bigtable/dataflow/example/SourceRowCount.java [81:114]
public static void main(String[] args) {
CountOptions options =
PipelineOptionsFactory.fromArgs(args).withValidation().as(CountOptions.class);
String PROJECT_ID = options.getBigtableProjectId();
String INSTANCE_ID = options.getBigtableInstanceId();
String TABLE_ID = options.getBigtableTableId();
// [START bigtable_dataflow_connector_scan_config]
Scan scan = new Scan();
scan.setCacheBlocks(false);
scan.setFilter(new FirstKeyOnlyFilter());
// CloudBigtableTableConfiguration contains the project, zone, cluster and table to connect to.
// You can supply an optional Scan() to filter the rows that will be read.
CloudBigtableScanConfiguration config =
new CloudBigtableScanConfiguration.Builder()
.withProjectId(PROJECT_ID)
.withInstanceId(INSTANCE_ID)
.withTableId(TABLE_ID)
.withScan(scan)
.build();
Pipeline p = Pipeline.create(options);
p.apply(Read.from(CloudBigtableIO.read(config)))
.apply(Count.<Result>globally())
.apply(ParDo.of(stringifier))
.apply(TextIO.write().to(options.getResultLocation()));
// [END bigtable_dataflow_connector_scan_config]
p.run().waitUntilFinish();
// Once this is done, you can get the result file via "gsutil cp <resultLocation>-00000-of-00001"
}