use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class AggregateBeforeJoinOptimizerTest method testWhereOnMultiReferenceTimeDimensionInProjection.
@Test
public void testWhereOnMultiReferenceTimeDimensionInProjection() {
SQLTable gameRevenueTable = (SQLTable) metaDataStore.getTable("gameRevenue", NO_VERSION);
FilterExpression where = new AndFilterExpression(new FilterPredicate(new Path(GameRevenue.class, dictionary, "countryIsoCode"), Operator.IN, Arrays.asList("foo")), new FilterPredicate(new Path(GameRevenue.class, dictionary, "lastDate"), Operator.IN, Arrays.asList(new Day(new Date()))));
Query query = Query.builder().source(gameRevenueTable).metricProjection(gameRevenueTable.getMetricProjection("revenue")).timeDimensionProjection(gameRevenueTable.getTimeDimensionProjection("lastDate")).whereFilter(where).build();
String expected = "SELECT MAX(`example_GameRevenue_XXX`.`INNER_AGG_XXX`) AS `revenue`," + "PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd') AS `lastDate` " + "FROM (SELECT MAX(`example_GameRevenue`.`revenue`) AS `INNER_AGG_XXX`," + "`example_GameRevenue`.`player_stats_id` AS `player_stats_id`," + "`example_GameRevenue`.`saleDate` AS `saleDate`," + "`example_GameRevenue`.`country_id` AS `country_id` " + "FROM `gameRevenue` AS `example_GameRevenue` " + "GROUP BY `example_GameRevenue`.`player_stats_id`, " + "`example_GameRevenue`.`saleDate`, " + "`example_GameRevenue`.`country_id` ) " + "AS `example_GameRevenue_XXX` " + "LEFT OUTER JOIN `playerStats` AS `example_GameRevenue_XXX_playerStats_XXX` " + "ON `example_GameRevenue_XXX`.`player_stats_id` = `example_GameRevenue_XXX_playerStats_XXX`.`id` " + "LEFT OUTER JOIN `countries` AS `example_GameRevenue_XXX_country_XXX` " + "ON `example_GameRevenue_XXX`.`country_id` = `example_GameRevenue_XXX_country_XXX`.`id` " + "WHERE (`example_GameRevenue_XXX_country_XXX`.`iso_code` IN (:XXX) " + "AND PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd') IN (:XXX)) " + "GROUP BY PARSEDATETIME(FORMATDATETIME(CASE WHEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` > `example_GameRevenue_XXX`.`saleDate` THEN `example_GameRevenue_XXX_playerStats_XXX`.`recordedDate` ELSE `example_GameRevenue_XXX`.`saleDate` END, 'yyyy-MM-dd'), 'yyyy-MM-dd')";
compareQueryLists(expected, engine.explain(query));
testQueryExecution(query);
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class SplitFilterExpressionVisitor method visitAndExpression.
@Override
public FilterConstraints visitAndExpression(final AndFilterExpression expression) {
/*
* Definition:
* C = condition
* pure-W = WHERE C
* pure-H = HAVING C
* mix-HW = WHERE C HAVING C'
*
* Given that L and R operands of an AndFilterExpression can only be one of "pure-H", "pure-W", or "mix-HW",
* then:
*
* pure-W1 AND pure-W2 = WHERE C1 AND WHERE C2 = WHERE (C1 AND C2) = pure-W
* pure-H1 AND pure-H2 = HAVING C1 AND HAVING C2 = HAVING (C1 AND C2) = pure-H
*
* pure-H1 AND pureW2 = HAVING C1 AND WHERE C2 = WHERE C2 HAVING C1 = mix-HW
* pure-W1 AND pureH2 = WHERE C1 HAVING C2 = mix-HW
*
* mix-HW1 AND pure-W2 = WHERE C1 HAVING C1' AND WHERE C2 = WHERE (C1 & C2) HAVING C1' = mix-HW
* mix-HW1 AND pure-H2 = WHERE C1 HAVING C1' AND HAVING C2 = WHERE C1 HAVING (C1' & C2) = mix-HW
*
* mix-HW1 AND mim-HW2 = WHERE C1 HAVING C1' AND WHERE C2 HAVING C2' = WHERE (C1 & C2) HAVING (C1' & C2')
* = mix-HW
*/
FilterConstraints left = expression.getLeft().accept(this);
FilterConstraints right = expression.getRight().accept(this);
if (left.isPureWhere() && right.isPureWhere()) {
// pure-W1 AND pure-W2 = WHERE (C1 & C2) = pure-W
return FilterConstraints.pureWhere(new AndFilterExpression(left.getWhereExpression(), right.getWhereExpression()));
}
if (left.isPureHaving() && right.isPureHaving()) {
// pure-H1 AND pure-H2 = HAVING (C1 AND C2) = pure-H
return FilterConstraints.pureHaving(new AndFilterExpression(left.getHavingExpression(), right.getHavingExpression()));
}
// all of the rests are mix-HW
return FilterConstraints.withWhereAndHaving(AndFilterExpression.fromPair(left.getWhereExpression(), right.getWhereExpression()), AndFilterExpression.fromPair(left.getHavingExpression(), right.getHavingExpression()));
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class PermissionToFilterExpressionVisitorTest method testTestMethods.
@Test
public void testTestMethods() {
List<FilterExpression> unfilterable = Arrays.asList(FALSE_USER_CHECK_EXPRESSION, TRUE_USER_CHECK_EXPRESSION, NO_EVALUATION_EXPRESSION);
for (FilterExpression e : unfilterable) {
assertTrue(isSpecialCase(e), String.format("isSpecialCase(%s)", e));
}
assertTrue(containsOnlyFilterableExpressions(new AndFilterExpression(IN_PREDICATE, NOT_IN_PREDICATE)));
assertTrue(containsOnlyFilterableExpressions(new OrFilterExpression(IN_PREDICATE, NOT_IN_PREDICATE)));
assertFalse(containsOnlyFilterableExpressions(new AndFilterExpression(IN_PREDICATE, FALSE_USER_CHECK_EXPRESSION)));
assertFalse(containsOnlyFilterableExpressions(new OrFilterExpression(IN_PREDICATE, FALSE_USER_CHECK_EXPRESSION)));
assertFalse(containsOnlyFilterableExpressions(new AndFilterExpression(IN_PREDICATE, new AndFilterExpression(IN_PREDICATE, TRUE_USER_CHECK_EXPRESSION))));
assertFalse(containsOnlyFilterableExpressions(new OrFilterExpression(IN_PREDICATE, new OrFilterExpression(IN_PREDICATE, TRUE_USER_CHECK_EXPRESSION))));
FilterExpression negated, expected;
negated = negate(new OrFilterExpression(NOT_IN_PREDICATE, NOT_IN_PREDICATE));
expected = new AndFilterExpression(IN_PREDICATE, IN_PREDICATE);
assertEquals(expected, negated);
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class PermissionToFilterExpressionVisitorTest method containsOnlyFilterableExpressions.
private static boolean containsOnlyFilterableExpressions(FilterExpression expr) {
if (isSpecialCase(expr)) {
return false;
}
FilterExpression left, right;
if (expr instanceof OrFilterExpression) {
OrFilterExpression or = (OrFilterExpression) expr;
left = or.getLeft();
right = or.getRight();
return containsOnlyFilterableExpressions(left) && containsOnlyFilterableExpressions(right);
}
if (expr instanceof AndFilterExpression) {
AndFilterExpression and = (AndFilterExpression) expr;
left = and.getLeft();
right = and.getRight();
return containsOnlyFilterableExpressions(left) && containsOnlyFilterableExpressions(right);
}
return true;
}
use of com.yahoo.elide.core.filter.expression.AndFilterExpression in project elide by yahoo.
the class PermissionToFilterExpressionVisitor method visitAndExpression.
@Override
public FilterExpression visitAndExpression(AndExpression andExpression) {
FilterExpression left = andExpression.getLeft().accept(this);
FilterExpression right = andExpression.getRight().accept(this);
// (FALSE_USER_CHECK_EXPRESSION AND NO_EVALUATION_EXPRESSION) => FALSE_USER_CHECK_EXPRESSION
if (expressionWillFail(left) || expressionWillFail(right)) {
return FALSE_USER_CHECK_EXPRESSION;
}
if (expressionWillNotFilter(left)) {
return right;
}
if (expressionWillNotFilter(right)) {
return left;
}
return new AndFilterExpression(left, right);
}
Aggregations