Skip to content

Commit

Permalink
SDC-12486. Avoid BigQuery.getTable(TableId) throw a NullPointerExcept…
Browse files Browse the repository at this point in the history
…ion when TableId contains an empty name

BigQuery.getTable(tableId) throws a NullPointerException when called with a tableId with an empty name (empty, not null). This is a bug in the Google client implementation. This workaround intends to prevent our software to crash in this case and to show a warning to the user instead while sending their record to error.

Change-Id: Ifbdc01242d54ed4ccb077431b8cb6d993b88a90d
Reviewed-on: https://review.streamsets.net/c/25791
Tested-by: StreamSets CI <streamsets-ci-spam@streamsets.com>
Reviewed-by: Xavier Baqués <xavi@streamsets.com>
  • Loading branch information
srgrr committed Sep 17, 2019
1 parent d2737a5 commit ee35154
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,25 @@ public void write(Batch batch) throws StageException {
String datasetName = dataSetEval.eval(elVars, conf.datasetEL, String.class);
String tableName = tableNameELEval.eval(elVars, conf.tableNameEL, String.class);
TableId tableId = TableId.of(datasetName, tableName);
if (tableIdExistsCache.get(tableId)) {

// BigQuery.getTable(tableId) throws a NullPointerException if the table name is empty
// This has been reported to Google and they marked it as a bug in their issue tracker
// Send the record to error and show a more friendly message instead
if(tableName.isEmpty()) {
getContext().toError(record, Errors.BIGQUERY_18);
}
else if(!tableIdExistsCache.get(tableId)) {
getContext().toError(record, Errors.BIGQUERY_17, datasetName, tableName, conf.credentials.projectId);
}
else {
List<Record> tableIdRecords = tableIdToRecords.computeIfAbsent(tableId, t -> new ArrayList<>());
tableIdRecords.add(record);
} else {
getContext().toError(record, Errors.BIGQUERY_17, datasetName, tableName, conf.credentials.projectId);
}
} catch (ELEvalException e) {
LOG.error("Error evaluating DataSet/TableName EL", e);
getContext().toError(record, Errors.BIGQUERY_10, e);
} catch (ExecutionException e){
LOG.error("Error when checking exists for tableId, Reason : {}", e);
LOG.error("Error when checking exists for tableId, Reason : {}", e.getMessage(), e);
Throwable rootCause = Throwables.getRootCause(e);
getContext().toError(record, Errors.BIGQUERY_13, rootCause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum Errors implements ErrorCode {
BIGQUERY_15("Error evaluated Row Id, value evaluates to empty"),
BIGQUERY_16("Root field of record should be a Map or a List Map"),
BIGQUERY_17("Data set '{}' or Table '{}' does not exist in Big Query under project '{}'"),
BIGQUERY_18("Table name is empty or table expression refers to an empty or non-existing field"),
;

private final String msg;
Expand Down

0 comments on commit ee35154

Please sign in to comment.