use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotValidationTest method makeSnapshotRowIdsRequest.
// Generate a valid snapshot-by-rowId request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotRowIdsRequest() {
SnapshotRequestRowIdTableModel snapshotRequestTableModel = new SnapshotRequestRowIdTableModel().tableName("snapshot").columns(Arrays.asList("col1", "col2", "col3")).rowIds(Arrays.asList("row1", "row2", "row3"));
SnapshotRequestRowIdModel rowIdSpec = new SnapshotRequestRowIdModel().tables(Collections.singletonList(snapshotRequestTableModel));
SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYROWID).rowIdSpec(rowIdSpec);
return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotValidationTest method makeSnapshotByQueryRequest.
// Generate a valid snapshot-by-query request, we will tweak individual pieces to test validation below
public SnapshotRequestModel makeSnapshotByQueryRequest() {
SnapshotRequestQueryModel querySpec = new SnapshotRequestQueryModel().assetName("asset").query("SELECT * FROM dataset");
SnapshotRequestContentsModel snapshotRequestContentsModel = new SnapshotRequestContentsModel().datasetName("dataset").mode(SnapshotRequestContentsModel.ModeEnum.BYQUERY).querySpec(querySpec);
return new SnapshotRequestModel().contents(Collections.singletonList(snapshotRequestContentsModel));
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotValidationTest method testSnapshotByQuery.
@Test
public void testSnapshotByQuery() throws Exception {
SnapshotRequestModel querySpec = this.snapshotByQueryRequestModel;
querySpec.getContents().get(0).getQuerySpec().setQuery(null);
expectBadSnapshotCreateRequest(snapshotByQueryRequestModel);
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotTest method snapshotRowIdsHappyPathTest.
@Test
public void snapshotRowIdsHappyPathTest() throws Exception {
// fetch rowIds from the ingested dataset by querying the participant table
DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
String datasetProject = dataset.getDataProject();
String bqDatasetName = PdaoConstant.PDAO_PREFIX + dataset.getName();
String participantTable = "participant";
String sampleTable = "sample";
BigQuery bigQuery = BigQueryFixtures.getBigQuery(dataset.getDataProject(), stewardToken);
String sql = String.format("SELECT %s FROM `%s.%s.%s`", PdaoConstant.PDAO_ROW_ID_COLUMN, datasetProject, bqDatasetName, participantTable);
TableResult participantIds = BigQueryFixtures.query(sql, bigQuery);
List<String> participantIdList = StreamSupport.stream(participantIds.getValues().spliterator(), false).map(v -> v.get(0).getStringValue()).collect(Collectors.toList());
sql = String.format("SELECT %s FROM `%s.%s.%s`", PdaoConstant.PDAO_ROW_ID_COLUMN, datasetProject, bqDatasetName, sampleTable);
TableResult sampleIds = BigQueryFixtures.query(sql, bigQuery);
List<String> sampleIdList = StreamSupport.stream(sampleIds.getValues().spliterator(), false).map(v -> v.get(0).getStringValue()).collect(Collectors.toList());
// swap in these row ids in the request
SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-row-ids-test.json", SnapshotRequestModel.class);
requestModel.getContents().get(0).getRowIdSpec().getTables().get(0).setRowIds(participantIdList);
requestModel.getContents().get(0).getRowIdSpec().getTables().get(1).setRowIds(sampleIdList);
SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshotWithRequest(steward(), dataset.getName(), requestModel);
TimeUnit.SECONDS.sleep(10);
createdSnapshotIds.add(snapshotSummary.getId());
SnapshotModel snapshot = dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId());
assertEquals("new snapshot has been created", snapshot.getName(), requestModel.getName());
assertEquals("new snapshot has the correct number of tables", requestModel.getContents().get(0).getRowIdSpec().getTables().size(), snapshot.getTables().size());
// TODO: get the snapshot and make sure the number of rows matches with the row ids input
assertThat("one relationship comes through", snapshot.getRelationships().size(), equalTo(1));
assertThat("the right relationship comes through", snapshot.getRelationships().get(0).getName(), equalTo("sample_participants"));
}
use of bio.terra.model.SnapshotRequestModel in project jade-data-repo by DataBiosphere.
the class SnapshotTest method snapshotByQueryHappyPathTest.
@Test
public void snapshotByQueryHappyPathTest() throws Exception {
DatasetModel dataset = dataRepoFixtures.getDataset(steward(), datasetId);
String datasetName = dataset.getName();
SnapshotRequestModel requestModel = jsonLoader.loadObject("ingest-test-snapshot-query.json", SnapshotRequestModel.class);
// swap in the correct dataset name (with the id at the end)
requestModel.getContents().get(0).setDatasetName(datasetName);
requestModel.getContents().get(0).getQuerySpec().setQuery("SELECT " + datasetName + ".sample.datarepo_row_id FROM " + datasetName + ".sample WHERE " + datasetName + ".sample.id ='sample6'");
SnapshotSummaryModel snapshotSummary = dataRepoFixtures.createSnapshotWithRequest(steward(), datasetName, requestModel);
TimeUnit.SECONDS.sleep(10);
createdSnapshotIds.add(snapshotSummary.getId());
SnapshotModel snapshot = dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId());
assertEquals("new snapshot has been created", snapshot.getName(), requestModel.getName());
}
Aggregations