Search in sources :

Example 1 with ExpressionDomainTranslator

use of io.prestosql.sql.planner.ExpressionDomainTranslator in project hetu-core by openlookeng.

the class CubeRangeCanonicalizer method mergePredicates.

public Expression mergePredicates(Expression cubePredicate) {
    Set<Identifier> predicateColumns = ExpressionUtils.getIdentifiers(cubePredicate);
    if (predicateColumns.size() > 1) {
        // Only single column predicates can be merged
        return cubePredicate;
    }
    Expression cubePredicateRewrite = ExpressionUtils.rewriteIdentifiersToSymbolReferences(cubePredicate);
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicateRewrite);
    CubeRangeVisitor visitor = new CubeRangeVisitor(types, metadata, session.toConnectorSession());
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    ExpressionDomainTranslator.ExtractionResult result = ExpressionDomainTranslator.fromPredicate(metadata, session, transformed, types);
    if (!result.getRemainingExpression().equals(BooleanLiteral.TRUE_LITERAL)) {
        log.info("Unable to transform predicate %s into tuple domain completely. Cannot merge ranges into single predicate.", transformed);
        return cubePredicateRewrite;
    }
    ExpressionDomainTranslator domainTranslator = new ExpressionDomainTranslator(new LiteralEncoder(metadata));
    return domainTranslator.toPredicate(result.getTupleDomain());
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ExpressionDomainTranslator(io.prestosql.sql.planner.ExpressionDomainTranslator) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder)

Aggregations

ExpressionDomainTranslator (io.prestosql.sql.planner.ExpressionDomainTranslator)1 LiteralEncoder (io.prestosql.sql.planner.LiteralEncoder)1 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)1 Expression (io.prestosql.sql.tree.Expression)1 Identifier (io.prestosql.sql.tree.Identifier)1 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)1