use of bio.terra.service.tabulardata.exception.BadExternalFileException in project jade-data-repo by DataBiosphere.
the class BigQueryPdao method createSoftDeleteExternalTable.
public void createSoftDeleteExternalTable(Dataset dataset, String path, String tableName, String suffix) throws InterruptedException {
BigQueryProject bigQueryProject = bigQueryProjectForDataset(dataset);
String extTableName = externalTableName(tableName, suffix);
TableId tableId = TableId.of(prefixName(dataset.getName()), extTableName);
Schema schema = Schema.of(Field.of(PDAO_ROW_ID_COLUMN, LegacySQLTypeName.STRING));
ExternalTableDefinition tableDef = ExternalTableDefinition.of(path, schema, FormatOptions.csv());
TableInfo tableInfo = TableInfo.of(tableId, tableDef);
bigQueryProject.getBigQuery().create(tableInfo);
// validate that the external table has data
String sql = new ST(validateExtTableTemplate).add("rowId", PDAO_ROW_ID_COLUMN).add("project", bigQueryProject.getProjectId()).add("dataset", tableId.getDataset()).add("table", tableId.getTable()).render();
TableResult result = bigQueryProject.query(sql);
if (result.getTotalRows() == 0L) {
// either the file at the path is empty or it doesn't exist. error out and let the cleanup begin
String msg = String.format("No rows found at %s. Likely it is from a bad path or empty file(s).", path);
throw new BadExternalFileException(msg);
}
}
Aggregations