Search in sources :

Example 1 with PdaoException

use of bio.terra.common.exception.PdaoException in project jade-data-repo by DataBiosphere.

the class BigQueryPdao method buildFormatOptions.

private FormatOptions buildFormatOptions(IngestRequestModel ingestRequest) {
    FormatOptions options;
    switch(ingestRequest.getFormat()) {
        case CSV:
            CsvOptions csvDefaults = FormatOptions.csv();
            options = CsvOptions.newBuilder().setFieldDelimiter(ingestRequest.getCsvFieldDelimiter() == null ? csvDefaults.getFieldDelimiter() : ingestRequest.getCsvFieldDelimiter()).setQuote(ingestRequest.getCsvQuote() == null ? csvDefaults.getQuote() : ingestRequest.getCsvQuote()).setSkipLeadingRows(ingestRequest.getCsvSkipLeadingRows() == null ? csvDefaults.getSkipLeadingRows() : ingestRequest.getCsvSkipLeadingRows()).setAllowQuotedNewLines(ingestRequest.isCsvAllowQuotedNewlines() == null ? csvDefaults.allowQuotedNewLines() : ingestRequest.isCsvAllowQuotedNewlines()).build();
            break;
        case JSON:
            options = FormatOptions.json();
            break;
        default:
            throw new PdaoException("Invalid format option: " + ingestRequest.getFormat());
    }
    return options;
}
Also used : PdaoException(bio.terra.common.exception.PdaoException) CsvOptions(com.google.cloud.bigquery.CsvOptions) FormatOptions(com.google.cloud.bigquery.FormatOptions)

Example 2 with PdaoException

use of bio.terra.common.exception.PdaoException in project jade-data-repo by DataBiosphere.

the class BigQueryPdao method createStagingLoadHistoryTable.

public void createStagingLoadHistoryTable(Dataset dataset, String tableName_FlightId) throws InterruptedException {
    BigQueryProject bigQueryProject = bigQueryProjectForDataset(dataset);
    try {
        String datasetName = prefixName(dataset.getName());
        if (bigQueryProject.tableExists(datasetName, PDAO_LOAD_HISTORY_STAGING_TABLE_PREFIX + tableName_FlightId)) {
            bigQueryProject.deleteTable(datasetName, PDAO_LOAD_HISTORY_STAGING_TABLE_PREFIX + tableName_FlightId);
        }
        bigQueryProject.createTable(datasetName, PDAO_LOAD_HISTORY_STAGING_TABLE_PREFIX + tableName_FlightId, buildLoadDatasetSchema());
    } catch (Exception ex) {
        throw new PdaoException("create staging load history table failed for " + dataset.getName(), ex);
    }
}
Also used : PdaoException(bio.terra.common.exception.PdaoException) IngestFileNotFoundException(bio.terra.service.dataset.exception.IngestFileNotFoundException) PdaoException(bio.terra.common.exception.PdaoException) MismatchedRowIdException(bio.terra.service.tabulardata.exception.MismatchedRowIdException) CorruptMetadataException(bio.terra.service.snapshot.exception.CorruptMetadataException) MismatchedValueException(bio.terra.service.snapshot.exception.MismatchedValueException) BadExternalFileException(bio.terra.service.tabulardata.exception.BadExternalFileException) InvalidQueryException(bio.terra.grammar.exception.InvalidQueryException) IngestFailureException(bio.terra.service.dataset.exception.IngestFailureException)

Example 3 with PdaoException

use of bio.terra.common.exception.PdaoException in project jade-data-repo by DataBiosphere.

the class BigQueryPdao method createSnapshotWithLiveViews.

