use of com.yahoo.elide.datastores.aggregation.query.MetricProjection in project elide by yahoo.
the class EntityProjectionTranslatorTest method testBasicTranslation.
@Test
public void testBasicTranslation() {
EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, basicProjection, scope, true);
Query query = translator.getQuery();
assertEquals(playerStatsTable, query.getSource());
assertEquals(1, query.getMetricProjections().size());
String actual = query.getMetricProjections().stream().map(MetricProjection::getAlias).findFirst().orElse(null);
assertEquals("lowScore", actual);
assertEquals(1, query.getAllDimensionProjections().size());
List<ColumnProjection> dimensions = new ArrayList<>(query.getAllDimensionProjections());
assertEquals("overallRating", dimensions.get(0).getName());
}
use of com.yahoo.elide.datastores.aggregation.query.MetricProjection in project elide by yahoo.
the class DailyAverageScorePerPeriod method resolve.
@Override
public QueryPlan resolve(Query query) {
SQLTable table = (SQLTable) query.getSource();
MetricProjection innerMetric = table.getMetricProjection("highScore");
TimeDimension innerTimeGrain = table.getTimeDimension("recordedDate");
Map<String, Argument> arguments = new HashMap<>();
arguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
QueryPlan innerQuery = QueryPlan.builder().source(query.getSource()).metricProjection(innerMetric).timeDimensionProjection(new SQLTimeDimensionProjection(innerTimeGrain, innerTimeGrain.getTimezone(), "recordedDate_DAY", arguments, true)).build();
QueryPlan outerQuery = QueryPlan.builder().source(innerQuery).metricProjection(new DailyAverageScorePerPeriod(this, "AVG({{$highScore}})")).build();
return outerQuery;
}
use of com.yahoo.elide.datastores.aggregation.query.MetricProjection in project elide by yahoo.
the class EntityProjectionTranslator method addHavingMetrics.
/**
* Adds to the list of queried metrics any metric in the HAVING filter that has not been explicitly requested
* by the client.
*/
private void addHavingMetrics() {
if (havingFilter == null) {
return;
}
// Flatten the HAVING filter expression into a list of predicates...
havingFilter.accept(new PredicateExtractionVisitor()).forEach(filterPredicate -> {
String fieldName = filterPredicate.getField();
// If the predicate field is a metric
if (queriedTable.getMetric(fieldName) != null) {
// If the query doesn't contain this metric.
if (metrics.stream().noneMatch((metric -> metric.getName().equals(fieldName)))) {
// Construct a new projection and add it to the query.
MetricProjection havingMetric = engine.constructMetricProjection(queriedTable.getMetric(fieldName), fieldName, new HashMap<>());
metrics.add(havingMetric);
}
}
});
}
Aggregations