Fixed query
This commit is contained in:
parent
c70970cf24
commit
3c7f8d9de7
|
@ -16,6 +16,7 @@ import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum;
|
import org.gcube.accounting.analytics.TemporalConstraint.CalendarEnum;
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
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.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||||
import org.gcube.accounting.utility.postgresql.PostgreSQLQuery;
|
import org.gcube.accounting.utility.postgresql.PostgreSQLQuery;
|
||||||
import org.gcube.accounting.utility.postgresql.RecordToDBFields;
|
import org.gcube.accounting.utility.postgresql.RecordToDBFields;
|
||||||
|
@ -183,8 +184,22 @@ public class Query extends PostgreSQLQuery {
|
||||||
stringBuffer.append(") AS ");
|
stringBuffer.append(") AS ");
|
||||||
break;
|
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:
|
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) {
|
if(addNested) {
|
||||||
stringBuffer.append(NESTED_TABLE_NAME);
|
stringBuffer.append(NESTED_TABLE_NAME);
|
||||||
stringBuffer.append(".");
|
stringBuffer.append(".");
|
||||||
|
@ -355,10 +370,15 @@ public class Query extends PostgreSQLQuery {
|
||||||
|
|
||||||
addTemporalConstraintToQuery();
|
addTemporalConstraintToQuery();
|
||||||
|
|
||||||
stringBuffer.append(" AND ");
|
if(filters!=null && filters.size()>0) {
|
||||||
addFilters();
|
stringBuffer.append(" AND ");
|
||||||
stringBuffer.append(" AND ");
|
addFilters();
|
||||||
addContextFilter();
|
}
|
||||||
|
|
||||||
|
if(contexts!=null && contexts.size()>0) {
|
||||||
|
stringBuffer.append(" AND ");
|
||||||
|
addContextFilter();
|
||||||
|
}
|
||||||
|
|
||||||
addDateGroupBy(false);
|
addDateGroupBy(false);
|
||||||
addDateOrderBy(false);
|
addDateOrderBy(false);
|
||||||
|
@ -382,11 +402,16 @@ public class Query extends PostgreSQLQuery {
|
||||||
stringBuffer.append(" FROM ");
|
stringBuffer.append(" FROM ");
|
||||||
stringBuffer.append(recordToDBFields.getTableName());
|
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();
|
addContextFilter();
|
||||||
|
|
||||||
addGroupAndOrderByForOrderByField();
|
addGroupAndOrderByForOrderByField();
|
||||||
|
|
|
@ -223,8 +223,10 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
||||||
@Test
|
@Test
|
||||||
public void gcTest() throws Exception {
|
public void gcTest() throws Exception {
|
||||||
accountingPersistenceQueryPostgreSQL.setRequestedRecords(AggregatedStorageStatusRecord.class);
|
accountingPersistenceQueryPostgreSQL.setRequestedRecords(AggregatedStorageStatusRecord.class);
|
||||||
|
TemporalConstraint temporalConstraint = getTemporalConstraint();
|
||||||
Collection<NumberedFilter> myFilters = accountingPersistenceQueryPostgreSQL.getFilterValues(AggregatedStorageStatusRecord.DATA_TYPE);
|
Collection<NumberedFilter> myFilters = accountingPersistenceQueryPostgreSQL.getFilterValues(AggregatedStorageStatusRecord.DATA_TYPE);
|
||||||
accountingPersistenceQueryPostgreSQL.setFilters(myFilters);
|
accountingPersistenceQueryPostgreSQL.setFilters(myFilters);
|
||||||
|
accountingPersistenceQueryPostgreSQL.setTemporalConstraint(temporalConstraint);
|
||||||
accountingPersistenceQueryPostgreSQL.getTimeSeries();
|
accountingPersistenceQueryPostgreSQL.getTimeSeries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue