use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class FieldSetQueryBuilder method handleColumnFilters.
private void handleColumnFilters(List<ColumnFilter> columnFilters, TableQueryAndConfig tableQueryAndConfig, StringBuilder sqlBuilder, Map<String, QueryParameterValue> paramMap) {
if (columnFilters.isEmpty()) {
throw new BadRequestException("Empty column filter list is invalid");
}
sqlBuilder.append("(");
boolean first = true;
for (ColumnFilter columnFilter : columnFilters) {
if (first) {
first = false;
} else {
sqlBuilder.append("\nand\n");
}
handleColumnFilter(columnFilter, tableQueryAndConfig, sqlBuilder, paramMap);
}
sqlBuilder.append(")");
}
use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class FieldSetQueryBuilder method buildQuery.
public QueryJobConfiguration buildQuery(ParticipantCriteria participantCriteria, TableQueryAndConfig tableQueryAndConfig, long resultSize, long offset) {
TableQuery tableQuery = tableQueryAndConfig.getTableQuery();
List<String> columnNames = tableQuery.getColumns();
String tableName = tableQuery.getTableName();
StringBuilder startSql = new StringBuilder("select ");
// TODO: add column aliases, use below
startSql.append(Joiner.on(", ").join(columnNames));
startSql.append("\nfrom `${projectId}.${dataSetId}.");
startSql.append(tableName);
startSql.append("` ");
startSql.append(tableName);
startSql.append("\nwhere\n");
Map<String, QueryParameterValue> paramMap = new HashMap<>();
List<List<ColumnFilter>> columnFilters = tableQuery.getFilters();
if (columnFilters != null && !columnFilters.isEmpty()) {
startSql.append("(");
boolean first = true;
for (List<ColumnFilter> filterList : columnFilters) {
if (first) {
first = false;
} else {
startSql.append("\nor\n");
}
handleColumnFilters(filterList, tableQueryAndConfig, startSql, paramMap);
}
startSql.append(")\nand\n");
}
StringBuilder endSql = new StringBuilder("order by ");
List<String> orderBy = tableQuery.getOrderBy();
if (orderBy.isEmpty()) {
throw new BadRequestException("Order by list must not be empty");
}
endSql.append(Joiner.on(", ").join(orderBy));
endSql.append(" limit ");
endSql.append(resultSize);
if (offset > 0) {
endSql.append(" offset ");
endSql.append(offset);
}
return participantCounter.buildQuery(participantCriteria, startSql.toString(), endSql.toString(), tableName, paramMap);
}
Aggregations