Search in sources :

Example 96 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class TransformUncorrelatedInPredicateSubqueryToJoin method apply.

@Override
public Result apply(ApplyNode applyNode, Captures captures, Context context) {
    if (applyNode.getSubqueryAssignments().size() != 1) {
        return Result.empty();
    }
    Expression expression = castToExpression(getOnlyElement(applyNode.getSubqueryAssignments().getExpressions()));
    InPredicate inPredicate;
    if (expression instanceof InPredicate) {
        inPredicate = (InPredicate) expression;
    } else {
        return Result.empty();
    }
    Symbol semiJoinSymbol = getOnlyElement(applyNode.getSubqueryAssignments().getSymbols());
    JoinNode.EquiJoinClause equiJoinClause = new JoinNode.EquiJoinClause(SymbolUtils.from(inPredicate.getValue()), SymbolUtils.from(inPredicate.getValueList()));
    List<Symbol> outputSymbols = new LinkedList<>(applyNode.getInput().getOutputSymbols());
    outputSymbols.add(SymbolUtils.from(inPredicate.getValueList()));
    AggregationNode distinctNode = new AggregationNode(context.getIdAllocator().getNextId(), applyNode.getSubquery(), ImmutableMap.of(), singleGroupingSet(applyNode.getSubquery().getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
    JoinNode joinNode = new JoinNode(context.getIdAllocator().getNextId(), JoinNode.Type.RIGHT, distinctNode, applyNode.getInput(), ImmutableList.of(equiJoinClause), outputSymbols, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Collections.emptyMap());
    Map<Symbol, RowExpression> assignments = new HashMap<>();
    assignments.put(semiJoinSymbol, castToRowExpression(new IsNotNullPredicate(inPredicate.getValueList())));
    for (Symbol symbol : applyNode.getInput().getOutputSymbols()) {
        assignments.put(symbol, castToRowExpression(toSymbolReference(symbol)));
    }
    ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), joinNode, new Assignments(assignments));
    return Result.ofPlanNode(projectNode);
}
Also used : HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) JoinNode(io.prestosql.spi.plan.JoinNode) Assignments(io.prestosql.spi.plan.Assignments) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(io.prestosql.spi.relation.RowExpression) AggregationNode(io.prestosql.spi.plan.AggregationNode) InPredicate(io.prestosql.sql.tree.InPredicate) LinkedList(java.util.LinkedList) IsNotNullPredicate(io.prestosql.sql.tree.IsNotNullPredicate) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 97 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class ActualProperties method translateRowExpression.

public ActualProperties translateRowExpression(Map<Symbol, RowExpression> assignments, TypeProvider types) {
    Map<Symbol, SymbolReference> inputToOutputSymbol = new HashMap<>();
    for (Map.Entry<Symbol, RowExpression> assignment : assignments.entrySet()) {
        RowExpression expression = assignment.getValue();
        SymbolReference symbolReference = SymbolUtils.toSymbolReference(assignment.getKey());
        if (isExpression(expression)) {
            if (castToExpression(expression) instanceof SymbolReference) {
                inputToOutputSymbol.put(SymbolUtils.from(castToExpression(expression)), symbolReference);
            }
        } else {
            if (expression instanceof VariableReferenceExpression) {
                inputToOutputSymbol.put(new Symbol(((VariableReferenceExpression) expression).getName()), symbolReference);
            }
        }
    }
    Map<Symbol, Partitioning.ArgumentBinding> inputToOutputMappings = inputToOutputSymbol.entrySet().stream().collect(Collectors.toMap(v -> v.getKey(), v -> expressionBinding(v.getValue())));
    Map<Symbol, NullableValue> translatedConstants = new HashMap<>();
    for (Map.Entry<Symbol, NullableValue> entry : constants.entrySet()) {
        if (inputToOutputSymbol.containsKey(entry.getKey())) {
            Symbol symbol = SymbolUtils.from(inputToOutputSymbol.get(entry.getKey()));
            translatedConstants.put(symbol, entry.getValue());
        } else {
            inputToOutputMappings.put(entry.getKey(), constantBinding(entry.getValue()));
        }
    }
    return builder().global(global.translateRowExpression(inputToOutputMappings, assignments, types)).local(LocalProperties.translate(localProperties, symbol -> inputToOutputSymbol.containsKey(symbol) ? Optional.of(SymbolUtils.from(inputToOutputSymbol.get(symbol))) : Optional.empty())).constants(translatedConstants).build();
}
Also used : Iterables.transform(com.google.common.collect.Iterables.transform) SINGLE_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) TypeProvider(io.prestosql.sql.planner.TypeProvider) HashMap(java.util.HashMap) NullableValue(io.prestosql.spi.predicate.NullableValue) Function(java.util.function.Function) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) MoreLists.filteredCopy(io.prestosql.util.MoreLists.filteredCopy) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Partitioning(io.prestosql.sql.planner.Partitioning) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) COORDINATOR_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION) ConstantProperty(io.prestosql.spi.connector.ConstantProperty) Symbol(io.prestosql.spi.plan.Symbol) SymbolUtils(io.prestosql.sql.planner.SymbolUtils) LocalProperty(io.prestosql.spi.connector.LocalProperty) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Collectors(java.util.stream.Collectors) ArgumentBinding.constantBinding(io.prestosql.sql.planner.Partitioning.ArgumentBinding.constantBinding) ArgumentBinding.expressionBinding(io.prestosql.sql.planner.Partitioning.ArgumentBinding.expressionBinding) Metadata(io.prestosql.metadata.Metadata) Objects(java.util.Objects) PartitioningHandle(io.prestosql.sql.planner.PartitioningHandle) List(java.util.List) SOURCE_DISTRIBUTION(io.prestosql.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) SymbolReference(io.prestosql.sql.tree.SymbolReference) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) Immutable(javax.annotation.concurrent.Immutable) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) SymbolReference(io.prestosql.sql.tree.SymbolReference) RowExpression(io.prestosql.spi.relation.RowExpression) NullableValue(io.prestosql.spi.predicate.NullableValue) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 98 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class PushTopNThroughProject method symbolMapper.

