Polber commented on code in PR #29261:
URL: https://github.com/apache/beam/pull/29261#discussion_r1379607512


##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaWriteSchemaTransformProvider.java:
##########
@@ -103,17 +107,22 @@ public static class ErrorCounterFn extends DoFn<Row, 
KV<byte[], byte[]>> {
       private SerializableFunction<Row, byte[]> toBytesFn;
       private Counter errorCounter;
       private Long errorsInBundle = 0L;
+      private final boolean failOnError;
 
-      public ErrorCounterFn(String name, SerializableFunction<Row, byte[]> 
toBytesFn) {
+      public ErrorCounterFn(String name, SerializableFunction<Row, byte[]> 
toBytesFn, boolean failOnError) {
         this.toBytesFn = toBytesFn;
-        errorCounter = 
Metrics.counter(KafkaWriteSchemaTransformProvider.class, name);
+        this.errorCounter = 
Metrics.counter(KafkaWriteSchemaTransformProvider.class, name);
+        this.failOnError = failOnError;
       }
 
       @ProcessElement
       public void process(@DoFn.Element Row row, MultiOutputReceiver receiver) 
{
         try {
           receiver.get(OUTPUT_TAG).output(KV.of(new byte[1], 
toBytesFn.apply(row)));
         } catch (Exception e) {

Review Comment:
   Done.



##########
sdks/java/io/kafka/src/main/java/org/apache/beam/sdk/io/kafka/KafkaWriteSchemaTransformProvider.java:
##########
@@ -103,17 +107,22 @@ public static class ErrorCounterFn extends DoFn<Row, 
KV<byte[], byte[]>> {
       private SerializableFunction<Row, byte[]> toBytesFn;
       private Counter errorCounter;
       private Long errorsInBundle = 0L;
+      private final boolean failOnError;
 
-      public ErrorCounterFn(String name, SerializableFunction<Row, byte[]> 
toBytesFn) {
+      public ErrorCounterFn(String name, SerializableFunction<Row, byte[]> 
toBytesFn, boolean failOnError) {
         this.toBytesFn = toBytesFn;
-        errorCounter = 
Metrics.counter(KafkaWriteSchemaTransformProvider.class, name);
+        this.errorCounter = 
Metrics.counter(KafkaWriteSchemaTransformProvider.class, name);
+        this.failOnError = failOnError;
       }
 
       @ProcessElement
       public void process(@DoFn.Element Row row, MultiOutputReceiver receiver) 
{
         try {
           receiver.get(OUTPUT_TAG).output(KV.of(new byte[1], 
toBytesFn.apply(row)));
         } catch (Exception e) {
+          if (failOnError) {
+            throw new RuntimeException(e.getMessage());
+          }
           errorsInBundle += 1;
           LOG.warn("Error while processing the element", e);
           receiver

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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to