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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations