use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class SnapshotService method conjureSnapshotTablesFromAsset.
/**
* Magic up the snapshot tables and snapshot map from the asset tables and columns.
* This method sets the table lists into snapshot and snapshotSource.
*
* @param asset the one and only asset specification for this snapshot
* @param snapshot snapshot to point back to and fill in
* @param snapshotSource snapshotSource to point back to and fill in
*/
private void conjureSnapshotTablesFromAsset(AssetSpecification asset, Snapshot snapshot, SnapshotSource snapshotSource) {
List<SnapshotTable> tableList = new ArrayList<>();
List<SnapshotMapTable> mapTableList = new ArrayList<>();
for (AssetTable assetTable : asset.getAssetTables()) {
// Create early so we can hook up back pointers.
SnapshotTable table = new SnapshotTable();
// Build the column lists in parallel, so we can easily connect the
// map column to the snapshot column.
List<Column> columnList = new ArrayList<>();
List<SnapshotMapColumn> mapColumnList = new ArrayList<>();
for (AssetColumn assetColumn : assetTable.getColumns()) {
Column column = new Column(assetColumn.getDatasetColumn());
columnList.add(column);
mapColumnList.add(new SnapshotMapColumn().fromColumn(assetColumn.getDatasetColumn()).toColumn(column));
}
table.name(assetTable.getTable().getName()).columns(columnList);
tableList.add(table);
mapTableList.add(new SnapshotMapTable().fromTable(assetTable.getTable()).toTable(table).snapshotMapColumns(mapColumnList));
}
snapshotSource.snapshotMapTables(mapTableList);
snapshot.snapshotTables(tableList);
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class BigQueryPdao method mapValuesToRows.
// compute the row ids from the input ids and validate all inputs have matches
// returns a structure with the matching row ids (suitable for calling create snapshot)
// and any mismatched input values that don't have corresponding roww.
// NOTE: In the fullness of time, we may not do this and kick the function into the UI.
// So this code assumes there is one source and one set of input values.
// The query it builds embeds data values into the query in an array. I think it will
// support about 25,000 input values. If that is not enough there is another, more
// complicated alternative:
// - create a scratch table at snapshot creation time
// - truncate before we start
// - load the values in
// - do the query
// - truncate (even tidier...)
// So if we need to make this work in the long term, we can take that approach.
@Override
public RowIdMatch mapValuesToRows(Snapshot snapshot, SnapshotSource source, List<String> inputValues) throws InterruptedException {
// One source: grab it and navigate to the relevant parts
BigQueryProject bigQueryProject = bigQueryProjectForSnapshot(snapshot);
AssetSpecification asset = source.getAssetSpecification();
Column column = asset.getRootColumn().getDatasetColumn();
ST sqlTemplate = new ST(mapValuesToRowsTemplate);
sqlTemplate.add("project", bigQueryProject.getProjectId());
sqlTemplate.add("dataset", prefixName(source.getDataset().getName()));
sqlTemplate.add("table", column.getTable().getName());
sqlTemplate.add("column", column.getName());
sqlTemplate.add("inputVals", inputValues);
// Execute the query building the row id match structure that tracks the matching
// ids and the mismatched ids
RowIdMatch rowIdMatch = new RowIdMatch();
String sql = sqlTemplate.render();
logger.debug("mapValuesToRows sql: " + sql);
TableResult result = bigQueryProject.query(sql);
for (FieldValueList row : result.iterateAll()) {
// Test getting these by name
FieldValue rowId = row.get(0);
FieldValue inputValue = row.get(1);
if (rowId.isNull()) {
rowIdMatch.addMismatch(inputValue.getStringValue());
logger.debug("rowId=<NULL>" + " inVal=" + inputValue.getStringValue());
} else {
rowIdMatch.addMatch(inputValue.getStringValue(), rowId.getStringValue());
logger.debug("rowId=" + rowId.getStringValue() + " inVal=" + inputValue.getStringValue());
}
}
return rowIdMatch;
}
use of bio.terra.common.Column in project jade-data-repo by DataBiosphere.
the class AssetDao method retrieveAssetSpecifications.
// also retrieves dependent objects
public List<AssetSpecification> retrieveAssetSpecifications(Dataset dataset) {
Map<UUID, DatasetTable> allTables = dataset.getTablesById();
Map<UUID, Column> allColumns = dataset.getAllColumnsById();
Map<UUID, Relationship> allRelationships = dataset.getRelationshipsById();
String sql = "SELECT id, name, root_table_id, root_column_id FROM asset_specification WHERE dataset_id = " + ":datasetId";
MapSqlParameterSource params = new MapSqlParameterSource().addValue("datasetId", dataset.getId());
return jdbcTemplate.query(sql, params, (rs, rowNum) -> {
UUID specId = rs.getObject("id", UUID.class);
AssetSpecification spec = new AssetSpecification().id(specId).name(rs.getString("name"));
spec.assetTables(new ArrayList(retrieveAssetTablesAndColumns(spec, rs.getObject("root_table_id", UUID.class), rs.getObject("root_column_id", UUID.class), allTables, allColumns)));
spec.assetRelationships(retrieveAssetRelationships(spec.getId(), allRelationships));
return spec;
});
}
Aggregations