You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "Dippatel98 (via GitHub)" <gi...@apache.org> on 2023/04/26 17:22:32 UTC

[GitHub] [beam] Dippatel98 commented on a diff in pull request #26286: Added dlq and error metrics to pubsublite read schema transform

Dippatel98 commented on code in PR #26286:
URL: https://github.com/apache/beam/pull/26286#discussion_r1178186879


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsublite/PubsubLiteReadSchemaTransformProvider.java:
##########
@@ -59,12 +68,52 @@
   public static final Set<String> VALID_DATA_FORMATS =
       Sets.newHashSet(VALID_FORMATS_STR.split(","));
 
+  public static final TupleTag<Row> OUTPUT_TAG = new TupleTag<Row>() {};
+  public static final TupleTag<Row> ERROR_TAG = new TupleTag<Row>() {};
+  public static final Schema ERROR_SCHEMA =
+      Schema.builder().addStringField("error").addNullableByteArrayField("row").build();
+
   @Override
   protected @UnknownKeyFor @NonNull @Initialized Class<PubsubLiteReadSchemaTransformConfiguration>
       configurationClass() {
     return PubsubLiteReadSchemaTransformConfiguration.class;
   }
 
+  public static class ErrorFn extends DoFn<SequencedMessage, Row> {
+    private SerializableFunction<byte[], Row> valueMapper;
+    private Counter errorCounter;
+    private Long errorsInBundle = 0L;
+
+    public ErrorFn(String name, SerializableFunction<byte[], Row> valueMapper) {
+      this.errorCounter = Metrics.counter(PubsubLiteReadSchemaTransformProvider.class, name);
+      this.valueMapper = valueMapper;
+    }
+
+    @ProcessElement
+    public void process(@DoFn.Element SequencedMessage seqMessage, MultiOutputReceiver receiver) {
+      try {
+        receiver
+            .get(OUTPUT_TAG)
+            .output(valueMapper.apply(seqMessage.getMessage().getData().toByteArray()));
+      } catch (Exception e) {
+        errorsInBundle += 1;
+        System.out.println("Error while parsing the element" + e.toString());

Review Comment:
   Done



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org