Search in sources :

Example 36 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class AggregationDataStoreTransactionTest method testMissingRequiredColumnFilter.

@Test
public void testMissingRequiredColumnFilter() throws Exception {
    Type<PlayerStatsWithRequiredFilter> tableType = ClassType.of(PlayerStatsWithRequiredFilter.class);
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
    SQLTable table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), tableType, dictionary);
    Query query = Query.builder().column(SQLMetricProjection.builder().name("highScore").build()).source(table).build();
    AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    assertThrows(BadRequestException.class, () -> tx.addColumnFilterArguments(table, query, dictionary));
}
Also used : PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 37 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class DefaultQueryValidatorTest method testMissingRequiredParameterInProjection.

@Test
public void testMissingRequiredParameterInProjection() {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName")).build();
    validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' is required");
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 38 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class SubqueryFilterSplitter method visitPredicate.

@Override
public SplitFilter visitPredicate(FilterPredicate filterPredicate) {
    Type<?> tableType = filterPredicate.getEntityType();
    String fieldName = filterPredicate.getField();
    SQLTable table = metaDataStore.getTable(tableType);
    List<Reference> references = parser.parse(table, table.getColumnProjection(fieldName));
    boolean hasJoin = references.stream().anyMatch(ref -> ref.accept(new HasJoinVisitor()));
    if (hasJoin) {
        return SplitFilter.builder().outer(filterPredicate).build();
    }
    return SplitFilter.builder().inner(filterPredicate).build();
}
Also used : Reference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) HasJoinVisitor(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.HasJoinVisitor)

Example 39 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class DailyAverageScorePerPeriod method resolve.

@Override
public QueryPlan resolve(Query query) {
    SQLTable table = (SQLTable) query.getSource();
    MetricProjection innerMetric = table.getMetricProjection("highScore");
    TimeDimension innerTimeGrain = table.getTimeDimension("recordedDate");
    Map<String, Argument> arguments = new HashMap<>();
    arguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
    QueryPlan innerQuery = QueryPlan.builder().source(query.getSource()).metricProjection(innerMetric).timeDimensionProjection(new SQLTimeDimensionProjection(innerTimeGrain, innerTimeGrain.getTimezone(), "recordedDate_DAY", arguments, true)).build();
    QueryPlan outerQuery = QueryPlan.builder().source(innerQuery).metricProjection(new DailyAverageScorePerPeriod(this, "AVG({{$highScore}})")).build();
    return outerQuery;
}
Also used : SQLMetricProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection) MetricProjection(com.yahoo.elide.datastores.aggregation.query.MetricProjection) Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) SQLTimeDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLTimeDimensionProjection) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) QueryPlan(com.yahoo.elide.datastores.aggregation.query.QueryPlan)

Example 40 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testWhereOnDimensionInProjectionNotRequiringJoin.

@Test
public void testWhereOnDimensionInProjectionNotRequiringJoin() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    FilterExpression having = new FilterPredicate(new Path(GameRevenue.class, dictionary, "revenue"), Operator.GT, Arrays.asList(9000));
    FilterExpression where = new FilterPredicate(new Path(GameRevenue.class, dictionary, "category"), Operator.IN, Arrays.asList("foo"));
    Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).dimensionProjection(gameRevenueTable.getDimensionProjection("countryIsoCode")).dimensionProjection(gameRevenueTable.getDimensionProjection("category")).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`.`category` AS `category` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`country_id` AS `country_id`," + "`example_GameRevenue`.`category` AS `category` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "WHERE `example_GameRevenue`.`category` IN (:XXX) " + "GROUP BY `example_GameRevenue`.`country_id`, " + "`example_GameRevenue`.`category` ) " + "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`.`category` " + "HAVING MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) > :XXX\n";
    compareQueryLists(expected, engine.explain(query));
    testQueryExecution(query);
}
Also used : Path(com.yahoo.elide.core.Path) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) GameRevenue(example.GameRevenue) 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) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)76 Test (org.junit.jupiter.api.Test)59 Query (com.yahoo.elide.datastores.aggregation.query.Query)50 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)49 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)34 Path (com.yahoo.elide.core.Path)31 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)31 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)29 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)29 Argument (com.yahoo.elide.core.request.Argument)24 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)20 Date (java.util.Date)19 GameRevenue (example.GameRevenue)15 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)12 HashSet (java.util.HashSet)12 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)8 Namespace (com.yahoo.elide.datastores.aggregation.metadata.models.Namespace)8 HashMap (java.util.HashMap)8 TreeMap (java.util.TreeMap)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7