use of com.google.cloud.bigtable.data.v2.BigtableDataClient in project java-bigtable by googleapis.
the class WriteConditionally method writeConditionally.
public static void writeConditionally(String projectId, String instanceId, String tableId) {
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
long timestamp = System.currentTimeMillis() * 1000;
String rowkey = "phone#4c410523#20190501";
Mutation mutation = Mutation.create().setCell(COLUMN_FAMILY_NAME, "os_name", timestamp, "android");
Filter filter = FILTERS.chain().filter(FILTERS.family().exactMatch(COLUMN_FAMILY_NAME)).filter(FILTERS.qualifier().exactMatch("os_build")).filter(FILTERS.value().regex("PQ2A\\..*"));
ConditionalRowMutation conditionalRowMutation = ConditionalRowMutation.create(tableId, rowkey).condition(filter).then(mutation);
boolean success = dataClient.checkAndMutateRow(conditionalRowMutation);
System.out.printf("Successfully updated row's os_name: %b", success);
} catch (Exception e) {
System.out.println("Error during WriteConditionally: \n" + e.toString());
e.printStackTrace();
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataClient in project java-bigtable by googleapis.
the class WriteSimple method writeSimple.
public static void writeSimple(String projectId, String instanceId, String tableId) {
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
long timestamp = System.currentTimeMillis() * 1000;
String rowkey = "phone#4c410523#20190501";
RowMutation rowMutation = RowMutation.create(tableId, rowkey).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_cell".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom("connected_wifi".getBytes()), timestamp, 1).setCell(COLUMN_FAMILY_NAME, "os_build", timestamp, "PQ2A.190405.003");
dataClient.mutateRow(rowMutation);
System.out.printf("Successfully wrote row %s", rowkey);
} catch (Exception e) {
System.out.println("Error during WriteSimple: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataClient in project java-bigtable by googleapis.
the class Reads method readRowRanges.
public static void readRowRanges(String projectId, String instanceId, String tableId) {
// the "close" method on the client to safely clean up any remaining background resources.
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
Query query = Query.create(tableId).range("phone#4c410523#20190501", "phone#4c410523#20190601").range("phone#5c10102#20190501", "phone#5c10102#20190601");
ServerStream<Row> rows = dataClient.readRows(query);
for (Row row : rows) {
printRow(row);
}
} catch (IOException e) {
System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataClient in project java-bigtable by googleapis.
the class Reads method readFilter.
public static void readFilter(String projectId, String instanceId, String tableId) {
Filters.Filter filter = FILTERS.value().regex("PQ2A.*");
// the "close" method on the client to safely clean up any remaining background resources.
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
Query query = Query.create(tableId).filter(filter);
ServerStream<Row> rows = dataClient.readRows(query);
for (Row row : rows) {
printRow(row);
}
} catch (IOException e) {
System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataClient in project java-bigtable by googleapis.
the class Reads method readRow.
public static void readRow(String projectId, String instanceId, String tableId) {
// the "close" method on the client to safely clean up any remaining background resources.
try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
String rowkey = "phone#4c410523#20190501";
Row row = dataClient.readRow(tableId, rowkey);
printRow(row);
} catch (IOException e) {
System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
}
}
Aggregations