Search in sources :

Example 46 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class SQLColumnProjectionTest method testColumnArgsColumnThatCanNest.

@Test
public void testColumnArgsColumnThatCanNest() throws Exception {
    SQLTable table = metaDataStore.getTable(ClassType.of(TableA.class));
    Map<String, Argument> args = new HashMap<>();
    args.put("foo", Argument.builder().name("foo").value("bar").build());
    ColumnProjection projection = table.getColumnProjection("dim2", args);
    assertTrue(projection.canNest(table, metaDataStore));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) Test(org.junit.jupiter.api.Test)

Example 47 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class QueryEngineTest method testMultipleTimeGrainsFilteredByMonthAlias.

@Test
public void testMultipleTimeGrainsFilteredByMonthAlias() throws Exception {
    Map<String, Argument> dayArguments = new HashMap<>();
    dayArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
    Map<String, Argument> monthArguments = new HashMap<>();
    monthArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.MONTH).build());
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("highScore", Sorting.SortOrder.asc);
    FilterPredicate predicate = new FilterPredicate(new Path(ClassType.of(PlayerStats.class), dictionary, "recordedDate", "byMonth", new HashSet<>(monthArguments.values())), Operator.IN, Lists.newArrayList(new Day(Date.valueOf("2019-07-01"))));
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).whereFilter(predicate).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
    List<PlayerStats> results = toList(engine.executeQuery(query, transaction).getData());
    assertEquals(3, results.size());
    assertEquals(1000, results.get(0).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-13")), results.get(0).fetch("byDay", null));
    assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(0).fetch("byMonth", null));
    assertEquals(1234, results.get(1).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-12")), results.get(1).fetch("byDay", null));
    assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(1).fetch("byMonth", null));
    assertEquals(2412, results.get(2).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-11")), results.get(2).fetch("byDay", null));
    assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(2).fetch("byMonth", null));
}
Also used : Path(com.yahoo.elide.core.Path) Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) PlayerStats(example.PlayerStats) TreeMap(java.util.TreeMap) Month(com.yahoo.elide.datastores.aggregation.timegrains.Month) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) HashSet(java.util.HashSet) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 48 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class EntityHydratorTest method testTimeDimensionHydration.

@Test
void testTimeDimensionHydration() throws Exception {
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.next()).thenReturn(true, false);
    when(resultSet.getObject("highScore")).thenReturn(1234);
    when(resultSet.getObject(createSafeAlias("recordedDate", "byDay"))).thenReturn(new Date(1612390856));
    when(resultSet.getObject(createSafeAlias("recordedDate", "byMonth"))).thenReturn(new Date(1612390856));
    when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
    when(resultSetMetaData.getColumnCount()).thenReturn(3);
    Map<String, Argument> monthArguments = new HashMap<>();
    monthArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.MONTH).build());
    Map<String, Argument> dayArguments = new HashMap<>();
    dayArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).build();
    EntityHydrator hydrator = new EntityHydrator(resultSet, query, dictionary);
    Iterator<Object> iterator = hydrator.iterator();
    assertTrue(iterator.hasNext());
    PlayerStats stats = (PlayerStats) iterator.next();
    assertEquals(Month.class, stats.fetch("byMonth", null).getClass());
    assertEquals(Day.class, stats.fetch("byDay", null).getClass());
    assertFalse(iterator.hasNext());
    assertThrows(NoSuchElementException.class, () -> hydrator.iterator().next());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PlayerStats(example.PlayerStats) Date(java.sql.Date) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 49 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class EntityHydratorTest method testEmptyResponse.

@Test
void testEmptyResponse() throws Exception {
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.next()).thenReturn(false);
    Map<String, Argument> monthArguments = new HashMap<>();
    monthArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.MONTH).build());
    Map<String, Argument> dayArguments = new HashMap<>();
    dayArguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byMonth", monthArguments)).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate", "byDay", dayArguments)).build();
    EntityHydrator hydrator = new EntityHydrator(resultSet, query, dictionary);
    Iterator<Object> iterator = hydrator.iterator();
    assertFalse(iterator.hasNext());
    assertThrows(NoSuchElementException.class, () -> hydrator.iterator().next());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 50 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class AggregationDataStoreTransaction method addTableFilterArguments.

@VisibleForTesting
Query addTableFilterArguments(Table table, Query query, EntityDictionary dictionary) {
    FilterExpression filterTemplate = table.getRequiredFilter(dictionary);
    Query modifiedQuery = query;
    if (filterTemplate != null) {
        Map<String, Argument> allArguments = validateRequiredFilter(filterTemplate, query, table);
        if (!allArguments.isEmpty()) {
            if (query.getArguments() != null) {
                allArguments.putAll(query.getArguments());
            }
            modifiedQuery = Query.builder().query(query).arguments(allArguments).build();
        }
    }
    return modifiedQuery;
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Argument(com.yahoo.elide.core.request.Argument) ToString(lombok.ToString) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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