Search in sources :

Example 46 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query 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 47 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query 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 48 with Query

use of com.yahoo.elide.datastores.aggregation.query.Query 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)

Example 49 with Query

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

the class JoinJoinTable method testArgumentsInJoinExprCase3.

// Both dim4 and dim5 passes same value for join expression's argument 'exprArg'
// dim4 and dim5 passes different value for join table's column argument 'joinArg'
// 2 Join expressions are generated.
@Test
void testArgumentsInJoinExprCase3() {
    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 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("joinArg", Argument.builder().name("joinArg").value("foo5").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_201179732`.`dim1` AS `dim4`," + NL + "           `MainTable_join2_201179856`.`dim1` AS `dim5` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_201179732` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_201179732`.`dim4` - 'foo4' " + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_201179856` " + NL + "ON " + NL + "  value = 'same' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_201179856`.`dim4` - 'foo5' ";
    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 50 with Query

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

the class JoinJoinTable method testArgumentsInJoinExprCase2b.

// dim4x and dim5x passes different value for join expression's argument 'exprArg'
// 1 Join expression is generated as they invoke dim4 and dim5 using sql helper with same value
@Test
void testArgumentsInJoinExprCase2b() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
    SQLDimensionProjection dim4x = (SQLDimensionProjection) table.getDimensionProjection("dim4x", "dim4x", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
    SQLDimensionProjection dim5x = (SQLDimensionProjection) table.getDimensionProjection("dim5x", "dim5x", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4x).dimensionProjection(dim5x).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2_156385021`.`dim1` - 'value4' AS `dim4x`," + NL + "           `MainTable_join2_156385021`.`dim1` - 'value5' AS `dim5x` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_156385021` " + NL + "ON " + NL + "  value = 'fixedExpr' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_156385021`.`dim4` - 'fixedArg' ";
    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

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