Search in sources :

Example 1 with QueryParameters

use of org.pmiops.workbench.cohortbuilder.querybuilder.QueryParameters in project workbench by all-of-us.

the class ParticipantCounter method buildQuery.

private StringJoiner buildQuery(List<SearchGroup> groups, String mainTable, Map<String, QueryParameterValue> params, Boolean excludeSQL) {
    StringJoiner joiner = new StringJoiner("and ");
    List<String> queryParts = new ArrayList<>();
    for (SearchGroup includeGroup : groups) {
        for (SearchGroupItem includeItem : includeGroup.getItems()) {
            QueryJobConfiguration queryRequest = QueryBuilderFactory.getQueryBuilder(FactoryKey.getType(includeItem.getType())).buildQueryJobConfig(new QueryParameters().type(includeItem.getType()).parameters(includeItem.getSearchParameters()));
            params.putAll(queryRequest.getNamedParameters());
            queryParts.add(queryRequest.getQuery());
        }
        if (excludeSQL) {
            joiner.add(EXCLUDE_SQL_TEMPLATE.replace("${mainTable}", mainTable).replace("${excludeSql}", String.join(UNION_TEMPLATE, queryParts)));
        } else {
            joiner.add(INCLUDE_SQL_TEMPLATE.replace("${mainTable}", mainTable).replace("${includeSql}", String.join(UNION_TEMPLATE, queryParts)));
        }
        queryParts = new ArrayList<>();
    }
    return joiner;
}
Also used : SearchGroup(org.pmiops.workbench.model.SearchGroup) ArrayList(java.util.ArrayList) QueryParameters(org.pmiops.workbench.cohortbuilder.querybuilder.QueryParameters) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) StringJoiner(java.util.StringJoiner) SearchGroupItem(org.pmiops.workbench.model.SearchGroupItem)

Aggregations

QueryJobConfiguration (com.google.cloud.bigquery.QueryJobConfiguration)1 ArrayList (java.util.ArrayList)1 StringJoiner (java.util.StringJoiner)1 QueryParameters (org.pmiops.workbench.cohortbuilder.querybuilder.QueryParameters)1 SearchGroup (org.pmiops.workbench.model.SearchGroup)1 SearchGroupItem (org.pmiops.workbench.model.SearchGroupItem)1