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