private Optional<SymbolMapper> symbolMapper(List<Symbol> symbols, Assignments assignments) {
    SymbolMapper.Builder mapper = SymbolMapper.builder();
    for (Symbol symbol : symbols) {
        if (isExpression(assignments.get(symbol))) {
            Expression expression = castToExpression(assignments.get(symbol));
            if (!(expression instanceof SymbolReference)) {
                return Optional.empty();
            }
            mapper.put(symbol, SymbolUtils.from(expression));
        } else {
            RowExpression expression = assignments.get(symbol);
            if (!(expression instanceof VariableReferenceExpression)) {
                return Optional.empty();
            }
            mapper.put(symbol, new Symbol(((VariableReferenceExpression) expression).getName()));
        }
    }
    return Optional.of(mapper.build());
}
Also used : SymbolMapper(io.prestosql.sql.planner.optimizations.SymbolMapper) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) SymbolReference(io.prestosql.sql.tree.SymbolReference) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) RowExpression(io.prestosql.spi.relation.RowExpression)

Example 99 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class TestScanFilterAndProjectOperator method testRecordCursorSource.

@Test
public void testRecordCursorSource() {
    final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(VARCHAR), 10_000, 0);
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new RecordPageSource(new PageRecordSet(ImmutableList.of(VARCHAR), input)), cursorProcessor, pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), null, ImmutableList.of(VARCHAR), new DataSize(0, BYTE), 0, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), false, Optional.empty(), 0, 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), ImmutableList.of(input));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : CursorProcessor(io.prestosql.operator.project.CursorProcessor) RowExpression(io.prestosql.spi.relation.RowExpression) Page(io.prestosql.spi.Page) PageRecordSet(io.prestosql.operator.index.PageRecordSet) RecordPageSource(io.prestosql.spi.connector.RecordPageSource) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProcessor(io.prestosql.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) CatalogName(io.prestosql.spi.connector.CatalogName) UUID(java.util.UUID) Split(io.prestosql.metadata.Split) TestingSplit(io.prestosql.testing.TestingSplit) MaterializedResult(io.prestosql.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Example 100 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class TestScanFilterAndProjectOperator method testPageSource.

@Test
public void testPageSource() {
    final Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(VARCHAR), 10_000, 0);
    DriverContext driverContext = newDriverContext();
    List<RowExpression> projections = ImmutableList.of(field(0, VARCHAR));
    Supplier<CursorProcessor> cursorProcessor = expressionCompiler.compileCursorProcessor(Optional.empty(), projections, "key");
    Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(Optional.empty(), projections);
    ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory factory = new ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory(0, new PlanNodeId("test"), new PlanNodeId("0"), (session, split, table, columns, dynamicFilter) -> new FixedPageSource(ImmutableList.of(input)), cursorProcessor, pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), null, ImmutableList.of(VARCHAR), new DataSize(0, BYTE), 0, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), false, Optional.empty(), 0, 0);
    SourceOperator operator = factory.createOperator(driverContext);
    operator.addSplit(new Split(new CatalogName("test"), TestingSplit.createLocalSplit(), Lifespan.taskWide()));
    operator.noMoreSplits();
    MaterializedResult expected = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), ImmutableList.of(input));
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(VARCHAR), toPages(operator));
    assertEquals(actual.getRowCount(), expected.getRowCount());
    assertEquals(actual, expected);
}
Also used : CursorProcessor(io.prestosql.operator.project.CursorProcessor) RowExpression(io.prestosql.spi.relation.RowExpression) Page(io.prestosql.spi.Page) FixedPageSource(io.prestosql.spi.connector.FixedPageSource) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProcessor(io.prestosql.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) CatalogName(io.prestosql.spi.connector.CatalogName) UUID(java.util.UUID) Split(io.prestosql.metadata.Split) TestingSplit(io.prestosql.testing.TestingSplit) MaterializedResult(io.prestosql.testing.MaterializedResult) OperatorAssertion.toMaterializedResult(io.prestosql.operator.OperatorAssertion.toMaterializedResult) Test(org.testng.annotations.Test)

Aggregations

RowExpression (io.prestosql.spi.relation.RowExpression)185 ArrayList (java.util.ArrayList)66 Symbol (io.prestosql.spi.plan.Symbol)62 CallExpression (io.prestosql.spi.relation.CallExpression)56 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)52 ImmutableList (com.google.common.collect.ImmutableList)45 Test (org.testng.annotations.Test)42 Type (io.prestosql.spi.type.Type)41 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)39 List (java.util.List)39 Map (java.util.Map)39 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)31 Optional (java.util.Optional)30 Expression (io.prestosql.sql.tree.Expression)29 Metadata (io.prestosql.metadata.Metadata)28 PlanNode (io.prestosql.spi.plan.PlanNode)27 ImmutableMap (com.google.common.collect.ImmutableMap)26 SpecialForm (io.prestosql.spi.relation.SpecialForm)25 FunctionHandle (io.prestosql.spi.function.FunctionHandle)24 ProjectNode (io.prestosql.spi.plan.ProjectNode)24