public TypeProvider getTypes() { return TypeProvider.copyOf(symbols); } }
public Type getTypeForSymbol(Symbol symbol) { return types.get(symbol); } }
public boolean areExpressionsEquivalent(Session session, Expression leftExpression, Expression rightExpression, TypeProvider types) { Map<Symbol, Integer> symbolInput = new HashMap<>(); Map<Integer, Type> inputTypes = new HashMap<>(); int inputId = 0; for (Entry<Symbol, Type> entry : types.allTypes().entrySet()) { symbolInput.put(entry.getKey(), inputId); inputTypes.put(inputId, entry.getValue()); inputId++; } RowExpression leftRowExpression = toRowExpression(session, leftExpression, symbolInput, inputTypes); RowExpression rightRowExpression = toRowExpression(session, rightExpression, symbolInput, inputTypes); RowExpression canonicalizedLeft = leftRowExpression.accept(CANONICALIZATION_VISITOR, null); RowExpression canonicalizedRight = rightRowExpression.accept(CANONICALIZATION_VISITOR, null); return canonicalizedLeft.equals(canonicalizedRight); }
private static ExpressionAnalysis analyzeExpressionsWithInputs( Session session, Metadata metadata, SqlParser sqlParser, Map<Integer, Type> types, Iterable<Expression> expressions, List<Expression> parameters, WarningCollector warningCollector) { Field[] fields = new Field[types.size()]; for (Entry<Integer, Type> entry : types.entrySet()) { fields[entry.getKey()] = com.facebook.presto.sql.analyzer.Field.newUnqualified(Optional.empty(), entry.getValue()); } RelationType tupleDescriptor = new RelationType(fields); return analyzeExpressions(session, metadata, sqlParser, tupleDescriptor, TypeProvider.empty(), expressions, parameters, warningCollector); }
public TypeProvider getTypes() { return TypeProvider.viewOf(symbols); }
public static TypeProvider viewOf(Map<Symbol, Type> types) { return new TypeProvider(types); }
private static void assertProjection(String expression, @Nullable Object expectedValue) { assertProjection( expression, expectedValue, ImmutableMap.of(), TypeProvider.empty(), 0); }
@Test public void testFunctionCall() { assertCalculate( new FunctionCall( QualifiedName.of("length"), ImmutableList.of(new Cast(new NullLiteral(), "VARCHAR(10)")))) .distinctValuesCount(0.0) .lowValueUnknown() .highValueUnknown() .nullsFraction(1.0); assertCalculate( new FunctionCall( QualifiedName.of("length"), ImmutableList.of(new SymbolReference("x"))), PlanNodeStatsEstimate.unknown(), TypeProvider.viewOf(ImmutableMap.of(new Symbol("x"), createVarcharType(2)))) .distinctValuesCountUnknown() .lowValueUnknown() .highValueUnknown() .nullsFractionUnknown(); }
public static TypeProvider empty() { return new TypeProvider(ImmutableMap.of()); }
private Type checkedTypeLookup(Symbol symbol) { Type type = types.get(symbol); checkArgument(type != null, "Types is missing info for symbol: %s", symbol); return type; }
protected final OperatorFactory createHashProjectOperator(int operatorId, PlanNodeId planNodeId, List<Type> types) { ImmutableMap.Builder<Symbol, Type> symbolTypes = ImmutableMap.builder(); ImmutableMap.Builder<Symbol, Integer> symbolToInputMapping = ImmutableMap.builder(); ImmutableList.Builder<PageProjection> projections = ImmutableList.builder(); for (int channel = 0; channel < types.size(); channel++) { Symbol symbol = new Symbol("h" + channel); symbolTypes.put(symbol, types.get(channel)); symbolToInputMapping.put(symbol, channel); projections.add(new InputPageProjection(channel, types.get(channel))); } Optional<Expression> hashExpression = HashGenerationOptimizer.getHashExpression(ImmutableList.copyOf(symbolTypes.build().keySet())); verify(hashExpression.isPresent()); projections.add(new InterpretedPageProjection( hashExpression.get(), TypeProvider.copyOf(symbolTypes.build()), symbolToInputMapping.build(), localQueryRunner.getMetadata(), localQueryRunner.getSqlParser(), session)); return new FilterAndProjectOperator.FilterAndProjectOperatorFactory( operatorId, planNodeId, () -> new PageProcessor(Optional.empty(), projections.build()), ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT))), getFilterAndProjectMinOutputPageSize(session), getFilterAndProjectMinOutputPageRowCount(session)); }
private SymbolStatsAssertion assertCalculate(Expression scalarExpression, PlanNodeStatsEstimate inputStatistics) { return assertCalculate(scalarExpression, inputStatistics, TypeProvider.empty()); }
private SubPlan buildFragment(PlanNode root, FragmentProperties properties, PlanFragmentId fragmentId) { Set<Symbol> dependencies = SymbolsExtractor.extractOutputSymbols(root); List<PlanNodeId> schedulingOrder = scheduleOrder(root); boolean equals = properties.getPartitionedSources().equals(ImmutableSet.copyOf(schedulingOrder)); checkArgument(equals, "Expected scheduling order (%s) to contain an entry for all partitioned sources (%s)", schedulingOrder, properties.getPartitionedSources()); PlanFragment fragment = new PlanFragment( fragmentId, root, Maps.filterKeys(types.allTypes(), in(dependencies)), properties.getPartitioningHandle(), schedulingOrder, properties.getPartitioningScheme(), StageExecutionDescriptor.ungroupedExecution(), statsAndCosts.getForSubplan(root)); return new SubPlan(fragment, properties.getChildren()); }
public static TypeProvider copyOf(Map<Symbol, Type> types) { return new TypeProvider(ImmutableMap.copyOf(types)); }
private boolean canSkipHashGeneration(List<Symbol> partitionSymbols) { // HACK: bigint grouped aggregation has special operators that do not use precomputed hash, so we can skip hash generation return partitionSymbols.isEmpty() || (partitionSymbols.size() == 1 && types.get(Iterables.getOnlyElement(partitionSymbols)).equals(BIGINT)); }
private PlanNodeStatsAssertion assertNormalized(PlanNodeStatsEstimate estimate) { TypeProvider types = TypeProvider.copyOf(estimate.getSymbolsWithKnownStatistics().stream() .collect(toImmutableMap(identity(), symbol -> BIGINT))); return assertNormalized(estimate, types); }
metadata, sqlParser, TypeProvider.empty(), ImmutableList.copyOf(row), emptyList(),
public static String graphvizLogicalPlan(PlanNode plan, TypeProvider types) { PlanFragment fragment = new PlanFragment( new PlanFragmentId("graphviz_plan"), plan, types.allTypes(), SINGLE_DISTRIBUTION, ImmutableList.of(plan.getId()), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), plan.getOutputSymbols()), StageExecutionDescriptor.ungroupedExecution(), StatsAndCosts.empty()); return GraphvizPrinter.printLogical(ImmutableList.of(fragment)); }
private String formatOutputs(Iterable<Symbol> symbols) { return Joiner.on(", ").join(Iterables.transform(symbols, input -> input + ":" + types.get(input).getDisplayName())); }
@Test public void testSymbolReference() { Symbol symbol = new Symbol("symbol"); ImmutableMap<Symbol, Integer> symbolToInputMappings = ImmutableMap.of(symbol, 0); assertProjection("symbol", true, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, BOOLEAN)), 0, createBlock(BOOLEAN, true)); assertProjection("symbol", null, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, BOOLEAN)), 0, createNullBlock(BOOLEAN)); assertProjection("symbol", 42L, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, BIGINT)), 0, createBlock(BIGINT, 42)); assertProjection("symbol", null, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, BIGINT)), 0, createNullBlock(BIGINT)); assertProjection("symbol", 11.1, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, DOUBLE)), 0, createBlock(DOUBLE, 11.1)); assertProjection("symbol", null, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, DOUBLE)), 0, createNullBlock(DOUBLE)); assertProjection("symbol", "foo", symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, VARCHAR)), 0, createBlock(VARCHAR, "foo")); assertProjection("symbol", null, symbolToInputMappings, TypeProvider.copyOf(ImmutableMap.of(symbol, VARCHAR)), 0, createNullBlock(VARCHAR)); }