Search in sources :

Example 11 with Argument

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

the class AggregateBeforeJoinOptimizerTest method testHavingOnTimeDimensionInProjectionNotRequiringJoinWithArguments.

@Test
public void testHavingOnTimeDimensionInProjectionNotRequiringJoinWithArguments() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Set<Argument> arguments = new HashSet<>();
    arguments.add(Argument.builder().name("grain").value("MONTH").build());
    FilterExpression expression = new OrFilterExpression(new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000)), 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", arguments)).havingFilter(expression).build();
    compareQueryLists("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-01'), 'yyyy-MM-dd') AS `saleDate` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`country_id`, " + "PARSEDATETIME(FORMATDATETIME(`example_GameRevenue`.`saleDate`, 'yyyy-MM-01'), '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 " + "OR `example_GameRevenue_XXX`.`saleDate` IN (:XXX))\n", engine.explain(query));
    testQueryExecution(query);
}
Also used : Path(com.yahoo.elide.core.Path) Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) Date(java.util.Date) HashSet(java.util.HashSet) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 12 with Argument

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

the class QueryEngineTest method testMultipleTimeGrainsFilteredByDayAlias.

@Test
public void testMultipleTimeGrainsFilteredByDayAlias() 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", "byDay", new HashSet<>(dayArguments.values())), Operator.IN, Lists.newArrayList(new Day(Date.valueOf("2019-07-11"))));
    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(1, results.size());
    assertEquals(2412, results.get(0).getHighScore());
    assertEquals(new Day(Date.valueOf("2019-07-11")), results.get(0).fetch("byDay", null));
    assertEquals(new Month(Date.valueOf("2019-07-01")), results.get(0).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 13 with Argument

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

the class JoinJoinTable method testArgumentsInJoinExprCase5a.

// Both dim4a and dim5a passes same value for join expression's argument 'exprArg'
// dim4a and dim5a passes different value for join table's column argument 'joinArg'
// 1 Join expressions is generated as fixed value of joinArg is used while calling join table's column.
@Test
void testArgumentsInJoinExprCase5a() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    dim4Arg.put("joinArg", Argument.builder().name("joinArg").value("foo4").build());
    SQLDimensionProjection dim4a = (SQLDimensionProjection) table.getDimensionProjection("dim4a", "dim4a", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    dim5Arg.put("joinArg", Argument.builder().name("joinArg").value("foo5").build());
    SQLDimensionProjection dim5a = (SQLDimensionProjection) table.getDimensionProjection("dim5a", "dim5a", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4a).dimensionProjection(dim5a).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2a_157775546`.`dim1` AS `dim4a`," + NL + "           `MainTable_join2a_157775546`.`dim1` AS `dim5a` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2a_157775546` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2a_157775546`.`dim4` - 'fixedFoo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 14 with Argument

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

the class JoinJoinTable method testArgumentsInJoinExprCase1.

// Both dim4 and dim5 passes same value for join expression's argument 'exprArg'
// Single Join expression is generated.
@Test
void testArgumentsInJoinExprCase1() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    SQLDimensionProjection dim4 = (SQLDimensionProjection) table.getDimensionProjection("dim4", "dim4", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    SQLDimensionProjection dim5 = (SQLDimensionProjection) table.getDimensionProjection("dim5", "dim5", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4).dimensionProjection(dim5).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2_201179280`.`dim1` AS `dim4`," + NL + "           `MainTable_join2_201179280`.`dim1` AS `dim5` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_201179280` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_201179280`.`dim4` - 'foo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 15 with Argument

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

the class JoinJoinTable method testArgumentsInJoinExprCase4.

// Both dim4 and dim5 passes same value for join expression's argument 'exprArg'
// dim4 and dim5 passes different value for column argument 'arg6'
// 2 Join expressions are generated.
@Test
void testArgumentsInJoinExprCase4() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    dim4Arg.put("arg6", Argument.builder().name("arg6").value("bar4").build());
    SQLDimensionProjection dim4 = (SQLDimensionProjection) table.getDimensionProjection("dim4", "dim4", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("same").build());
    dim5Arg.put("arg6", Argument.builder().name("arg6").value("bar5").build());
    SQLDimensionProjection dim5 = (SQLDimensionProjection) table.getDimensionProjection("dim5", "dim5", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4).dimensionProjection(dim5).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2_148518185`.`dim1` AS `dim4`," + NL + "           `MainTable_join2_209848490`.`dim1` AS `dim5` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_148518185` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar4' = `MainTable_join2_148518185`.`dim4` - 'foo' " + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_209848490` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar5' = `MainTable_join2_209848490`.`dim4` - 'foo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) 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