public void createSnapshotWithLiveViews(Snapshot snapshot, Dataset dataset) throws InterruptedException {
    BigQueryProject bigQueryProject = bigQueryProjectForSnapshot(snapshot);
    String projectId = bigQueryProject.getProjectId();
    String snapshotName = snapshot.getName();
    BigQuery bigQuery = bigQueryProject.getBigQuery();
    String datasetBqDatasetName = prefixName(dataset.getName());
    // create snapshot BQ dataset
    snapshotCreateBQDataset(bigQueryProject, snapshot);
    // create the row id table (row id col and table id col)
    bigQueryProject.createTable(snapshotName, PDAO_ROW_ID_TABLE, rowIdTableSchema());
    // get source dataset table live views
    List<DatasetTable> tables = dataset.getTables();
    // create a snapshot table based on the live view data row ids
    String liveViewTables = createSnaphotTableFromLiveViews(bigQueryProject, tables, datasetBqDatasetName);
    ST sqlTemplate = new ST(insertAllLiveViewDataTemplate);
    sqlTemplate.add("project", projectId);
    sqlTemplate.add("snapshot", snapshotName);
    sqlTemplate.add("dataRepoTable", PDAO_ROW_ID_TABLE);
    sqlTemplate.add("dataRepoTableId", PDAO_TABLE_ID_COLUMN);
    sqlTemplate.add("dataRepoRowId", PDAO_ROW_ID_COLUMN);
    sqlTemplate.add("liveViewTables", liveViewTables);
    bigQueryProject.query(sqlTemplate.render());
    ST sqlValidateSnapshotTemplate = new ST(validateSnapshotSizeTemplate);
    sqlValidateSnapshotTemplate.add("project", projectId);
    sqlValidateSnapshotTemplate.add("snapshot", snapshotName);
    sqlValidateSnapshotTemplate.add("dataRepoTable", PDAO_ROW_ID_TABLE);
    TableResult result = bigQueryProject.query(sqlValidateSnapshotTemplate.render());
    if (result.getTotalRows() <= 0) {
        throw new PdaoException("This snapshot is empty");
    }
    snapshotViewCreation(datasetBqDatasetName, snapshotName, snapshot, projectId, bigQuery, bigQueryProject);
}
Also used : ST(org.stringtemplate.v4.ST) BigQuery(com.google.cloud.bigquery.BigQuery) TableResult(com.google.cloud.bigquery.TableResult) PdaoException(bio.terra.common.exception.PdaoException) DatasetTable(bio.terra.service.dataset.DatasetTable)

Example 4 with PdaoException

use of bio.terra.common.exception.PdaoException in project jade-data-repo by DataBiosphere.

the class BigQueryProject method datasetExists.

// TODO: REVIEWERS PLEASE CHECK: Should these methods be in here? On the one hand, it is convenient. But it
// mixes the duties of this class: it is supplying both the cache and the BQ methods. Unfortunately, it
// doesn't supply all of the BQ methods, so sometimes getBigQuery is needed. Seems like it could be
// improved.
// 
// In general, BigQueryPdao is too big and needs refactoring. Perhaps when that is done, we can also
// re-think this code structure.
public boolean datasetExists(String datasetName) {
    try {
        DatasetId datasetId = DatasetId.of(projectId, datasetName);
        Dataset dataset = bigQuery.getDataset(datasetId);
        return (dataset != null);
    } catch (Exception ex) {
        throw new PdaoException("existence check failed for " + datasetName, ex);
    }
}
Also used : PdaoException(bio.terra.common.exception.PdaoException) Dataset(com.google.cloud.bigquery.Dataset) BigQueryException(com.google.cloud.bigquery.BigQueryException) PdaoException(bio.terra.common.exception.PdaoException) DatasetId(com.google.cloud.bigquery.DatasetId)

Example 5 with PdaoException

use of bio.terra.common.exception.PdaoException in project jade-data-repo by DataBiosphere.

the class BigQueryProject method tableExists.

public boolean tableExists(String datasetName, String tableName) {
    try {
        TableId tableId = TableId.of(projectId, datasetName, tableName);
        Table table = bigQuery.getTable(tableId);
        return (table != null);
    } catch (Exception ex) {
        throw new PdaoException("existence check failed for " + datasetName + "." + tableName, ex);
    }
}
Also used : TableId(com.google.cloud.bigquery.TableId) Table(com.google.cloud.bigquery.Table) PdaoException(bio.terra.common.exception.PdaoException) BigQueryException(com.google.cloud.bigquery.BigQueryException) PdaoException(bio.terra.common.exception.PdaoException)

Aggregations

PdaoException (bio.terra.common.exception.PdaoException)14 BigQuery (com.google.cloud.bigquery.BigQuery)6 DatasetTable (bio.terra.service.dataset.DatasetTable)5 TableResult (com.google.cloud.bigquery.TableResult)5 BigQueryException (com.google.cloud.bigquery.BigQueryException)4 FieldValueList (com.google.cloud.bigquery.FieldValueList)4 ST (org.stringtemplate.v4.ST)4 Table (bio.terra.common.Table)3 InvalidQueryException (bio.terra.grammar.exception.InvalidQueryException)3 AssetTable (bio.terra.service.dataset.AssetTable)3 IngestFailureException (bio.terra.service.dataset.exception.IngestFailureException)3 IngestFileNotFoundException (bio.terra.service.dataset.exception.IngestFileNotFoundException)3 SnapshotMapTable (bio.terra.service.snapshot.SnapshotMapTable)3 SnapshotTable (bio.terra.service.snapshot.SnapshotTable)3 CorruptMetadataException (bio.terra.service.snapshot.exception.CorruptMetadataException)3 MismatchedValueException (bio.terra.service.snapshot.exception.MismatchedValueException)3 BigQueryError (com.google.cloud.bigquery.BigQueryError)3 FieldValue (com.google.cloud.bigquery.FieldValue)3 Dataset (bio.terra.service.dataset.Dataset)2 IamRole (bio.terra.service.iam.IamRole)2