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);
}
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();
}
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());
}
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);
}
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);
}
Aggregations