Search in sources :

Example 11 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicateExtractionVisitorTest method testPredicateExtraction.

@Test
public void testPredicateExtraction() throws Exception {
    Path p1Path = new Path(Arrays.asList(new Path.PathElement(Book.class, Author.class, "authors"), new Path.PathElement(Author.class, String.class, "name")));
    FilterPredicate p1 = new InPredicate(p1Path, "foo", "bar");
    Path p2Path = new Path(Arrays.asList(new Path.PathElement(Book.class, String.class, "name")));
    FilterPredicate p2 = new InPredicate(p2Path, "blah");
    Path p3Path = new Path(Arrays.asList(new Path.PathElement(Book.class, String.class, "genre")));
    FilterPredicate p3 = new InPredicate(p3Path, "scifi");
    // P4 is a duplicate of P3
    Path p4Path = new Path(Arrays.asList(new Path.PathElement(Book.class, String.class, "genre")));
    FilterPredicate p4 = new InPredicate(p4Path, "scifi");
    OrFilterExpression or = new OrFilterExpression(p2, p3);
    AndFilterExpression and1 = new AndFilterExpression(or, p1);
    AndFilterExpression and2 = new AndFilterExpression(and1, p4);
    NotFilterExpression not = new NotFilterExpression(and2);
    // First test collecting the predicates in a Set
    PredicateExtractionVisitor visitor = new PredicateExtractionVisitor();
    Collection<FilterPredicate> filterPredicates = not.accept(visitor);
    assertTrue(filterPredicates.containsAll(Sets.newHashSet(p1, p2, p3)));
    assertEquals(filterPredicates.size(), 3);
    // Second test collecting the predicates in a List
    visitor = new PredicateExtractionVisitor(new ArrayList<>());
    filterPredicates = not.accept(visitor);
    assertTrue(filterPredicates.containsAll(Arrays.asList(p1, p2, p3, p4)));
    assertEquals(filterPredicates.size(), 4);
}
Also used : Path(com.yahoo.elide.core.Path) ArrayList(java.util.ArrayList) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 12 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testAndPartialPredicateExtraction.

@Test
public void testAndPartialPredicateExtraction() {
    FilterExpression dataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    FilterExpression anotherDataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Science Fiction");
    FilterExpression expectedExpression = new AndFilterExpression(dataStoreExpression, anotherDataStoreExpression);
    FilterExpression inMemoryExpression = new InPredicate(new Path(Book.class, dictionary, "editor.firstName"), "Jack");
    FilterExpression finalExpression = new AndFilterExpression(new AndFilterExpression(dataStoreExpression, inMemoryExpression), anotherDataStoreExpression);
    FilterExpression extracted = FilterPredicatePushdownExtractor.extractPushDownPredicate(dictionary, finalExpression);
    assertEquals(expectedExpression, extracted);
}
Also used : Path(com.yahoo.elide.core.Path) Book(example.Book) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 13 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testNoPredicateExtraction.

@Test
public void testNoPredicateExtraction() {
    FilterExpression dataStoreExpression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    FilterExpression inMemoryExpression = new InPredicate(new Path(Book.class, dictionary, "editor.firstName"), "Literary Fiction");
    FilterExpression finalExpression = new NotFilterExpression(new AndFilterExpression(dataStoreExpression, inMemoryExpression));
    FilterExpression extracted = FilterPredicatePushdownExtractor.extractPushDownPredicate(dictionary, finalExpression);
    assertNull(extracted);
}
Also used : Path(com.yahoo.elide.core.Path) Book(example.Book) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 14 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class FilterPredicatePushdownExtractorTest method testFullPredicateExtraction.

@Test
public void testFullPredicateExtraction() {
    FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
    FilterExpression extracted = FilterPredicatePushdownExtractor.extractPushDownPredicate(dictionary, expression);
    assertEquals(expression, extracted);
}
Also used : Path(com.yahoo.elide.core.Path) Book(example.Book) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Test(org.junit.jupiter.api.Test)

Example 15 with Path

use of com.yahoo.elide.core.Path in project elide by yahoo.

the class AggregateBeforeJoinOptimizerTest method testWhereOnTimeDimensionInProjectionNotRequiringJoinWithDefaultMatchingArguments.

@Test
public void testWhereOnTimeDimensionInProjectionNotRequiringJoinWithDefaultMatchingArguments() {
    SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
    Set<Argument> arguments = new HashSet<>();
    arguments.add(Argument.builder().name("grain").value("DAY").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-dd'), '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);
}
Also used : Path(com.yahoo.elide.core.Path) Argument(com.yahoo.elide.core.request.Argument) 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) 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)

Aggregations

Path (com.yahoo.elide.core.Path)88 Test (org.junit.jupiter.api.Test)67 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)51 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)41 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)35 Query (com.yahoo.elide.datastores.aggregation.query.Query)35 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)34 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)33 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)31 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)29 Book (example.Book)29 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)22 Date (java.util.Date)19 Argument (com.yahoo.elide.core.request.Argument)14 EntityProjection (com.yahoo.elide.core.request.EntityProjection)14 GameRevenue (example.GameRevenue)14 HashSet (java.util.HashSet)14 Author (example.Author)12 Publisher (example.Publisher)9 Sorting (com.yahoo.elide.core.request.Sorting)8