Search in sources :

Example 1 with MismatchedRowIdException

use of bio.terra.service.tabulardata.exception.MismatchedRowIdException in project jade-data-repo by DataBiosphere.

the class BigQueryPdao method validateDeleteRequest.

/**
 * Goes through each of the provided tables and checks to see if the proposed row ids to soft delete exist in the
 * raw dataset table. This will error out on the first sign of mismatch.
 *
 * @param dataset dataset repo concept object
 * @param tables list of table specs from the DataDeletionRequest
 * @param suffix a string added onto the end of the external table to prevent collisions
 */
public void validateDeleteRequest(Dataset dataset, List<DataDeletionTableModel> tables, String suffix) throws InterruptedException {
    BigQueryProject bigQueryProject = bigQueryProjectForDataset(dataset);
    for (DataDeletionTableModel table : tables) {
        String tableName = table.getTableName();
        String rawTableName = dataset.getTableByName(tableName).get().getRawTableName();
        String sql = new ST(validateSoftDeleteTemplate).add("rowId", PDAO_ROW_ID_COLUMN).add("project", bigQueryProject.getProjectId()).add("dataset", prefixName(dataset.getName())).add("softDeleteExtTable", externalTableName(tableName, suffix)).add("rawTable", rawTableName).render();
        TableResult result = bigQueryProject.query(sql);
        long numMismatched = getSingleLongValue(result);
        // shortcut out early, no use wasting more compute
        if (numMismatched > 0) {
            throw new MismatchedRowIdException(String.format("Could not match %s row ids for table %s", numMismatched, tableName));
        }
    }
}
Also used : ST(org.stringtemplate.v4.ST) TableResult(com.google.cloud.bigquery.TableResult) MismatchedRowIdException(bio.terra.service.tabulardata.exception.MismatchedRowIdException) DataDeletionTableModel(bio.terra.model.DataDeletionTableModel)

Aggregations

DataDeletionTableModel (bio.terra.model.DataDeletionTableModel)1 MismatchedRowIdException (bio.terra.service.tabulardata.exception.MismatchedRowIdException)1 TableResult (com.google.cloud.bigquery.TableResult)1 ST (org.stringtemplate.v4.ST)1