Search in sources :

Example 1 with LiteralEncoder

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

the class TestTupleDomainFilterUtils method setup.

@BeforeClass
public void setup() {
    metadata = createTestMetadataManager();
    literalEncoder = new LiteralEncoder(metadata);
}
Also used : LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with LiteralEncoder

use of io.prestosql.sql.planner.LiteralEncoder 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)

Example 3 with LiteralEncoder

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

the class PushProjectionIntoTableScan method apply.

@Override
public Result apply(ProjectNode project, Captures captures, Context context) {
    TableScanNode tableScan = captures.get(TABLE_SCAN);
    List<ConnectorExpression> projections;
    try {
        projections = project.getAssignments().getExpressions().stream().map(expression -> ConnectorExpressionTranslator.translate(expression)).collect(toImmutableList());
    } catch (UnsupportedOperationException e) {
        // rewritten in terms of the new assignments for the columns passed in #2
        return Result.empty();
    }
    Map<String, ColumnHandle> assignments = tableScan.getAssignments().entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().getName(), Map.Entry::getValue));
    Optional<ProjectionApplicationResult<TableHandle>> result = metadata.applyProjection(context.getSession(), tableScan.getTable(), projections, assignments);
    if (!result.isPresent()) {
        return Result.empty();
    }
    List<Symbol> newScanOutputs = new ArrayList<>();
    Map<Symbol, ColumnHandle> newScanAssignments = new HashMap<>();
    Map<String, Symbol> variableMappings = new HashMap<>();
    for (ProjectionApplicationResult.Assignment assignment : result.get().getAssignments()) {
        Symbol symbol = context.getSymbolAllocator().newSymbol(assignment.getVariable(), assignment.getType());
        newScanOutputs.add(symbol);
        newScanAssignments.put(symbol, assignment.getColumn());
        variableMappings.put(assignment.getVariable(), symbol);
    }
    // TODO: ensure newProjections.size == original projections.size
    List<RowExpression> newProjections = result.get().getProjections().stream().map(expression -> ConnectorExpressionTranslator.translate(expression, variableMappings, new LiteralEncoder(metadata))).collect(toImmutableList());
    Assignments.Builder newProjectionAssignments = Assignments.builder();
    for (int i = 0; i < project.getOutputSymbols().size(); i++) {
        newProjectionAssignments.put(project.getOutputSymbols().get(i), newProjections.get(i));
    }
    return Result.ofPlanNode(new ProjectNode(context.getIdAllocator().getNextId(), TableScanNode.newInstance(tableScan.getId(), result.get().getHandle(), newScanOutputs, newScanAssignments, tableScan.getStrategy(), tableScan.getReuseTableScanMappingId(), tableScan.getConsumerTableScanNodeCount(), tableScan.isForDelete()), newProjectionAssignments.build()));
}
Also used : Patterns.source(io.prestosql.sql.planner.plan.Patterns.source) ProjectionApplicationResult(io.prestosql.spi.connector.ProjectionApplicationResult) HashMap(java.util.HashMap) Pattern(io.prestosql.matching.Pattern) TableHandle(io.prestosql.spi.metadata.TableHandle) ArrayList(java.util.ArrayList) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) ConnectorExpressionTranslator(io.prestosql.spi.expression.ConnectorExpressionTranslator) Capture.newCapture(io.prestosql.matching.Capture.newCapture) Map(java.util.Map) Patterns.project(io.prestosql.sql.planner.plan.Patterns.project) Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) Captures(io.prestosql.matching.Captures) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Capture(io.prestosql.matching.Capture) RowExpression(io.prestosql.spi.relation.RowExpression) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder) Optional(java.util.Optional) Patterns.tableScan(io.prestosql.sql.planner.plan.Patterns.tableScan) ConnectorExpression(io.prestosql.spi.expression.ConnectorExpression) HashMap(java.util.HashMap) ConnectorExpression(io.prestosql.spi.expression.ConnectorExpression) Symbol(io.prestosql.spi.plan.Symbol) ArrayList(java.util.ArrayList) Assignments(io.prestosql.spi.plan.Assignments) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) RowExpression(io.prestosql.spi.relation.RowExpression) ProjectionApplicationResult(io.prestosql.spi.connector.ProjectionApplicationResult) TableScanNode(io.prestosql.spi.plan.TableScanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 4 with LiteralEncoder

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

the class SimplifyExpressions method createRewrite.

private static ExpressionRewriter createRewrite(Metadata metadata, TypeAnalyzer typeAnalyzer) {
    requireNonNull(metadata, "metadata is null");
    requireNonNull(typeAnalyzer, "typeAnalyzer is null");
    LiteralEncoder literalEncoder = new LiteralEncoder(metadata);
    return (expression, context) -> rewrite(expression, context.getSession(), context.getSymbolAllocator(), metadata, literalEncoder, typeAnalyzer);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ExpressionInterpreter(io.prestosql.sql.planner.ExpressionInterpreter) Rule(io.prestosql.sql.planner.iterative.Rule) Set(java.util.Set) ExtractCommonPredicatesExpressionRewriter.extractCommonPredicates(io.prestosql.sql.planner.iterative.rule.ExtractCommonPredicatesExpressionRewriter.extractCommonPredicates) Metadata(io.prestosql.metadata.Metadata) NodeRef(io.prestosql.sql.tree.NodeRef) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) NoOpSymbolResolver(io.prestosql.sql.planner.NoOpSymbolResolver) SymbolReference(io.prestosql.sql.tree.SymbolReference) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder) PushDownNegationsExpressionRewriter.pushDownNegations(io.prestosql.sql.planner.iterative.rule.PushDownNegationsExpressionRewriter.pushDownNegations) Type(io.prestosql.spi.type.Type) Expression(io.prestosql.sql.tree.Expression) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder)

