use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getAggregatedDataValueSet.
@Override
public DataValueSet getAggregatedDataValueSet(DataQueryParams params) {
DataQueryParams query = DataQueryParams.newBuilder(params).withSkipMeta(false).withSkipData(false).withIncludeNumDen(false).withOutputFormat(OutputFormat.DATA_VALUE_SET).build();
Grid grid = getAggregatedDataValueGridInternal(query);
return AnalyticsUtils.getDataValueSetFromGrid(params, grid);
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultDataQueryService method getFromAnalyticalObject.
@Override
public DataQueryParams getFromAnalyticalObject(AnalyticalObject object) {
Assert.notNull(object, "Analytical object cannot be null");
DataQueryParams.Builder params = DataQueryParams.newBuilder();
I18nFormat format = i18nManager.getI18nFormat();
IdScheme idScheme = IdScheme.UID;
Date date = object.getRelativePeriodDate();
String userOrgUnit = object.getRelativeOrganisationUnit() != null ? object.getRelativeOrganisationUnit().getUid() : null;
List<OrganisationUnit> userOrgUnits = getUserOrgUnits(null, userOrgUnit);
object.populateAnalyticalProperties();
for (DimensionalObject column : object.getColumns()) {
params.addDimension(getDimension(column.getDimension(), getDimensionalItemIds(column.getItems()), date, userOrgUnits, format, false, false, idScheme));
}
for (DimensionalObject row : object.getRows()) {
params.addDimension(getDimension(row.getDimension(), getDimensionalItemIds(row.getItems()), date, userOrgUnits, format, false, false, idScheme));
}
for (DimensionalObject filter : object.getFilters()) {
params.addFilter(getDimension(filter.getDimension(), getDimensionalItemIds(filter.getItems()), date, userOrgUnits, format, false, false, idScheme));
}
return params.build();
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class JdbcRawAnalyticsManager method getStatement.
private String getStatement(DataQueryParams params, String partition) {
List<String> dimensionColumns = params.getDimensions().stream().map(d -> statementBuilder.columnQuote(d.getDimensionName())).collect(Collectors.toList());
setOrgUnitSelect(params, dimensionColumns);
SqlHelper sqlHelper = new SqlHelper();
String sql = "select " + StringUtils.join(dimensionColumns, ", ") + ", " + DIM_NAME_OU + ", value " + "from " + partition + " ax " + "inner join organisationunit ou on ax.ou = ou.uid " + "inner join _periodstructure ps on ax.pe = ps.iso ";
for (DimensionalObject dim : params.getDimensions()) {
if (!dim.getItems().isEmpty() && !dim.isFixed()) {
String col = statementBuilder.columnQuote(dim.getDimensionName());
if (DimensionalObject.ORGUNIT_DIM_ID.equals(dim.getDimension())) {
sql += sqlHelper.whereAnd() + " (";
for (DimensionalItemObject item : dim.getItems()) {
OrganisationUnit unit = (OrganisationUnit) item;
sql += DIM_NAME_OU + " like '" + unit.getPath() + "%' or ";
}
sql = TextUtils.removeLastOr(sql) + ") ";
} else {
sql += sqlHelper.whereAnd() + " " + col + " in (" + getQuotedCommaDelimitedString(getUids(dim.getItems())) + ") ";
}
}
}
if (params.hasStartEndDate()) {
sql += sqlHelper.whereAnd() + " " + "ps.startdate >= '" + DateUtils.getMediumDateString(params.getStartDate()) + "' and " + "ps.enddate <= '" + DateUtils.getMediumDateString(params.getEndDate()) + "' ";
}
return sql;
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByPartition.
// -------------------------------------------------------------------------
// Supportive - group by methods
// -------------------------------------------------------------------------
@Override
public List<DataQueryParams> groupByPartition(DataQueryParams params, QueryPlannerParams plannerParams) {
Set<String> validPartitions = partitionManager.getDataValueAnalyticsPartitions();
String tableName = plannerParams.getTableName();
String tableSuffix = plannerParams.getTableSuffix();
List<DataQueryParams> queries = new ArrayList<>();
if (params.isSkipPartitioning()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(new Partitions().add(tableName)).build();
queries.add(query);
} else if (!params.getPeriods().isEmpty()) {
ListMap<Partitions, DimensionalItemObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap(params.getPeriods(), tableName, tableSuffix, validPartitions);
for (Partitions partitions : partitionPeriodMap.keySet()) {
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPeriods(partitionPeriodMap.get(partitions)).withPartitions(partitions).build();
queries.add(query);
}
}
} else if (!params.getFilterPeriods().isEmpty()) {
Partitions partitions = PartitionUtils.getPartitions(params.getFilterPeriods(), tableName, tableSuffix, validPartitions);
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
queries.add(query);
}
} else if (params.hasStartEndDate()) {
Partitions partitions = PartitionUtils.getPartitions(params.getStartDate(), params.getEndDate(), tableName, tableSuffix, validPartitions);
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
queries.add(query);
}
} else {
throw new IllegalQueryException("Query does not contain any period dimension items");
}
if (queries.size() > 1) {
log.debug(String.format("Split on partition: %d", queries.size()));
}
return queries;
}
use of org.hisp.dhis.analytics.DataQueryParams in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByStartEndDate.
@Override
public List<DataQueryParams> groupByStartEndDate(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getPeriods().isEmpty()) {
for (DimensionalItemObject item : params.getPeriods()) {
Period period = (Period) item;
DataQueryParams query = DataQueryParams.newBuilder(params).withStartDate(period.getStartDate()).withEndDate(period.getEndDate()).build();
BaseDimensionalObject staticPeriod = (BaseDimensionalObject) query.getDimension(PERIOD_DIM_ID);
staticPeriod.setDimensionName(period.getIsoDate());
staticPeriod.setFixed(true);
queries.add(query);
}
} else if (!params.getFilterPeriods().isEmpty()) {
Period period = (Period) params.getFilterPeriods().get(0);
DataQueryParams query = DataQueryParams.newBuilder(params).withStartDate(period.getStartDate()).withEndDate(period.getEndDate()).removeFilter(PERIOD_DIM_ID).build();
queries.add(query);
} else {
throw new IllegalQueryException("Query does not contain any period dimension items");
}
if (queries.size() > 1) {
log.debug(String.format("Split on period: %d", queries.size()));
}
return queries;
}
Aggregations