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()] = io.prestosql.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 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()] = io.prestosql.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 Type checkedTypeLookup(Symbol symbol) { Type type = types.get(symbol); checkArgument(type != null, "Types is missing info for symbol: %s", symbol); return type; }
public TypeProvider getTypes() { return TypeProvider.copyOf(symbols); } }
private static void assertProjection(String expression, @Nullable Object expectedValue) { assertProjection( expression, expectedValue, ImmutableMap.of(), TypeProvider.empty(), 0); }
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); }
@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 static void assertProjection(String expression, @Nullable Object expectedValue) { assertProjection( expression, expectedValue, ImmutableMap.of(), TypeProvider.empty(), 0); }
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(), ungroupedExecution(), statsAndCosts.getForSubplan(root)); return new SubPlan(fragment, properties.getChildren()); }
@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(); }