Search in sources :

Example 1 with RelationValidationException

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

the class AccessControlMaySeeTest method testTableScopeException.

@Test
public void testTableScopeException() throws Exception {
    accessControl.ensureMaySee(new RelationValidationException(List.of(RelationName.fromIndexName("users"), RelationName.fromIndexName("my_schema.foo")), "bla"));
    assertAskedAnyForTable("doc.users");
    assertAskedAnyForTable("my_schema.foo");
}
Also used : RelationValidationException(io.crate.exceptions.RelationValidationException) Test(org.junit.Test)

Example 2 with RelationValidationException

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

the class RelationAnalyzer method visitJoin.

@Override
protected AnalyzedRelation visitJoin(Join node, StatementAnalysisContext statementContext) {
    AnalyzedRelation leftRel = node.getLeft().accept(this, statementContext);
    AnalyzedRelation rightRel = node.getRight().accept(this, statementContext);
    RelationAnalysisContext relationContext = statementContext.currentRelationContext();
    Optional<JoinCriteria> optCriteria = node.getCriteria();
    Symbol joinCondition = null;
    if (optCriteria.isPresent()) {
        JoinCriteria joinCriteria = optCriteria.get();
        if (joinCriteria instanceof JoinOn || joinCriteria instanceof JoinUsing) {
            final CoordinatorTxnCtx coordinatorTxnCtx = statementContext.transactionContext();
            ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, nodeCtx, statementContext.paramTyeHints(), new FullQualifiedNameFieldProvider(relationContext.sources(), relationContext.parentSources(), coordinatorTxnCtx.sessionContext().searchPath().currentSchema()), new SubqueryAnalyzer(this, statementContext));
            Expression expr;
            if (joinCriteria instanceof JoinOn) {
                expr = ((JoinOn) joinCriteria).getExpression();
            } else {
                expr = JoinUsing.toExpression(leftRel.relationName().toQualifiedName(), rightRel.relationName().toQualifiedName(), ((JoinUsing) joinCriteria).getColumns());
            }
            try {
                joinCondition = expressionAnalyzer.convert(expr, relationContext.expressionAnalysisContext());
            } catch (RelationUnknown e) {
                throw new RelationValidationException(e.getTableIdents(), String.format(Locale.ENGLISH, "missing FROM-clause entry for relation '%s'", e.getTableIdents()));
            }
        } 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 : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) RelationUnknown(io.crate.exceptions.RelationUnknown) Symbol(io.crate.expression.symbol.Symbol) ExpressionAnalyzer(io.crate.analyze.expressions.ExpressionAnalyzer) RelationValidationException(io.crate.exceptions.RelationValidationException) JoinUsing(io.crate.sql.tree.JoinUsing) Expression(io.crate.sql.tree.Expression) JoinCriteria(io.crate.sql.tree.JoinCriteria) SubqueryAnalyzer(io.crate.analyze.expressions.SubqueryAnalyzer) JoinOn(io.crate.sql.tree.JoinOn)

Aggregations

RelationValidationException (io.crate.exceptions.RelationValidationException)2 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 SubqueryAnalyzer (io.crate.analyze.expressions.SubqueryAnalyzer)1 RelationUnknown (io.crate.exceptions.RelationUnknown)1 Symbol (io.crate.expression.symbol.Symbol)1 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)1 Expression (io.crate.sql.tree.Expression)1 JoinCriteria (io.crate.sql.tree.JoinCriteria)1 JoinOn (io.crate.sql.tree.JoinOn)1 JoinUsing (io.crate.sql.tree.JoinUsing)1 Test (org.junit.Test)1