Пример #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
  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());
  }