예제 #1
0
  public static ExpressionAnalysis analyzeExpression(
      Session session,
      Metadata metadata,
      AccessControl accessControl,
      SqlParser sqlParser,
      TupleDescriptor tupleDescriptor,
      Analysis analysis,
      boolean approximateQueriesEnabled,
      AnalysisContext context,
      Expression expression) {
    ExpressionAnalyzer analyzer =
        create(analysis, session, metadata, sqlParser, accessControl, approximateQueriesEnabled);
    analyzer.analyze(expression, tupleDescriptor, context);

    IdentityHashMap<Expression, Type> expressionTypes = analyzer.getExpressionTypes();
    IdentityHashMap<Expression, Type> expressionCoercions = analyzer.getExpressionCoercions();
    IdentityHashMap<FunctionCall, Signature> resolvedFunctions = analyzer.getResolvedFunctions();

    analysis.addTypes(expressionTypes);
    analysis.addCoercions(expressionCoercions);
    analysis.addFunctionSignatures(resolvedFunctions);
    analysis.addColumnReferences(analyzer.getColumnReferences());

    for (Expression subExpression : expressionTypes.keySet()) {
      analysis.addResolvedNames(subExpression, analyzer.getResolvedNames());
    }

    Set<InPredicate> subqueryInPredicates = analyzer.getSubqueryInPredicates();

    return new ExpressionAnalysis(
        expressionTypes, expressionCoercions, subqueryInPredicates, analyzer.getColumnReferences());
  }
예제 #2
0
 // TODO: temporary addition to infer result type from expression. fix this with the new planner
 // refactoring (martint)
 private Type extractType(Expression expression) {
   ExpressionAnalyzer expressionAnalyzer =
       new ExpressionAnalyzer(new Analysis(), session, metadata, experimentalSyntaxEnabled);
   List<Field> fields =
       IterableTransformer.<Symbol>on(DependencyExtractor.extractUnique(expression))
           .transform(
               new Function<Symbol, Field>() {
                 @Override
                 public Field apply(Symbol symbol) {
                   return Field.newUnqualified(
                       symbol.getName(), symbolAllocator.getTypes().get(symbol));
                 }
               })
           .list();
   return expressionAnalyzer.analyze(
       expression, new TupleDescriptor(fields), new AnalysisContext());
 }
예제 #3
0
  private static ExpressionAnalysis analyzeExpressions(
      Session session,
      Metadata metadata,
      SqlParser sqlParser,
      TupleDescriptor tupleDescriptor,
      Iterable<? extends Expression> expressions) {
    // expressions at this point can not have sub queries so deny all access checks
    // in the future, we will need a full access controller here to verify access to functions
    ExpressionAnalyzer analyzer =
        create(new Analysis(), session, metadata, sqlParser, new DenyAllAccessControl(), false);
    for (Expression expression : expressions) {
      analyzer.analyze(expression, tupleDescriptor, new AnalysisContext());
    }

    return new ExpressionAnalysis(
        analyzer.getExpressionTypes(),
        analyzer.getExpressionCoercions(),
        analyzer.getSubqueryInPredicates(),
        analyzer.getColumnReferences());
  }