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