arnavarora2004 commented on code in PR #35696:
URL: https://github.com/apache/beam/pull/35696#discussion_r2237695749


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableReadSchemaTransformProvider.java:
##########
@@ -152,45 +165,123 @@ 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())
+  // old logic for reference
+  //  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())
+  //                    .build();
+  //            cells.add(cellRow);
+  //          }
+  //          columns.put(col.getQualifier().toStringUtf8(), cells);
+  //        }
+  //        families.put(fam.getName(), columns);
+  //      }
+  //      Row beamRow =
+  //          Row.withSchema(ROW_SCHEMA)
+  //              .withFieldValue("key", 
ByteBuffer.wrap(bigtableRow.getKey().toByteArray()))
+  //              .withFieldValue("column_families", families)
+  //              .build();
+  //      return beamRow;
+  //    }
+  //  }

Review Comment:
   yup,



-- 
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]

Reply via email to