digdag icon indicating copy to clipboard operation
digdag copied to clipboard

bq> does not support to query BigQuery table with Google Sheet external table.

Open wapa5pow opened this issue 4 years ago • 0 comments

Google BigQuery table can be created with Google Sheet as follows.

image

When querying this kind of table, bq> operator needs drive read scope: "https://www.googleapis.com/auth/drive.readonly". (https://github.com/googleapis/google-api-java-client-services/blob/master/clients/google-api-services-sheets/v4/1.30.1/com/google/api/services/sheets/v4/SheetsScopes.java#L33)

However, digdag does not request the scope in the source code. ( https://github.com/treasure-data/digdag/blob/master/digdag-standards/src/main/java/io/digdag/standards/operator/gcp/BqClient.java#L40 )

If bq> operator query to the table with sheet, the following error occurs.

{
  "location" : "xxx",
  "message" : "Error while reading table: test.test, error message: Failed to read the spreadsheet. Errors: No OAuth token with Google Drive scope was found.",
  "reason" : "invalid"
}

To fix this, import import com.google.api.services.sheets.v4.SheetsScopes;, then fix scope with the following code.

            Set<String> scopes = new HashSet<String>();
            scopes.addAll(BigqueryScopes.all());
            scopes.add(SheetsScopes.DRIVE_READONLY);
            credential = credential.createScoped(scopes);

wapa5pow avatar Jun 23 '20 12:06 wapa5pow