Implementing query
This commit is contained in:
parent
82ed33203d
commit
94f4219852
|
@ -131,9 +131,9 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
||||||
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
public SortedMap<Calendar, Info> getTimeSeries(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
|
String context = AccountingPersistenceBackendQuery.getScopeToQuery();
|
||||||
Set<String> contexts = new HashSet<>();
|
Set<String> contexts = new HashSet<>();
|
||||||
contexts.add(currentScope);
|
contexts.add(context);
|
||||||
return getTimeSeries(clz, temporalConstraint, filters, contexts);
|
return getTimeSeries(clz, temporalConstraint, filters, contexts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +151,25 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
||||||
return getTimeSeries(clz, temporalConstraint, filters, null);
|
return getTimeSeries(clz, temporalConstraint, filters, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
||||||
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||||
|
List<String> contexts) throws Exception {
|
||||||
|
|
||||||
|
SortedMap<Filter,SortedMap<Calendar,Info>> ret = new TreeMap<>();
|
||||||
|
for(String context : contexts) {
|
||||||
|
Filter contextFilter = new Filter("context", context);
|
||||||
|
Set<String> timeSeriesContexts = new HashSet<>();
|
||||||
|
timeSeriesContexts.add(context);
|
||||||
|
SortedMap<Calendar, Info> timeSeries = getTimeSeries(clz, temporalConstraint, filters, timeSeriesContexts);
|
||||||
|
if(!timeSeries.isEmpty()) {
|
||||||
|
ret.put(contextFilter, timeSeries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
protected SortedSet<NumberedFilter> getNumberedValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
protected SortedSet<NumberedFilter> getNumberedValues(Class<? extends AggregatedRecord<?, ?>> clz,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters, String key,
|
TemporalConstraint temporalConstraint, List<Filter> filters, String key,
|
||||||
String orderingProperty, Integer limit) throws Exception {
|
String orderingProperty, Integer limit) throws Exception {
|
||||||
|
@ -168,9 +187,9 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
||||||
|
|
||||||
SortedSet<NumberedFilter> result = new TreeSet<>();
|
SortedSet<NumberedFilter> result = new TreeSet<>();
|
||||||
|
|
||||||
String currentScope = AccountingPersistenceBackendQuery.getScopeToQuery();
|
String context = AccountingPersistenceBackendQuery.getScopeToQuery();
|
||||||
Set<String> contexts = new HashSet<>();
|
Set<String> contexts = new HashSet<>();
|
||||||
contexts.add(currentScope);
|
contexts.add(context);
|
||||||
|
|
||||||
Query query = new Query(clz);
|
Query query = new Query(clz);
|
||||||
query.setTemporalConstraint(temporalConstraint);
|
query.setTemporalConstraint(temporalConstraint);
|
||||||
|
@ -218,15 +237,23 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||||
String topKey, String orderingProperty)
|
String topKey, String orderingProperty)
|
||||||
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
String context = AccountingPersistenceBackendQuery.getScopeToQuery();
|
||||||
}
|
Set<String> contexts = new HashSet<>();
|
||||||
|
contexts.add(context);
|
||||||
@Override
|
|
||||||
public JSONObject getUsageValue(Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint,
|
SortedMap<NumberedFilter,SortedMap<Calendar,Info>> ret = new TreeMap<>();
|
||||||
Filter applicant) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
SortedSet<NumberedFilter> top = getNumberedValues(clz, temporalConstraint, filters, topKey, orderingProperty, 3);
|
||||||
return null;
|
|
||||||
|
for(NumberedFilter numberedFilter : top) {
|
||||||
|
filters.add(numberedFilter);
|
||||||
|
SortedMap<Calendar,Info> map = getTimeSeries(clz, temporalConstraint, filters, contexts);
|
||||||
|
ret.put(numberedFilter, map);
|
||||||
|
filters.remove(numberedFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -235,14 +262,6 @@ public class AccountingPersistenceQueryPostgreSQL implements AccountingPersisten
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SortedMap<Filter, SortedMap<Calendar, Info>> getContextTimeSeries(
|
|
||||||
Class<? extends AggregatedRecord<?, ?>> clz, TemporalConstraint temporalConstraint, List<Filter> filters,
|
|
||||||
List<String> contexts) throws Exception {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRecord(String recordId, String type) throws Exception {
|
public String getRecord(String recordId, String type) throws Exception {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
||||||
import org.gcube.accounting.analytics.exception.KeyException;
|
import org.gcube.accounting.analytics.exception.KeyException;
|
||||||
import org.gcube.accounting.analytics.exception.ValueException;
|
import org.gcube.accounting.analytics.exception.ValueException;
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceBackendQueryConfiguration;
|
||||||
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||||
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.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -70,7 +71,6 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimeSeries() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
public void testTimeSeries() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
Calendar startTimeCalendar = Calendar.getInstance();
|
Calendar startTimeCalendar = Calendar.getInstance();
|
||||||
|
@ -98,6 +98,43 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContextTimeSeries() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
|
Calendar startTimeCalendar = Calendar.getInstance();
|
||||||
|
startTimeCalendar.set(Calendar.YEAR, 2020);
|
||||||
|
startTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||||
|
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
startTimeCalendar.set(Calendar.MINUTE, 0);
|
||||||
|
|
||||||
|
Calendar entTimeCalendar = Calendar.getInstance();
|
||||||
|
entTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||||
|
entTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
|
||||||
|
entTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
|
||||||
|
entTimeCalendar.set(Calendar.MINUTE, 17);
|
||||||
|
|
||||||
|
List<Filter> filters = new ArrayList<>();
|
||||||
|
Filter filter = new Filter(UsageRecord.CONSUMER_ID, QueryTest.getRandomUser());
|
||||||
|
filters.add(filter);
|
||||||
|
|
||||||
|
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MONTHLY);
|
||||||
|
|
||||||
|
List<String> contexts = new ArrayList<>();
|
||||||
|
contexts.add("/gcube/devsec/devVRE");
|
||||||
|
contexts.add("/gcube/devNext/NextNext");
|
||||||
|
|
||||||
|
SortedMap<Filter, SortedMap<Calendar, Info>> contextTimeseries = accountingPersistenceQueryPostgreSQL.getContextTimeSeries(AggregatedServiceUsageRecord.class, temporalConstraint, filters, contexts);
|
||||||
|
for(Filter f : contextTimeseries.keySet()) {
|
||||||
|
logger.debug("{}", f);
|
||||||
|
SortedMap<Calendar, Info> timeseries = contextTimeseries.get(f);
|
||||||
|
for(Calendar c : timeseries.keySet()) {
|
||||||
|
Info info = timeseries.get(c);
|
||||||
|
logger.debug("{}", info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFilterValues() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
public void testGetFilterValues() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
|
@ -130,9 +167,45 @@ public class AccountingPersistenceQueryPostgreSQLTest extends ContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
numberedFilters = accountingPersistenceQueryPostgreSQL.getFilterValues(AggregatedServiceUsageRecord.class, temporalConstraint, filters, AggregatedServiceUsageRecord.CALLED_METHOD, 2);
|
numberedFilters = accountingPersistenceQueryPostgreSQL.getFilterValues(AggregatedServiceUsageRecord.class, temporalConstraint, filters, AggregatedServiceUsageRecord.CALLED_METHOD, 3);
|
||||||
for(NumberedFilter numberedFilter : numberedFilters) {
|
for(NumberedFilter numberedFilter : numberedFilters) {
|
||||||
logger.debug("{}", numberedFilter);
|
logger.debug("{}", numberedFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTopValues() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||||
|
String orderingProperty = AccountingPersistenceQuery.getDefaultOrderingProperties(AggregatedServiceUsageRecord.class);
|
||||||
|
|
||||||
|
Calendar startTimeCalendar = Calendar.getInstance();
|
||||||
|
startTimeCalendar.set(Calendar.YEAR, 2020);
|
||||||
|
startTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||||
|
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
startTimeCalendar.set(Calendar.MINUTE, 0);
|
||||||
|
|
||||||
|
Calendar entTimeCalendar = Calendar.getInstance();
|
||||||
|
entTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||||
|
entTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
|
||||||
|
entTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
|
||||||
|
entTimeCalendar.set(Calendar.MINUTE, 17);
|
||||||
|
|
||||||
|
List<Filter> filters = new ArrayList<>();
|
||||||
|
Filter filter = new Filter(UsageRecord.CONSUMER_ID, QueryTest.getRandomUser());
|
||||||
|
filters.add(filter);
|
||||||
|
|
||||||
|
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MONTHLY);
|
||||||
|
|
||||||
|
SortedMap<NumberedFilter, SortedMap<Calendar, Info>> topTimeSeries = accountingPersistenceQueryPostgreSQL.getTopValues(AggregatedServiceUsageRecord.class, temporalConstraint, filters, AggregatedServiceUsageRecord.CALLED_METHOD, orderingProperty);
|
||||||
|
for(NumberedFilter numberedFilter : topTimeSeries.keySet()) {
|
||||||
|
logger.debug("{}", numberedFilter);
|
||||||
|
SortedMap<Calendar, Info> timeseries = topTimeSeries.get(numberedFilter);
|
||||||
|
for(Calendar c : timeseries.keySet()) {
|
||||||
|
Info info = timeseries.get(c);
|
||||||
|
logger.debug("{}", info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue