use of com.yahoo.elide.core.request.Argument 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.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method conjunctionMatchesTest.
@Test
public void conjunctionMatchesTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("lowScore>100;highScore=={{variable}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
Argument expected = Argument.builder().name("variable").value(123L).build();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(1, extractedArgs.size());
assertEquals(extractedArgs.get("variable"), expected);
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method mulipleConjunctionOrderTest.
@Test
public void mulipleConjunctionOrderTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;(highScore>=100;highScore<999)", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore>={{low}};highScore<{{high}}", playerStatsType, false, true);
Argument expected1 = Argument.builder().name("low").value(100L).build();
Argument expected2 = Argument.builder().name("high").value(999L).build();
Map<String, Argument> extractedArgs = new HashMap<>();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(2, extractedArgs.size());
assertEquals(extractedArgs.get("low"), expected1);
assertEquals(extractedArgs.get("high"), expected2);
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method parameterizedFilterArgumentsDoNotMatch.
@Test
public void parameterizedFilterArgumentsDoNotMatch() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("recordedDate[grain:day]=='2020-01-01'", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("recordedDate[grain:month]=={{day}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method predicateWithAliasMatchesTest.
@Test
public void predicateWithAliasMatchesTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
Attribute attribute = Attribute.builder().type(ClassType.of(Long.class)).name("highScore").alias("myScore").build();
FilterExpression templateExpression = dialect.parseFilterExpression("myScore=={{foo}}", playerStatsType, false, true, Set.of(attribute));
Map<String, Argument> extractedArgs = new HashMap<>();
Argument expected = Argument.builder().name("foo").value(123L).build();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(1, extractedArgs.size());
assertEquals(extractedArgs.get("foo"), expected);
}
Aggregations