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));
}
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));
}
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());
}
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());
}
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;
}
Aggregations