Search in sources :

Example 11 with ExpressionAnalyzer

use of io.crate.analyze.expressions.ExpressionAnalyzer 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)11 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)9 Symbol (io.crate.analyze.symbol.Symbol)9 DocTableInfo (io.crate.metadata.doc.DocTableInfo)4 DocTableRelation (io.crate.analyze.relations.DocTableRelation)3 TableInfo (io.crate.metadata.table.TableInfo)3 SubqueryAnalyzer (io.crate.analyze.expressions.SubqueryAnalyzer)2 TableReferenceResolver (io.crate.analyze.expressions.TableReferenceResolver)2 ValueNormalizer (io.crate.analyze.expressions.ValueNormalizer)2 WhereClauseAnalyzer (io.crate.analyze.where.WhereClauseAnalyzer)2 UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)2 Assignment (io.crate.sql.tree.Assignment)2 Settings (org.elasticsearch.common.settings.Settings)2 ImmutableList (com.google.common.collect.ImmutableList)1 FieldProvider (io.crate.analyze.relations.FieldProvider)1 NameFieldProvider (io.crate.analyze.relations.NameFieldProvider)1 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)1 SelectAnalysis (io.crate.analyze.relations.select.SelectAnalysis)1 DynamicReference (io.crate.analyze.symbol.DynamicReference)1 Function (io.crate.analyze.symbol.Function)1