Search in sources :

Example 1 with RelationUnknownException

use of io.crate.exceptions.RelationUnknownException in project crate by crate.

the class RelationAnalyzer method visitJoin.

@Override
protected AnalyzedRelation visitJoin(Join node, StatementAnalysisContext statementContext) {
    process(node.getLeft(), statementContext);
    process(node.getRight(), statementContext);
    RelationAnalysisContext relationContext = statementContext.currentRelationContext();
    Optional<JoinCriteria> optCriteria = node.getCriteria();
    Symbol joinCondition = null;
    if (optCriteria.isPresent()) {
        JoinCriteria joinCriteria = optCriteria.get();
        if (joinCriteria instanceof JoinOn) {
            ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, statementContext.sessionContext(), statementContext.convertParamFunction(), new FullQualifedNameFieldProvider(relationContext.sources()), new SubqueryAnalyzer(this, statementContext));
            try {
                joinCondition = expressionAnalyzer.convert(((JoinOn) joinCriteria).getExpression(), relationContext.expressionAnalysisContext());
            } catch (RelationUnknownException e) {
                throw new ValidationException(String.format(Locale.ENGLISH, "missing FROM-clause entry for relation '%s'", e.qualifiedName()));
            }
        } else {
            throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "join criteria %s not supported", joinCriteria.getClass().getSimpleName()));
        }
    }
    relationContext.addJoinType(JoinType.values()[node.getType().ordinal()], joinCondition);
    return null;
}
Also used : RelationUnknownException(io.crate.exceptions.RelationUnknownException) ValidationException(io.crate.exceptions.ValidationException) Symbol(io.crate.analyze.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) SubqueryAnalyzer(io.crate.analyze.expressions.SubqueryAnalyzer)

Aggregations

ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 SubqueryAnalyzer (io.crate.analyze.expressions.SubqueryAnalyzer)1 Symbol (io.crate.analyze.symbol.Symbol)1 RelationUnknownException (io.crate.exceptions.RelationUnknownException)1 ValidationException (io.crate.exceptions.ValidationException)1