Example 5 with LiteralEncoder

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

the class TableDeleteOperator method addInput.

@Override
public void addInput(Page page) {
    if (!sourceLayout.isPresent()) {
        throw new UnsupportedOperationException();
    }
    requireNonNull(page, "page is null");
    checkState(state == State.RUNNING, "Operator is %s", state);
    LiteralEncoder literalEncoder = new LiteralEncoder(metadata);
    // Convert the incoming data as Literal values for symbols
    // Current impl, one symbol->one value is expected.
    sourceLayout.get().keySet().stream().forEach(symbol -> {
        Block block = page.getBlock(sourceLayout.get().get(symbol));
        for (int i = 0; i < block.getPositionCount(); i++) {
            if (!block.isNull(i)) {
                Type type = types.get(symbol);
                symbolExpressionMap.putIfAbsent(symbol, ConstantExpression.createConstantExpression(block, type));
            }
        }
    });
}
Also used : Type(io.prestosql.spi.type.Type) LiteralEncoder(io.prestosql.sql.planner.LiteralEncoder) Block(io.prestosql.spi.block.Block) Constraint(io.prestosql.spi.connector.Constraint)

Aggregations

LiteralEncoder (io.prestosql.sql.planner.LiteralEncoder)6 Expression (io.prestosql.sql.tree.Expression)3 Metadata (io.prestosql.metadata.Metadata)2 Type (io.prestosql.spi.type.Type)2 TypeAnalyzer (io.prestosql.sql.planner.TypeAnalyzer)2 Rule (io.prestosql.sql.planner.iterative.Rule)2 Map (java.util.Map)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Session (io.prestosql.Session)1 Capture (io.prestosql.matching.Capture)1 Capture.newCapture (io.prestosql.matching.Capture.newCapture)1 Captures (io.prestosql.matching.Captures)1 Pattern (io.prestosql.matching.Pattern)1 Block (io.prestosql.spi.block.Block)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 Constraint (io.prestosql.spi.connector.Constraint)1 ProjectionApplicationResult (io.prestosql.spi.connector.ProjectionApplicationResult)1 ConnectorExpression (io.prestosql.spi.expression.ConnectorExpression)1