use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.
the class AbstractJdbcEventAnalyticsManager method getAggregatedEventData.
public Grid getAggregatedEventData(EventQueryParams params, Grid grid, int maxLimit) {
String countClause = getAggregateClause(params);
String sql = TextUtils.removeLastComma("select " + countClause + " as value," + StringUtils.join(getSelectColumns(params), ",") + " ");
// ---------------------------------------------------------------------
// Criteria
// ---------------------------------------------------------------------
sql += getFromClause(params);
sql += getWhereClause(params);
// ---------------------------------------------------------------------
// Group by
// ---------------------------------------------------------------------
List<String> selectColumnNames = getGroupByColumnNames(params);
if (selectColumnNames.size() > 0) {
sql += "group by " + StringUtils.join(selectColumnNames, ",") + " ";
}
if (params.hasSortOrder()) {
sql += "order by value " + params.getSortOrder().toString().toLowerCase() + " ";
}
if (params.hasLimit()) {
sql += "limit " + params.getLimit();
} else if (maxLimit > 0) {
sql += "limit " + (maxLimit + 1);
}
try {
if (params.analyzeOnly()) {
executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
} else {
getAggregatedEventData(grid, params, sql);
}
} catch (BadSqlGrammarException ex) {
log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
} catch (DataAccessResourceFailureException ex) {
log.warn(ErrorCode.E7131.getMessage(), ex);
throw new QueryRuntimeException(ErrorCode.E7131, ex);
}
return grid;
}
use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getEventCount.
@Override
public long getEventCount(EventQueryParams params) {
String sql = "select count(psi) ";
sql += getFromClause(params);
sql += getWhereClause(params);
long count = 0;
try {
log.debug("Analytics event count SQL: " + sql);
if (params.analyzeOnly()) {
executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
} else {
count = jdbcTemplate.queryForObject(sql, Long.class);
}
} catch (BadSqlGrammarException ex) {
log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
} catch (DataAccessResourceFailureException ex) {
log.warn(E7131.getMessage(), ex);
throw new QueryRuntimeException(E7131, ex);
} catch (DataIntegrityViolationException ex) {
log.warn(E7132.getMessage(), ex);
throw new QueryRuntimeException(E7132, ex);
}
return count;
}
use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.
the class JdbcAnalyticsManager method getAggregatedDataValues.
// -------------------------------------------------------------------------
// AnalyticsManager implementation
// -------------------------------------------------------------------------
@Override
@Async
public Future<Map<String, Object>> getAggregatedDataValues(DataQueryParams params, AnalyticsTableType tableType, int maxLimit) {
assertQuery(params);
try {
ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = params.getDataPeriodAggregationPeriodMap();
if (params.isDisaggregation() && params.hasDataPeriodType()) {
params = DataQueryParams.newBuilder(params).withDataPeriodsForAggregationPeriods(dataPeriodAggregationPeriodMap).build();
params = queryPlanner.assignPartitionsFromQueryPeriods(params, tableType);
}
String sql = getSelectClause(params);
sql += getFromClause(params);
sql += getWhereClause(params, tableType);
sql += getGroupByClause(params);
if (params.hasMeasureCriteria() && params.isDataType(DataType.NUMERIC)) {
sql += getMeasureCriteriaSql(params);
}
log.debug(sql);
if (params.analyzeOnly()) {
executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
return new AsyncResult<>(Maps.newHashMap());
}
Map<String, Object> map;
try {
map = getKeyValueMap(params, sql, maxLimit);
} catch (BadSqlGrammarException ex) {
log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
return new AsyncResult<>(Maps.newHashMap());
}
replaceDataPeriodsWithAggregationPeriods(map, params, dataPeriodAggregationPeriodMap);
return new AsyncResult<>(map);
} catch (DataAccessResourceFailureException ex) {
log.warn(ErrorCode.E7131.getMessage(), ex);
throw new QueryRuntimeException(ErrorCode.E7131, ex);
} catch (RuntimeException ex) {
log.error(DebugUtils.getStackTrace(ex));
throw ex;
}
}
use of org.hisp.dhis.common.QueryRuntimeException in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsManager method getEnrollmentCount.
@Override
public long getEnrollmentCount(EventQueryParams params) {
String sql = "select count(pi) ";
sql += getFromClause(params);
sql += getWhereClause(params);
long count = 0;
try {
log.debug("Analytics enrollment count SQL: " + sql);
if (params.analyzeOnly()) {
executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
} else {
count = jdbcTemplate.queryForObject(sql, Long.class);
}
} catch (BadSqlGrammarException ex) {
log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
} catch (DataAccessResourceFailureException ex) {
log.warn(ErrorCode.E7131.getMessage(), ex);
throw new QueryRuntimeException(ErrorCode.E7131, ex);
}
return count;
}
Aggregations