arnavarora2004 commented on code in PR #35696:
URL: https://github.com/apache/beam/pull/35696#discussion_r2240475538
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableReadSchemaTransformProvider.java:
##########
@@ -152,45 +165,87 @@ public PCollectionRowTuple expand(PCollectionRowTuple
input) {
.withInstanceId(configuration.getInstanceId())
.withProjectId(configuration.getProjectId()));
+ Schema outputSchema =
+ Boolean.FALSE.equals(configuration.getFlatten()) ? ROW_SCHEMA :
FLATTENED_ROW_SCHEMA;
+
PCollection<Row> beamRows =
- bigtableRows.apply(MapElements.via(new
BigtableRowToBeamRow())).setRowSchema(ROW_SCHEMA);
+ bigtableRows
+ .apply("ConvertToBeamRows", ParDo.of(new
BigtableRowConverterDoFn(configuration)))
+ .setRowSchema(outputSchema);
return PCollectionRowTuple.of(OUTPUT_TAG, beamRows);
}
}
- public static class BigtableRowToBeamRow extends
SimpleFunction<com.google.bigtable.v2.Row, Row> {
- @Override
- public Row apply(com.google.bigtable.v2.Row bigtableRow) {
- // The collection of families is represented as a Map of column families.
- // Each column family is represented as a Map of columns.
- // Each column is represented as a List of cells
- // Each cell is represented as a Beam Row consisting of value and
timestamp_micros
- Map<String, Map<String, List<Row>>> families = new HashMap<>();
-
- for (Family fam : bigtableRow.getFamiliesList()) {
- // Map of column qualifier to list of cells
- Map<String, List<Row>> columns = new HashMap<>();
- for (Column col : fam.getColumnsList()) {
- List<Row> cells = new ArrayList<>();
- for (Cell cell : col.getCellsList()) {
- Row cellRow =
- Row.withSchema(CELL_SCHEMA)
- .withFieldValue("value",
ByteBuffer.wrap(cell.getValue().toByteArray()))
- .withFieldValue("timestamp_micros",
cell.getTimestampMicros())
+ /**
+ * A {@link DoFn} that converts a Bigtable {@link
com.google.bigtable.v2.Row} to a Beam {@link
+ * Row}. It supports both a nested representation and a flattened
representation where each column
+ * becomes a separate output element.
+ */
+ private static class BigtableRowConverterDoFn extends
DoFn<com.google.bigtable.v2.Row, Row> {
+ private final BigtableReadSchemaTransformConfiguration configuration;
+
+ BigtableRowConverterDoFn(BigtableReadSchemaTransformConfiguration
configuration) {
+ this.configuration = configuration;
+ }
+
+ @ProcessElement
+ public void processElement(
+ @Element com.google.bigtable.v2.Row bigtableRow, OutputReceiver<Row>
out) {
Review Comment:
implemented,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]