Fixed query

This commit is contained in:
Luca Frosini 2021-11-22 15:07:29 +01:00
parent c70970cf24
commit 3c7f8d9de7
2 changed files with 36 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageStatusRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
import org.gcube.accounting.utility.postgresql.PostgreSQLQuery;
import org.gcube.accounting.utility.postgresql.RecordToDBFields;
@ -183,8 +184,22 @@ public class Query extends PostgreSQLQuery {
stringBuffer.append(") AS ");
break;
case AggregatedStorageStatusRecord.DATA_COUNT:
stringBuffer.append(", MAX(");
if(addNested) {
stringBuffer.append(NESTED_TABLE_NAME);
stringBuffer.append(".");
}
stringBuffer.append(dbField);
stringBuffer.append(") AS ");
break;
case AggregatedStorageUsageRecord.DATA_VOLUME:
stringBuffer.append(", SUM(");
if(clz.isAssignableFrom(AggregatedStorageUsageRecord.class)) {
stringBuffer.append(", SUM(");
}else if(clz.isAssignableFrom(AggregatedStorageStatusRecord.class)){
stringBuffer.append(", MAX(");
}
if(addNested) {
stringBuffer.append(NESTED_TABLE_NAME);
stringBuffer.append(".");
@ -355,10 +370,15 @@ public class Query extends PostgreSQLQuery {
addTemporalConstraintToQuery();
stringBuffer.append(" AND ");
addFilters();
stringBuffer.append(" AND ");
addContextFilter();
if(filters!=null && filters.size()>0) {
stringBuffer.append(" AND ");
addFilters();
}
if(contexts!=null && contexts.size()>0) {
stringBuffer.append(" AND ");
addContextFilter();
}
addDateGroupBy(false);
addDateOrderBy(false);
@ -382,11 +402,16 @@ public class Query extends PostgreSQLQuery {
stringBuffer.append(" FROM ");
stringBuffer.append(recordToDBFields.getTableName());
addTemporalConstraintToQuery();
if(temporalConstraint!=null) {
addTemporalConstraintToQuery();
stringBuffer.append(" AND ");
}
if(filters!=null && filters.size()>0) {
addFilters();
stringBuffer.append(" AND ");
}
stringBuffer.append(" AND ");
addFilters();
stringBuffer.append(" AND ");
addContextFilter();
addGroupAndOrderByForOrderByField();

View File

@ -223,8 +223,10 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
@Test
public void gcTest() throws Exception {
accountingPersistenceQueryPostgreSQL.setRequestedRecords(AggregatedStorageStatusRecord.class);
TemporalConstraint temporalConstraint = getTemporalConstraint();
Collection<NumberedFilter> myFilters = accountingPersistenceQueryPostgreSQL.getFilterValues(AggregatedStorageStatusRecord.DATA_TYPE);
accountingPersistenceQueryPostgreSQL.setFilters(myFilters);
accountingPersistenceQueryPostgreSQL.setTemporalConstraint(temporalConstraint);
accountingPersistenceQueryPostgreSQL.getTimeSeries();
}