Search in sources :

Example 11 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class SubqueryPlanner method appendInPredicateApplyNode.

private PlanBuilder appendInPredicateApplyNode(PlanBuilder inputSubPlan, InPredicate inPredicate, boolean correlationAllowed, Node node) {
    PlanBuilder subPlan = inputSubPlan;
    if (subPlan.canTranslate(inPredicate)) {
        // given subquery is already appended
        return subPlan;
    }
    subPlan = handleSubqueries(subPlan, inPredicate.getValue(), node);
    subPlan = subPlan.appendProjections(ImmutableList.of(inPredicate.getValue()), planSymbolAllocator, idAllocator);
    checkState(inPredicate.getValueList() instanceof SubqueryExpression);
    SubqueryExpression valueListSubquery = (SubqueryExpression) inPredicate.getValueList();
    SubqueryExpression uncoercedValueListSubquery = uncoercedSubquery(valueListSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedValueListSubquery);
    subqueryPlan = subqueryPlan.appendProjections(ImmutableList.of(valueListSubquery), planSymbolAllocator, idAllocator);
    SymbolReference valueList = toSymbolReference(subqueryPlan.translate(valueListSubquery));
    Symbol rewrittenValue = subPlan.translate(inPredicate.getValue());
    InPredicate inPredicateSubqueryExpression = new InPredicate(toSymbolReference(rewrittenValue), valueList);
    Symbol inPredicateSubquerySymbol = planSymbolAllocator.newSymbol(inPredicateSubqueryExpression, BOOLEAN);
    subPlan.getTranslations().put(inPredicate, inPredicateSubquerySymbol);
    return appendApplyNode(subPlan, inPredicate, subqueryPlan.getRoot(), Assignments.of(inPredicateSubquerySymbol, castToRowExpression(inPredicateSubqueryExpression)), correlationAllowed);
}
Also used : SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Symbol(io.prestosql.spi.plan.Symbol) InPredicate(io.prestosql.sql.tree.InPredicate) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression)

Example 12 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class ExpressionDomainTranslator method extractDisjuncts.

private List<Expression> extractDisjuncts(Type type, DiscreteValues discreteValues, SymbolReference reference) {
    List<Expression> values = discreteValues.getValues().stream().map(object -> literalEncoder.toExpression(object, type)).collect(toList());
    // If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for
    checkState(!values.isEmpty());
    Expression predicate;
    if (values.size() == 1) {
        predicate = new ComparisonExpression(EQUAL, reference, getOnlyElement(values));
    } else {
        predicate = new InPredicate(reference, new InListExpression(values));
    }
    if (!discreteValues.isWhiteList()) {
        predicate = new NotExpression(predicate);
    }
    return ImmutableList.of(predicate);
}
Also used : GREATER_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) LESS_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) DiscreteValues(io.prestosql.spi.predicate.DiscreteValues) OperatorNotFoundException(io.prestosql.metadata.OperatorNotFoundException) FALSE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.FALSE_LITERAL) ValueSet(io.prestosql.spi.predicate.ValueSet) NullableValue(io.prestosql.spi.predicate.NullableValue) SqlParser(io.prestosql.sql.parser.SqlParser) PeekingIterator(com.google.common.collect.PeekingIterator) Cast(io.prestosql.sql.tree.Cast) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Slices(io.airlift.slice.Slices) Map(java.util.Map) EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.EQUAL) Type(io.prestosql.spi.type.Type) TypeCoercion(io.prestosql.type.TypeCoercion) SliceUtf8.getCodePointAt(io.airlift.slice.SliceUtf8.getCodePointAt) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) ExpressionUtils.or(io.prestosql.sql.ExpressionUtils.or) ImmutableMap(com.google.common.collect.ImmutableMap) CastType(io.prestosql.metadata.CastType) IsNotNullPredicate(io.prestosql.sql.tree.IsNotNullPredicate) LikeFunctions(io.prestosql.type.LikeFunctions) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) NullLiteral(io.prestosql.sql.tree.NullLiteral) SortedRangeSet(io.prestosql.spi.predicate.SortedRangeSet) Metadata(io.prestosql.metadata.Metadata) NodeRef(io.prestosql.sql.tree.NodeRef) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FunctionHandle(io.prestosql.spi.function.FunctionHandle) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) SymbolReference(io.prestosql.sql.tree.SymbolReference) StringLiteral(io.prestosql.sql.tree.StringLiteral) Domain(io.prestosql.spi.predicate.Domain) Optional(java.util.Optional) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) SymbolUtils.from(io.prestosql.sql.planner.SymbolUtils.from) Utils(io.prestosql.spi.predicate.Utils) InPredicate(io.prestosql.sql.tree.InPredicate) LESS_THAN(io.prestosql.sql.tree.ComparisonExpression.Operator.LESS_THAN) Slice(io.airlift.slice.Slice) InListExpression(io.prestosql.sql.tree.InListExpression) Marker(io.prestosql.spi.predicate.Marker) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) InterpretedFunctionInvoker(io.prestosql.sql.InterpretedFunctionInvoker) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Range(io.prestosql.spi.predicate.Range) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) LikePredicate(io.prestosql.sql.tree.LikePredicate) CAST(io.prestosql.metadata.CastType.CAST) Comparator.comparing(java.util.Comparator.comparing) AstVisitor(io.prestosql.sql.tree.AstVisitor) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) Block(io.prestosql.spi.block.Block) Nullable(javax.annotation.Nullable) GREATER_THAN(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN) Symbol(io.prestosql.spi.plan.Symbol) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) SliceUtf8.lengthOfCodePoint(io.airlift.slice.SliceUtf8.lengthOfCodePoint) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) Ranges(io.prestosql.spi.predicate.Ranges) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ExpressionUtils.and(io.prestosql.sql.ExpressionUtils.and) SliceUtf8.setCodePointAt(io.airlift.slice.SliceUtf8.setCodePointAt) ExpressionUtils.combineDisjunctsWithDefault(io.prestosql.sql.ExpressionUtils.combineDisjunctsWithDefault) Collectors.toList(java.util.stream.Collectors.toList) NOT_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.NOT_EQUAL) SliceUtf8.countCodePoints(io.airlift.slice.SliceUtf8.countCodePoints) VarcharType(io.prestosql.spi.type.VarcharType) Expression(io.prestosql.sql.tree.Expression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) InListExpression(io.prestosql.sql.tree.InListExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) InPredicate(io.prestosql.sql.tree.InPredicate)

