use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class DatasetDaoTest method primaryKeyTest.
@Test
public void primaryKeyTest() throws IOException, SQLException {
UUID datasetId = createDataset("dataset-primary-key.json");
try {
Dataset fromDB = datasetDao.retrieve(datasetId);
DatasetTable variants = fromDB.getTableByName("variant").orElseThrow(IllegalStateException::new);
DatasetTable freqAnalysis = fromDB.getTableByName("frequency_analysis").orElseThrow(IllegalStateException::new);
DatasetTable metaAnalysis = fromDB.getTableByName("meta_analysis").orElseThrow(IllegalStateException::new);
assertThat("single-column primary keys are set correctly", variants.getPrimaryKey().stream().map(Column::getName).collect(Collectors.toList()), equalTo(Collections.singletonList("id")));
assertThat("dual-column primary keys are set correctly", metaAnalysis.getPrimaryKey().stream().map(Column::getName).collect(Collectors.toList()), equalTo(Arrays.asList("variant_id", "phenotype")));
assertThat("many-column primary keys are set correctly", freqAnalysis.getPrimaryKey().stream().map(Column::getName).collect(Collectors.toList()), equalTo(Arrays.asList("variant_id", "ancestry", "phenotype")));
} finally {
datasetDao.delete(datasetId);
}
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class DatasetTableDao method retrieveTables.
public List<DatasetTable> retrieveTables(UUID parentId) {
MapSqlParameterSource params = new MapSqlParameterSource().addValue("dataset_id", parentId);
return jdbcTemplate.query(sqlSelectTable, params, (rs, rowNum) -> {
DatasetTable table = new DatasetTable().id(rs.getObject("id", UUID.class)).name(rs.getString("name")).rawTableName(rs.getString("raw_table_name")).softDeleteTableName(rs.getString("soft_delete_table_name"));
List<Column> columns = retrieveColumns(table);
table.columns(columns);
Map<String, Column> columnMap = columns.stream().collect(Collectors.toMap(Column::getName, Function.identity()));
List<String> primaryKey = DaoUtils.getStringList(rs, "primary_key");
List<Column> naturalKeyColumns = primaryKey.stream().map(columnMap::get).collect(Collectors.toList());
table.primaryKey(naturalKeyColumns);
long bqPartitionVersion = rs.getLong("bigquery_partition_config_version");
String bqPartitionConfig = rs.getString("bigquery_partition_config");
if (bqPartitionVersion == 1) {
try {
table.bigQueryPartitionConfig(objectMapper.readValue(bqPartitionConfig, BigQueryPartitionConfigV1.class));
} catch (Exception ex) {
throw new CorruptMetadataException("Malformed BigQuery partition config", ex);
}
} else {
throw new CorruptMetadataException("Unknown BigQuery partition config version: " + bqPartitionVersion);
}
return table;
});
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class DatasetTableDao method createColumns.
private void createColumns(UUID tableId, Collection<Column> columns) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("table_id", tableId);
DaoKeyHolder keyHolder = new DaoKeyHolder();
for (Column column : columns) {
params.addValue("name", column.getName());
params.addValue("type", column.getType());
params.addValue("array_of", column.isArrayOf());
jdbcTemplate.update(sqlInsertColumn, params, keyHolder);
UUID columnId = keyHolder.getId();
column.id(columnId);
}
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class SnapshotService method conjureSnapshotTablesFromRowIds.
private void conjureSnapshotTablesFromRowIds(SnapshotRequestRowIdModel requestRowIdModel, Snapshot snapshot, SnapshotSource snapshotSource) {
// TODO this will need to be changed when we have more than one dataset per snapshot (>1 contentsModel)
List<SnapshotTable> tableList = new ArrayList<>();
snapshot.snapshotTables(tableList);
List<SnapshotMapTable> mapTableList = new ArrayList<>();
snapshotSource.snapshotMapTables(mapTableList);
Dataset dataset = snapshotSource.getDataset();
// create a lookup from tableName -> table spec from the request
Map<String, SnapshotRequestRowIdTableModel> requestTableLookup = requestRowIdModel.getTables().stream().collect(Collectors.toMap(SnapshotRequestRowIdTableModel::getTableName, Function.identity()));
// for each dataset table specified in the request, create a table in the snapshot with the same name
for (DatasetTable datasetTable : dataset.getTables()) {
if (!requestTableLookup.containsKey(datasetTable.getName())) {
// only capture the dataset tables in the request model
continue;
}
List<Column> columnList = new ArrayList<>();
SnapshotTable snapshotTable = new SnapshotTable().name(datasetTable.getName()).columns(columnList);
tableList.add(snapshotTable);
List<SnapshotMapColumn> mapColumnList = new ArrayList<>();
mapTableList.add(new SnapshotMapTable().fromTable(datasetTable).toTable(snapshotTable).snapshotMapColumns(mapColumnList));
// for each dataset column specified in the request, create a column in the snapshot with the same name
Set<String> requestColumns = new HashSet<>(requestTableLookup.get(datasetTable.getName()).getColumns());
datasetTable.getColumns().stream().filter(c -> requestColumns.contains(c.getName())).forEach(datasetColumn -> {
Column snapshotColumn = new Column().name(datasetColumn.getName());
SnapshotMapColumn snapshotMapColumn = new SnapshotMapColumn().fromColumn(datasetColumn).toColumn(snapshotColumn);
columnList.add(snapshotColumn);
mapColumnList.add(snapshotMapColumn);
});
}
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class SnapshotService method conjureSnapshotTablesFromDatasetTables.
private void conjureSnapshotTablesFromDatasetTables(Snapshot snapshot, SnapshotSource snapshotSource) {
// TODO this will need to be changed when we have more than one dataset per snapshot (>1 contentsModel)
// for each dataset table specified in the request, create a table in the snapshot with the same name
Dataset dataset = snapshotSource.getDataset();
List<SnapshotTable> tableList = new ArrayList<>();
List<SnapshotMapTable> mapTableList = new ArrayList<>();
for (DatasetTable datasetTable : dataset.getTables()) {
List<Column> columnList = new ArrayList<>();
List<SnapshotMapColumn> mapColumnList = new ArrayList<>();
// for each dataset column specified in the request, create a column in the snapshot with the same name
for (Column datasetColumn : datasetTable.getColumns()) {
Column snapshotColumn = new Column().name(datasetColumn.getName());
SnapshotMapColumn snapshotMapColumn = new SnapshotMapColumn().fromColumn(datasetColumn).toColumn(snapshotColumn);
columnList.add(snapshotColumn);
mapColumnList.add(snapshotMapColumn);
}
// create snapshot tables & mapping with the proper dataset name and columns
SnapshotTable snapshotTable = new SnapshotTable().name(datasetTable.getName()).columns(columnList);
tableList.add(snapshotTable);
mapTableList.add(new SnapshotMapTable().fromTable(datasetTable).toTable(snapshotTable).snapshotMapColumns(mapColumnList));
}
// set the snapshot tables and mapping
snapshot.snapshotTables(tableList);
snapshotSource.snapshotMapTables(mapTableList);
}
Aggregations