Skip to content

Commit

Permalink
Added check for sheet files.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasrathee-cs committed Nov 19, 2024
1 parent fbbac79 commit 363f490
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/main/java/io/cdap/plugin/google/common/APIRequestRetryer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public <V> void onRetry(Attempt<V> attempt) {
GoogleJsonResponseException e = (GoogleJsonResponseException) exceptionCause;
LOG.warn(String.format(
"Error code: '%d', message: '%s'. Attempt: '%d'. Delay since first: '%d'. Description: '%s'.",
e.getDetails().getCode(),
getExceptionStatusCode(e),
e.getStatusMessage(),
attempt.getAttemptNumber(),
attempt.getDelaySinceFirstAttempt(),
Expand Down Expand Up @@ -125,21 +125,26 @@ private static boolean checkHttpResponseException(Throwable t) {

private static boolean isTooManyRequestsError(GoogleJsonResponseException e) {
List<String> possibleMessages = Arrays.asList(TOO_MANY_REQUESTS_MESSAGE, LIMIT_RATE_EXCEEDED_MESSAGE);
return e.getDetails().getCode() == TOO_MANY_REQUESTS_CODE && possibleMessages.contains(e.getStatusMessage());
return getExceptionStatusCode(e) == TOO_MANY_REQUESTS_CODE && possibleMessages.contains(
e.getStatusMessage());
}

private static boolean isRateLimitError(GoogleJsonResponseException e) {
return e.getDetails().getCode() == LIMIT_RATE_EXCEEDED_CODE
return getExceptionStatusCode(e) == LIMIT_RATE_EXCEEDED_CODE
&& (LIMIT_RATE_EXCEEDED_MESSAGE.equals(e.getStatusMessage())
|| e.getDetails().getMessage().contains(LIMIT_RATE_EXCEEDED_MESSAGE));
}

private static boolean isBackendError(GoogleJsonResponseException e) {
return e.getDetails().getCode() == BACKEND_ERROR_CODE;
return getExceptionStatusCode(e) == BACKEND_ERROR_CODE;
}

private static boolean isServiceUnavailableError(GoogleJsonResponseException e) {
return e.getDetails().getCode() == SERVICE_UNAVAILABLE_CODE;
return getExceptionStatusCode(e) == SERVICE_UNAVAILABLE_CODE;
}

private static Integer getExceptionStatusCode(GoogleJsonResponseException e) {
return e.getDetails() != null ? e.getDetails().getCode() : null;
}

private static boolean isRateLimitError(HttpResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ public List<File> getFilesSummary(List<ExportedType> exportedTypes, int filesNum
int retrievedFiles = 0;
int actualFilesNumber = filesNumber;
if (IdentifierType.FILE_IDENTIFIER.equals(config.getIdentifierType())) {
files.add(service.files().get(config.getFileIdentifier()).setSupportsAllDrives(true).execute());
File file = service.files().get(config.getFileIdentifier()).setSupportsAllDrives(true).execute();
// size will be 1 in case of Sheets plugin with export type as SPREADSHEETS.
if (exportedTypes.size() == 1 && exportedTypes.contains(ExportedType.SPREADSHEETS) && !file.getMimeType()
.equalsIgnoreCase(DRIVE_SPREADSHEETS_MIME)) {
throw new ExecutionException(
String.format("File with id: '%s' has a MIME_TYPE '%s' and is not a Google Sheets File.",
file.getMimeType(),
config.getFileIdentifier()), null);
}
files.add(file);
return files;
}
Drive.Files.List request = service.files().list()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static StructuredRecord transform(RowRecord rowRecord, Schema schema, boo
builder.set(metadataRecordName, rowRecord.getMetadata());
} else {
ComplexSingleValueColumn complexSingleValueColumn = rowRecord.getHeaderedCells().get(name);
if (complexSingleValueColumn.getData() == null && complexSingleValueColumn.getSubColumns().isEmpty()) {
if (complexSingleValueColumn == null || (complexSingleValueColumn.getData() == null
&& complexSingleValueColumn.getSubColumns().isEmpty())) {
builder.set(name, null);
} else {
processCellData(builder, field, complexSingleValueColumn);
Expand Down

0 comments on commit 363f490

Please sign in to comment.