use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.
the class SimpleFilterProjectSemiJoinStatsRule method extractSemiJoinOutputFilter.
private Optional<SemiJoinOutputFilter> extractSemiJoinOutputFilter(RowExpression predicate, RowExpression input) {
checkState(!isExpression(predicate));
List<RowExpression> conjuncts = LogicalRowExpressions.extractConjuncts(predicate);
List<RowExpression> semiJoinOutputReferences = conjuncts.stream().filter(conjunct -> isSemiJoinOutputReference(conjunct, input)).collect(toImmutableList());
if (semiJoinOutputReferences.size() != 1) {
return Optional.empty();
}
RowExpression semiJoinOutputReference = Iterables.getOnlyElement(semiJoinOutputReferences);
RowExpression remainingPredicate = logicalRowExpressions.combineConjuncts(conjuncts.stream().filter(conjunct -> conjunct != semiJoinOutputReference).collect(toImmutableList()));
boolean negated = isNotFunction(semiJoinOutputReference);
return Optional.of(new SemiJoinOutputFilter(negated, remainingPredicate));
}
use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.
the class TableDeleteOperator method getOutput.
@Override
public Page getOutput() {
if (state == State.FINISHED || (sourceLayout.isPresent() && state != State.FINISHING)) {
return null;
}
state = State.FINISHED;
TableHandle tableHandleForDelete = tableHandle;
if (sourceLayout.isPresent()) {
// Replace the values from subqueries in filter predicates
VariablesExtractor.extractUnique(filter.get()).stream().forEach(expr -> symbolExpressionMap.putIfAbsent(new Symbol(expr.getName()), expr));
RowExpression rowExpression = RowExpressionVariableInliner.inlineVariables(node -> symbolExpressionMap.get(new Symbol(node.getName())), filter.get());
// Create the tuple domain based on filter and values from source;
RowExpressionDomainTranslator.ExtractionResult<VariableReferenceExpression> decomposedPredicate = (new RowExpressionDomainTranslator(metadata)).fromPredicate(session.toConnectorSession(), rowExpression, RowExpressionDomainTranslator.BASIC_COLUMN_EXTRACTOR);
TupleDomain<ColumnHandle> tupleDomain = decomposedPredicate.getTupleDomain().transform(variableName -> assignments.get(new Symbol(variableName.getName())));
Constraint constraint = new Constraint(tupleDomain);
// Apply the constraint on the table handle
Optional<TableHandle> tableHandleDelete = metadata.applyDelete(session, this.tableHandle, constraint);
if (tableHandleDelete.isPresent()) {
tableHandleForDelete = tableHandleDelete.get();
}
}
OptionalLong rowsDeletedCount = metadata.executeDelete(session, tableHandleForDelete);
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(1, TYPES);
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
page.declarePosition();
if (rowsDeletedCount.isPresent()) {
BIGINT.writeLong(rowsBuilder, rowsDeletedCount.getAsLong());
} else {
rowsBuilder.appendNull();
}
return page.build();
}
use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.
the class TestScanFilterAndProjectOperator method testRecordCursorYield.
@Test
public void testRecordCursorYield() {
// create a generic long function that yields for projection on every row
// verify we will yield #row times totally
// create a table with 15 rows
int length = 15;
Page input = SequencePageBuilder.createSequencePage(ImmutableList.of(BIGINT), length, 0);
DriverContext driverContext = newDriverContext();
// set up generic long function with a callback to force yield
Metadata localMetadata = functionAssertions.getMetadata();
localMetadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(new GenericLongFunction("record_cursor", value -> {
driverContext.getYieldSignal().forceYieldForTesting();
return value;
})));
ExpressionCompiler compiler = new ExpressionCompiler(localMetadata, new PageFunctionCompiler(localMetadata, 0));
List<RowExpression> projections = ImmutableList.of(call(QualifiedObjectName.valueOfDefaultFunction("generic_long_record_cursor").toString(), new BuiltInFunctionHandle(internalScalarFunction(QualifiedObjectName.valueOfDefaultFunction("generic_long_record_cursor"), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()))), BIGINT, field(0, BIGINT)));
Supplier<CursorProcessor> cursorProcessor = compiler.compileCursorProcessor(Optional.empty(), projections, "key");
Supplier<PageProcessor> pageProcessor = compiler.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(BIGINT), input)), cursorProcessor, pageProcessor, TEST_TABLE_HANDLE, ImmutableList.of(), null, ImmutableList.of(BIGINT), 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();
// start driver; get null value due to yield for the first 15 times
for (int i = 0; i < length; i++) {
driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
assertNull(operator.getOutput());
driverContext.getYieldSignal().reset();
}
// the 16th yield is not going to prevent the operator from producing a page
driverContext.getYieldSignal().setWithDelay(SECONDS.toNanos(1000), driverContext.getYieldExecutor());
Page output = operator.getOutput();
driverContext.getYieldSignal().reset();
assertNotNull(output);
assertEquals(toValues(BIGINT, output.getBlock(0)), toValues(BIGINT, input.getBlock(0)));
}
use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.
the class SqlQueryExecution method findMappingFromPlan.
private void findMappingFromPlan(Map<String, Set<String>> mapping, PlanNode sourceNode) {
if (sourceNode != null && sourceNode instanceof ProjectNode) {
ProjectNode projectNode = (ProjectNode) sourceNode;
Map<Symbol, RowExpression> assignments = projectNode.getAssignments().getMap();
for (Symbol symbol : assignments.keySet()) {
if (mapping.containsKey(symbol.getName())) {
Set<String> sets = mapping.get(symbol.getName());
RowExpression expression = assignments.get(symbol);
if (expression instanceof VariableReferenceExpression) {
sets.add(((VariableReferenceExpression) expression).getName());
} else {
sets.add(expression.toString());
}
} else {
for (Map.Entry<String, Set<String>> entry : mapping.entrySet()) {
if (entry.getValue().contains(symbol.getName())) {
RowExpression expression = assignments.get(symbol);
if (expression instanceof VariableReferenceExpression) {
entry.getValue().add(((VariableReferenceExpression) expression).getName());
} else {
entry.getValue().add(expression.toString());
}
}
}
}
}
}
for (PlanNode planNode : sourceNode.getSources()) {
findMappingFromPlan(mapping, planNode);
}
}
use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.
the class TestDynamicFilters method testExtractStaticFilters.
@Test
public void testExtractStaticFilters() {
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
ConstantExpression staticExpression = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression = new VariableReferenceExpression("col", VarcharType.VARCHAR);
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
RowExpression dynamicFilterExpression = call(DynamicFilters.Function.NAME, functionHandle, staticExpression.getType(), asList(staticExpression, variableExpression), Optional.empty());
RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, dynamicFilterExpression);
Optional<RowExpression> extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), staticExpression);
RowExpression combinedStaticExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression);
combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression, dynamicFilterExpression);
extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), combinedStaticExpression);
}
Aggregations