Search in sources :

Example 71 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query 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());
}
Also used : MetricProjection(com.yahoo.elide.datastores.aggregation.query.MetricProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) ArrayList(java.util.ArrayList) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 72 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class EntityProjectionTranslatorTest method testQueryArguments.

@Test
public void testQueryArguments() {
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, basicProjection, scope, true);
    Query query = translator.getQuery();
    Argument queryArg = query.getArguments().get("foo");
    assertEquals("bar", queryArg.getValue());
    Argument lowScoreArg = query.getColumnProjection("lowScore").getArguments().get("foo");
    assertEquals("bar", lowScoreArg.getValue());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Argument(com.yahoo.elide.core.request.Argument) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 73 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class EntityProjectionTranslatorTest method testHavingClauseMetricsMissingFromProjection.

@Test
public void testHavingClauseMetricsMissingFromProjection() throws ParseException {
    FilterExpression filter = filterParser.parseFilterExpression("lowScore>45", playerStatsType, false);
    EntityProjection projection = EntityProjection.builder().type(PlayerStats.class).filterExpression(filter).attribute(Attribute.builder().type(long.class).name("highScore").build()).attribute(Attribute.builder().type(String.class).name("overallRating").build()).build();
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
    Query query = translator.getQuery();
    List<String> metricNames = query.getMetricProjections().stream().map(MetricProjection::getName).collect(Collectors.toList());
    assertEquals(metricNames, Arrays.asList("highScore", "lowScore"));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 74 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class EntityProjectionTranslatorTest method testTimeDimension.

@Test
public void testTimeDimension() {
    EntityProjection projection = basicProjection.copyOf().attribute(Attribute.builder().type(Date.class).name("recordedDate").build()).build();
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
    Query query = translator.getQuery();
    List<TimeDimensionProjection> timeDimensions = new ArrayList<>(query.getTimeDimensionProjections());
    assertEquals(1, timeDimensions.size());
    assertEquals("recordedDate", timeDimensions.get(0).getAlias());
    assertEquals(TimeGrain.DAY, timeDimensions.get(0).getGrain());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) TimeDimensionProjection(com.yahoo.elide.datastores.aggregation.query.TimeDimensionProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) ArrayList(java.util.ArrayList) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 75 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query in project elide by yahoo.

the class QueryKeyExtractorTest method testMinimalQuery.

@Test
public void testMinimalQuery() {
    // check for proper handling of unset Query fields
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).build();
    assertEquals("example_PlayerStats;{highScore;{}}{}{};;;;", QueryKeyExtractor.extractKey(query));
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

Query (com.yahoo.elide.datastores.aggregation.query.Query)242 Test (org.junit.jupiter.api.Test)229 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)214 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)51 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)46 Argument (com.yahoo.elide.core.request.Argument)43 ArrayList (java.util.ArrayList)42 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)37 Path (com.yahoo.elide.core.Path)35 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)31 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)29 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)29 PlayerStats (example.PlayerStats)29 TreeMap (java.util.TreeMap)29 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)28 HashMap (java.util.HashMap)26 Date (java.util.Date)19 HashSet (java.util.HashSet)17 ToString (lombok.ToString)16 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)14