use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class ExpressionVerifier method visitInPredicate.
@Override
protected Boolean visitInPredicate(InPredicate actual, Node expectedExpression) {
if (expectedExpression instanceof InPredicate) {
InPredicate expected = (InPredicate) expectedExpression;
if (actual.getValueList() instanceof InListExpression) {
return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), expected.getValueList());
} else {
checkState(expected.getValueList() instanceof InListExpression, "ExpressionVerifier doesn't support unpacked expected values. Feel free to add support if needed");
/*
* If the expected value is a value list, but the actual is e.g. a SymbolReference,
* we need to unpack the value from the list so that when we hit visitSymbolReference, the
* expected.toString() call returns something that the symbolAliases actually contains.
* For example, InListExpression.toString returns "(onlyitem)" rather than "onlyitem".
*
* This is required because actual passes through the analyzer, planner, and possibly optimizers,
* one of which sometimes takes the liberty of unpacking the InListExpression.
*
* Since the expected value doesn't go through all of that, we have to deal with the case
* of the actual value being unpacked, but the expected value being an InListExpression.
*/
List<Expression> values = ((InListExpression) expected.getValueList()).getValues();
checkState(values.size() == 1, "Multiple expressions in expected value list %s, but actual value is not a list", values, actual.getValue());
Expression onlyExpectedExpression = values.get(0);
return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), onlyExpectedExpression);
}
}
return false;
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class FilterMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
FunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), functionResolution, metadata.getFunctionAndTypeManager());
FilterNode filterNode = (FilterNode) node;
if (isExpression(filterNode.getPredicate())) {
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
if (dynamicFilter.isPresent()) {
return new MatchResult(verifier.process(castToExpression(filterNode.getPredicate()), combineConjuncts(castToExpression(predicate), castToExpression(dynamicFilter.get()))));
}
DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
List<Expression> expressionList = extractResult.getStaticConjuncts().stream().map(OriginalExpressionUtils::castToExpression).collect(Collectors.toList());
return new MatchResult(verifier.process(combineConjuncts(expressionList), castToExpression(predicate)));
}
RowExpressionVerifier verifier = new RowExpressionVerifier(symbolAliases, metadata, session, filterNode.getOutputSymbols());
if (dynamicFilter.isPresent()) {
return new MatchResult(verifier.process(combineConjuncts(castToExpression(predicate), castToExpression(dynamicFilter.get())), filterNode.getPredicate()));
}
DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
return new MatchResult(verifier.process(castToExpression(predicate), logicalRowExpressions.combineConjuncts(extractResult.getStaticConjuncts())));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class JoinMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
JoinNode joinNode = (JoinNode) node;
if (joinNode.getCriteria().size() != equiCriteria.size()) {
return NO_MATCH;
}
if (filter.isPresent()) {
if (!joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
RowExpression expression = joinNode.getFilter().get();
if (isExpression(expression)) {
if (!new ExpressionVerifier(symbolAliases).process(castToExpression(expression), filter.get())) {
return NO_MATCH;
}
} else {
if (!new RowExpressionVerifier(symbolAliases, metadata, session, node.getOutputSymbols()).process(filter.get(), expression)) {
return NO_MATCH;
}
}
} else {
if (joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
}
if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
return NO_MATCH;
}
if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
return NO_MATCH;
}
/*
* Have to use order-independent comparison; there are no guarantees what order
* the equi criteria will have after planning and optimizing.
*/
Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
if (!expected.equals(actual)) {
return NO_MATCH;
}
if (dynamicFilter.isPresent() && !dynamicFilter.get().match(joinNode, symbolAliases).isMatch()) {
return NO_MATCH;
}
return MatchResult.match();
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method testBigIntType.
private void testBigIntType() {
mergeAndAssert(true, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(5L)), equal(C_BIGINT, bigintLiteral(6L)), equal(C_BIGINT, bigintLiteral(7L)), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThanOrEqual(C_BIGINT, bigintLiteral(9L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(15L)), between(C_BIGINT, bigintLiteral(25L), bigintLiteral(35L))), between(C_BIGINT, bigintLiteral(2L), bigintLiteral(12L)));
mergeAndAssert(true, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(5L)), equal(C_BIGINT, bigintLiteral(6L)), equal(C_BIGINT, bigintLiteral(7L)), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThanOrEqual(C_BIGINT, bigintLiteral(9L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(15L)), between(C_BIGINT, bigintLiteral(25L), bigintLiteral(35L))), and(greaterThan(C_BIGINT, bigintLiteral(2L)), lessThan(C_BIGINT, bigintLiteral(12L))));
mergeAndAssert(true, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(5L)), equal(C_BIGINT, bigintLiteral(6L)), equal(C_BIGINT, bigintLiteral(7L)), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThanOrEqual(C_BIGINT, bigintLiteral(9L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(15L)), between(C_BIGINT, bigintLiteral(25L), bigintLiteral(35L))), or(equal(C_BIGINT, bigintLiteral(2L)), equal(C_BIGINT, bigintLiteral(5L))));
mergeAndAssert(false, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(5L)), equal(C_BIGINT, bigintLiteral(6L)), equal(C_BIGINT, bigintLiteral(7L)), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThanOrEqual(C_BIGINT, bigintLiteral(9L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(15L)), between(C_BIGINT, bigintLiteral(25L), bigintLiteral(35L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(16L)));
Expression merged = mergeAndAssert(false, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(4L)), between(C_BIGINT, bigintLiteral(8L), bigintLiteral(10L))), between(C_BIGINT, bigintLiteral(2L), bigintLiteral(6L)));
mergeAndAssert(true, ExpressionUtils.or(merged, equal(C_BIGINT, bigintLiteral(5L)), between(C_BIGINT, bigintLiteral(6L), bigintLiteral(7L))), between(C_BIGINT, bigintLiteral(2L), bigintLiteral(10L)));
mergeAndAssert(true, ExpressionUtils.or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(5L)), equal(C_BIGINT, bigintLiteral(6L)), equal(C_BIGINT, nullLiteral()), equal(C_BIGINT, bigintLiteral(7L)), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThanOrEqual(C_BIGINT, bigintLiteral(9L))), between(C_BIGINT, bigintLiteral(10L), bigintLiteral(15L)), between(C_BIGINT, bigintLiteral(25L), bigintLiteral(35L))), between(C_BIGINT, bigintLiteral(2L), bigintLiteral(12L)));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method mergeAndAssert.
private Expression mergeAndAssert(boolean contains, Expression expression, Expression partExpression) {
CubeRangeCanonicalizer canonicalizer = new CubeRangeCanonicalizer(metadata, TEST_SESSION, TYPES);
Expression transformed = canonicalizer.mergePredicates(expression);
ExpressionDomainTranslator.ExtractionResult expressionTD = ExpressionDomainTranslator.fromPredicate(metadata, TEST_SESSION, transformed, TYPES);
Assert.assertEquals(expressionTD.getRemainingExpression(), BooleanLiteral.TRUE_LITERAL, "Still some part of expression not converted into TupleDomain");
ExpressionDomainTranslator.ExtractionResult partTD = ExpressionDomainTranslator.fromPredicate(metadata, TEST_SESSION, partExpression, TYPES);
Assert.assertEquals(partTD.getRemainingExpression(), BooleanLiteral.TRUE_LITERAL, "Still some part of expression not converted into TupleDomain");
Assert.assertEquals(contains, expressionTD.getTupleDomain().contains(partTD.getTupleDomain()));
return transformed;
}
Aggregations