Search in sources :

Example 26 with Argument

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;
}
Also used : SQLMetricProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection) MetricProjection(com.yahoo.elide.datastores.aggregation.query.MetricProjection) Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) SQLTimeDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLTimeDimensionProjection) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) QueryPlan(com.yahoo.elide.datastores.aggregation.query.QueryPlan)

Example 27 with Argument

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);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 28 with Argument

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);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 29 with Argument

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());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 30 with Argument

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);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Aggregations

Argument (com.yahoo.elide.core.request.Argument)71 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)48 Query (com.yahoo.elide.datastores.aggregation.query.Query)38 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)35 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)25 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)22 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)15 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)14 HashSet (java.util.HashSet)14 Path (com.yahoo.elide.core.Path)12 ToString (lombok.ToString)12 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)11 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)10 Date (java.util.Date)10 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)9 GameRevenue (example.GameRevenue)7 PlayerStats (example.PlayerStats)6 SQLMetricProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection)5 Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)5