Example 13 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestScalarStatsCalculator method testCastDoubleToShortRangeUnknownDistinctValuesCount.

@Test
public void testCastDoubleToShortRangeUnknownDistinctValuesCount() {
    PlanNodeStatsEstimate inputStatistics = PlanNodeStatsEstimate.builder().addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0.3).setLowValue(1.6).setHighValue(3.3).setAverageRowSize(2.0).build()).build();
    assertCalculate(new Cast(new SymbolReference("a"), "bigint"), inputStatistics).lowValue(2.0).highValue(3.0).distinctValuesCountUnknown().nullsFraction(0.3).dataSizeUnknown();
}
Also used : Cast(io.prestosql.sql.tree.Cast) Symbol(io.prestosql.spi.plan.Symbol) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 14 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestScalarStatsCalculator method testFunctionCall.

@Test
public void testFunctionCall() {
    assertCalculate(new FunctionCallBuilder(metadata).setName(QualifiedName.of("length")).addArgument(createVarcharType(10), new Cast(new NullLiteral(), "VARCHAR(10)")).build()).distinctValuesCount(0.0).lowValueUnknown().highValueUnknown().nullsFraction(1.0);
    assertCalculate(new FunctionCallBuilder(metadata).setName(QualifiedName.of("length")).addArgument(createVarcharType(2), new SymbolReference("x")).build(), PlanNodeStatsEstimate.unknown(), TypeProvider.viewOf(ImmutableMap.of(new Symbol("x"), createVarcharType(2)))).distinctValuesCountUnknown().lowValueUnknown().highValueUnknown().nullsFractionUnknown();
}
Also used : Cast(io.prestosql.sql.tree.Cast) SymbolReference(io.prestosql.sql.tree.SymbolReference) Symbol(io.prestosql.spi.plan.Symbol) NullLiteral(io.prestosql.sql.tree.NullLiteral) FunctionCallBuilder(io.prestosql.sql.planner.FunctionCallBuilder) Test(org.testng.annotations.Test)

Example 15 with SymbolReference

use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.

the class TestCostCalculator method testProject.

@Test
public void testProject() {
    TableScanNode tableScan = tableScan("ts", "orderkey");
    PlanNode project = project("project", tableScan, "string", new Cast(new SymbolReference("orderkey"), "STRING"));
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts", cpuCost(1000));
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("project", statsEstimate(project, 4000), "ts", statsEstimate(tableScan, 1000));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT, "string", VARCHAR);
    assertCost(project, costs, stats, types).cpu(1000 + 4000 * OFFSET_AND_IS_NULL_OVERHEAD).memory(0).network(0);
    assertCostEstimatedExchanges(project, costs, stats, types).cpu(1000 + 4000 * OFFSET_AND_IS_NULL_OVERHEAD).memory(0).network(0);
    assertCostFragmentedPlan(project, costs, stats, types).cpu(1000 + 4000 * OFFSET_AND_IS_NULL_OVERHEAD).memory(0).network(0);
    assertCostHasUnknownComponentsForUnknownStats(project, types);
}
Also used : Cast(io.prestosql.sql.tree.Cast) Type(io.prestosql.spi.type.Type) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Aggregations

SymbolReference (io.prestosql.sql.tree.SymbolReference)57 Symbol (io.prestosql.spi.plan.Symbol)30 Expression (io.prestosql.sql.tree.Expression)29 Test (org.testng.annotations.Test)25 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)23 Cast (io.prestosql.sql.tree.Cast)19 RowExpression (io.prestosql.spi.relation.RowExpression)17 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)17 LongLiteral (io.prestosql.sql.tree.LongLiteral)14 ImmutableList (com.google.common.collect.ImmutableList)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 Type (io.prestosql.spi.type.Type)12 List (java.util.List)12 Map (java.util.Map)12 ProjectNode (io.prestosql.spi.plan.ProjectNode)11 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)10 ArrayList (java.util.ArrayList)10 Assignments (io.prestosql.spi.plan.Assignments)9 CallExpression (io.prestosql.spi.relation.CallExpression)9 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)9