use of bio.terra.model.SnapshotRequestRowIdModel in project jade-data-repo by DataBiosphere.
the class BigQueryPdao method createSnapshotWithProvidedIds.
public void createSnapshotWithProvidedIds(Snapshot snapshot, SnapshotRequestContentsModel contentsModel) throws InterruptedException {
BigQueryProject bigQueryProject = bigQueryProjectForSnapshot(snapshot);
String projectId = bigQueryProject.getProjectId();
String snapshotName = snapshot.getName();
BigQuery bigQuery = bigQueryProject.getBigQuery();
SnapshotRequestRowIdModel rowIdModel = contentsModel.getRowIdSpec();
// create snapshot BQ dataset
snapshotCreateBQDataset(bigQueryProject, snapshot);
// create the row id table
bigQueryProject.createTable(snapshotName, PDAO_ROW_ID_TABLE, rowIdTableSchema());
// populate root row ids. Must happen before the relationship walk.
// NOTE: when we have multiple sources, we can put this into a loop
SnapshotSource source = snapshot.getSnapshotSources().get(0);
String datasetBqDatasetName = prefixName(source.getDataset().getName());
for (SnapshotRequestRowIdTableModel table : rowIdModel.getTables()) {
String tableName = table.getTableName();
Table sourceTable = source.reverseTableLookup(tableName).orElseThrow(() -> new CorruptMetadataException("cannot find destination table: " + tableName));
List<String> rowIds = table.getRowIds();
if (rowIds.size() > 0) {
ST sqlTemplate = new ST(loadRootRowIdsTemplate);
sqlTemplate.add("project", projectId);
sqlTemplate.add("snapshot", snapshotName);
sqlTemplate.add("dataset", datasetBqDatasetName);
sqlTemplate.add("tableId", sourceTable.getId().toString());
sqlTemplate.add("rowIds", rowIds);
bigQueryProject.query(sqlTemplate.render());
}
ST sqlTemplate = new ST(validateRowIdsForRootTemplate);
sqlTemplate.add("project", projectId);
sqlTemplate.add("snapshot", snapshotName);
sqlTemplate.add("dataset", datasetBqDatasetName);
sqlTemplate.add("table", sourceTable.getName());
TableResult result = bigQueryProject.query(sqlTemplate.render());
FieldValueList row = result.iterateAll().iterator().next();
FieldValue countValue = row.get(0);
if (countValue.getLongValue() != rowIds.size()) {
logger.error("Invalid row ids supplied: rowIds=" + rowIds.size() + " count=" + countValue.getLongValue());
for (String rowId : rowIds) {
logger.error(" rowIdIn: " + rowId);
}
throw new PdaoException("Invalid row ids supplied");
}
}
snapshotViewCreation(datasetBqDatasetName, snapshotName, snapshot, projectId, bigQuery, bigQueryProject);
}
use of bio.terra.model.SnapshotRequestRowIdModel in project jade-data-repo by DataBiosphere.
the class SnapshotValidationTest method testSnapshotRowIdsEmptyRowIds.
@Test
public void testSnapshotRowIdsEmptyRowIds() throws Exception {
SnapshotRequestRowIdModel rowIdSpec = snapshotByRowIdsRequestModel.getContents().get(0).getRowIdSpec();
rowIdSpec.getTables().get(0).setRowIds(Collections.emptyList());
expectBadSnapshotCreateRequest(snapshotByRowIdsRequestModel);
}
Aggregations