forked from wepay/kafka-connect-bigquery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into failed-serialize-concurrent-merge-update
- Loading branch information
Showing
28 changed files
with
1,045 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/ErrantRecordHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.wepay.kafka.connect.bigquery; | ||
|
||
import com.google.cloud.bigquery.BigQuery; | ||
import com.google.cloud.bigquery.BigQueryError; | ||
import org.apache.kafka.connect.sink.ErrantRecordReporter; | ||
import org.apache.kafka.connect.sink.SinkRecord; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ErrantRecordHandler { | ||
private static final Logger logger = LoggerFactory.getLogger(ErrantRecordHandler.class); | ||
private final ErrantRecordReporter errantRecordReporter; | ||
|
||
private static final List<String> allowedBigQueryErrorReason = Arrays.asList("invalid"); | ||
|
||
public ErrantRecordHandler(ErrantRecordReporter errantRecordReporter) { | ||
this.errantRecordReporter = errantRecordReporter; | ||
} | ||
|
||
public void sendRecordsToDLQ(Set<SinkRecord> rows, Exception e) { | ||
if(errantRecordReporter != null) { | ||
logger.debug("Sending {} records to DLQ", rows.size()); | ||
for (SinkRecord r : rows) { | ||
// Reporting records in async mode | ||
errantRecordReporter.report(r, e); | ||
} | ||
} else { | ||
logger.warn("Cannot send Records to DLQ as ErrantRecordReporter is null"); | ||
} | ||
} | ||
|
||
public ErrantRecordReporter getErrantRecordReporter() { | ||
return errantRecordReporter; | ||
} | ||
|
||
public List<String> getAllowedBigQueryErrorReason() { | ||
return allowedBigQueryErrorReason; | ||
} | ||
|
||
public boolean isErrorReasonAllowed(List<BigQueryError> bqErrorList) { | ||
for (BigQueryError bqError: bqErrorList) { | ||
boolean errorMatch = false; | ||
String bqErrorReason = bqError.getReason(); | ||
for (String allowedBqErrorReason: allowedBigQueryErrorReason) { | ||
if (bqErrorReason.equalsIgnoreCase(allowedBqErrorReason)) { | ||
errorMatch = true; | ||
break; | ||
} | ||
} | ||
if(!errorMatch) | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.