Search in sources :

Example 86 with Query

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

the class DruidExplainQueryTest method testExplainHavingMetricsOrDims.

@Test
public void testExplainHavingMetricsOrDims() throws Exception {
    Query query = TestQuery.HAVING_METRICS_OR_DIMS.getQuery();
    String expectedQueryStr = "SELECT MAX(\"example_PlayerStats\".\"highScore\") AS \"highScore\"," + "\"example_PlayerStats\".\"overallRating\" AS \"overallRating\" " + "FROM \"playerStats\" AS \"example_PlayerStats\" " + "GROUP BY \"example_PlayerStats\".\"overallRating\" " + "HAVING (\"example_PlayerStats\".\"overallRating\" IS NOT NULL " + "OR MAX(\"example_PlayerStats\".\"highScore\") > :XXX)";
    compareQueryLists(expectedQueryStr, engine.explain(query));
    testQueryExecution(TestQuery.HAVING_METRICS_OR_DIMS.getQuery());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Test(org.junit.jupiter.api.Test) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)

Example 87 with Query

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

the class DruidExplainQueryTest method testInnerJoin.

@Test
public void testInnerJoin() throws Exception {
    Query query = TestQuery.INNER_JOIN.getQuery();
    String expectedQueryStr = "SELECT DISTINCT \"example_VideoGame_playerInnerJoin_XXX\".\"name\" AS \"playerNameInnerJoin\" FROM \"videoGames\" AS \"example_VideoGame\"" + " INNER JOIN \"players\" AS \"example_VideoGame_playerInnerJoin_XXX\" ON \"example_VideoGame\".\"player_id\"" + " = \"example_VideoGame_playerInnerJoin_XXX\".\"id\"";
    compareQueryLists(expectedQueryStr, engine.explain(query));
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Test(org.junit.jupiter.api.Test) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)

Example 88 with Query

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

the class DruidExplainQueryTest method testExplainHavingMetricsOnly.

@Test
public void testExplainHavingMetricsOnly() throws Exception {
    Query query = TestQuery.HAVING_METRICS_ONLY.getQuery();
    String expectedQueryStr = "SELECT MIN(\"example_PlayerStats\".\"lowScore\") AS \"lowScore\" " + "FROM \"playerStats\" AS \"example_PlayerStats\" " + "HAVING MIN(\"example_PlayerStats\".\"lowScore\") > :XXX";
    compareQueryLists(expectedQueryStr, engine.explain(query));
    testQueryExecution(TestQuery.HAVING_METRICS_ONLY.getQuery());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Test(org.junit.jupiter.api.Test) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)

Example 89 with Query

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

the class DruidExplainQueryTest method testWhereWithArguments.

@Test
public void testWhereWithArguments() {
    Query query = TestQuery.WHERE_WITH_ARGUMENTS.getQuery();
    String queryStr = engine.explain(query).get(0);
    queryStr = repeatedWhitespacePattern.matcher(queryStr).replaceAll(" ");
    String expectedStr = getExpectedWhereWithArgumentsSQL().replace(BACKTICK, DOUBLE_QUOTE);
    assertEquals(expectedStr, queryStr);
    testQueryExecution(query);
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Test(org.junit.jupiter.api.Test) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)

Example 90 with Query

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

the class EntityHydratorTest method testNullEnumHydration.

@Test
void testNullEnumHydration() throws Exception {
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
    when(resultSet.next()).thenReturn(true, false);
    when(resultSet.getObject("overallRating")).thenReturn(null);
    when(resultSetMetaData.getColumnCount()).thenReturn(1);
    Query query = Query.builder().source(playerStatsTable).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).build();
    EntityHydrator hydrator = new EntityHydrator(resultSet, query, dictionary);
    Iterator<Object> iterator = hydrator.iterator();
    assertTrue(iterator.hasNext());
    PlayerStats stats = (PlayerStats) iterator.next();
    assertNull(stats.getOverallRating());
    assertFalse(iterator.hasNext());
    assertThrows(NoSuchElementException.class, () -> hydrator.iterator().next());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Query(com.yahoo.elide.datastores.aggregation.query.Query) ResultSet(java.sql.ResultSet) PlayerStats(example.PlayerStats) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) 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