use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnTimeDimensionNotInProjectionRequiringJoinWithArguments.
@Test
public void testWhereOnTimeDimensionNotInProjectionRequiringJoinWithArguments() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
Set<Argument> arguments = new HashSet<>();
arguments.add(Argument.builder().name("grain").value("MONTH").build());
FilterExpression where = new FilterPredicate(new Path(GameRevenue.class, dictionary, "sessionDate", "sessionDate", arguments), Operator.IN, Arrays.asList(new Day(new Date())));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).whereFilter(where).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`player_stats_id` AS `player_stats_id` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`player_stats_id` ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `playerStats` AS `example_GameRevenue_XXX_playerStats_XXX` " + "ON `example_GameRevenue_XXX`.`player_stats_id` = `example_GameRevenue_XXX_playerStats_XXX`.`id` " + "WHERE PARSEDATETIME(FORMATDATETIME(`example_GameRevenue_XXX_playerStats_XXX`.`recordedDate`, 'yyyy-MM-01'), 'yyyy-MM-dd') IN (:XXX)\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnTimeDimensionInProjectionNotRequiringJoinWithMismatchingArguments.
@Test
public void testWhereOnTimeDimensionInProjectionNotRequiringJoinWithMismatchingArguments() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
Set<Argument> arguments = new HashSet<>();
arguments.add(Argument.builder().name("grain").value("MONTH").build());
FilterExpression having = new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000));
FilterExpression where = new FilterPredicate(new Path(GameRevenue.class, dictionary, "saleDate", "saleDate", arguments), Operator.IN, Arrays.asList(new Day(new Date())));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("saleDate")).havingFilter(having).whereFilter(where).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "`example_GameRevenue_XXX_country_XXX`.`iso_code` AS `countryIsoCode`," + "`example_GameRevenue_XXX`.`saleDate` AS `saleDate` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id`," + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `saleDate` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "WHERE PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-01'), 'yyyy-MM-dd') IN (:XXX) " + "GROUP BY `example_GameRevenue`.`country_id`, " + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-dd'), 'yyyy-MM-dd') ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `countries` AS `example_GameRevenue_XXX_country_XXX` " + "ON `example_GameRevenue_XXX`.`country_id` = `example_GameRevenue_XXX_country_XXX`.`id` " + "GROUP BY `example_GameRevenue_XXX_country_XXX`.`iso_code`, " + "`example_GameRevenue_XXX`.`saleDate` " + "HAVING MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX\n";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.Path 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.Path in project elide by yahoo.
the class ExpressionParser method buildJoin.
private JoinReference buildJoin(Queryable source, String referenceName, Map<String, Argument> callingColumnArgs, Map<String, Argument> fixedArguments) {
Queryable root = source.getRoot();
Type<?> tableClass = dictionary.getEntityClass(root.getName(), root.getVersion());
JoinPath joinPath = new JoinPath(tableClass, metaDataStore, referenceName);
Path.PathElement lastElement = joinPath.lastElement().get();
Queryable joinSource = metaDataStore.getTable(lastElement.getType());
String fieldName = lastElement.getFieldName();
Reference reference;
if (fieldName.startsWith("$")) {
reference = PhysicalReference.builder().source(joinSource).name(fieldName.substring(1)).build();
} else {
ColumnProjection referencedColumn = joinSource.getColumnProjection(fieldName);
ColumnProjection newColumn = referencedColumn.withArguments(mergedArgumentMap(referencedColumn.getArguments(), callingColumnArgs, fixedArguments));
reference = LogicalReference.builder().source(joinSource).column(newColumn).references(buildReferenceForColumn(joinSource, newColumn)).build();
}
return JoinReference.builder().path(joinPath).source(source).reference(reference).build();
}
use of com.yahoo.elide.core.Path in project elide by yahoo.
the class EntityProjectionMaker method visitIncludePath.
public EntityProjection visitIncludePath(Path path) {
Path.PathElement pathElement = path.getPathElements().get(0);
int size = path.getPathElements().size();
Type<?> entityClass = pathElement.getFieldType();
if (size > 1) {
Path nextPath = new Path(path.getPathElements().subList(1, size));
EntityProjection relationshipProjection = visitIncludePath(nextPath);
return EntityProjection.builder().relationships(toRelationshipSet(getSparseRelationships(entityClass))).relationship(nextPath.getPathElements().get(0).getFieldName(), relationshipProjection).attributes(getSparseAttributes(entityClass)).filterExpression(scope.getFilterExpressionByType(entityClass).orElse(null)).type(entityClass).arguments(getDefaultEntityArguments(entityClass)).build();
}
return EntityProjection.builder().relationships(toRelationshipSet(getSparseRelationships(entityClass))).attributes(getSparseAttributes(entityClass)).type(entityClass).arguments(getDefaultEntityArguments(entityClass)).filterExpression(scope.getFilterExpressionByType(entityClass).orElse(null)).build();
}
Aggregations