Search in sources :

Example 11 with RelationUnknown

use of io.crate.exceptions.RelationUnknown 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)

Example 12 with RelationUnknown

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

the class DocTableInfoBuilder method docIndexMetadata.

private DocIndexMetadata docIndexMetadata() {
    DocIndexMetadata docIndexMetadata;
    String templateName = PartitionName.templateName(ident.schema(), ident.name());
    if (metadata.getTemplates().containsKey(templateName)) {
        docIndexMetadata = buildDocIndexMetadataFromTemplate(ident.indexNameOrAlias(), templateName);
        // We need all concrete indices, regardless of their state, for operations such as reopening.
        concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), ident.indexNameOrAlias());
        // We need all concrete open indices, as closed indices must not appear in the routing.
        concreteOpenIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed()), ident.indexNameOrAlias());
    } else {
        try {
            concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.strictExpandOpen(), ident.indexNameOrAlias());
            concreteOpenIndices = concreteIndices;
            if (concreteIndices.length == 0) {
                // no matching index found
                throw new RelationUnknown(ident);
            }
            docIndexMetadata = buildDocIndexMetadata(concreteIndices[0]);
        } catch (IndexNotFoundException ex) {
            throw new RelationUnknown(ident.fqn(), ex);
        }
    }
    return docIndexMetadata;
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 13 with RelationUnknown

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

the class DropTableAnalyzer method analyze.

private <T extends TableInfo> AnalyzedDropTable<T> analyze(QualifiedName name, boolean dropIfExists, SessionContext sessionContext) {
    T tableInfo;
    RelationName tableName;
    boolean maybeCorrupt = false;
    try {
        // noinspection unchecked
        tableInfo = (T) schemas.resolveTableInfo(name, Operation.DROP, sessionContext.sessionUser(), sessionContext.searchPath());
        tableName = tableInfo.ident();
    } catch (SchemaUnknownException | RelationUnknown e) {
        tableName = RelationName.of(name, sessionContext.searchPath().currentSchema());
        var metadata = clusterService.state().metadata();
        var indexNameOrAlias = tableName.indexNameOrAlias();
        if (metadata.hasIndex(indexNameOrAlias) || metadata.templates().containsKey(indexNameOrAlias)) {
            tableInfo = null;
            maybeCorrupt = true;
        } else if (dropIfExists) {
            tableInfo = null;
        } else {
            throw e;
        }
    } catch (OperationOnInaccessibleRelationException e) {
        throw e;
    } catch (Throwable t) {
        if (!sessionContext.sessionUser().isSuperUser()) {
            throw t;
        }
        tableInfo = null;
        maybeCorrupt = true;
        tableName = RelationName.of(name, sessionContext.searchPath().currentSchema());
        LOGGER.info("Unexpected error resolving table during DROP TABLE operation on {}. " + "Proceeding with operation as table schema may be corrupt (error={})", tableName, t);
    }
    return new AnalyzedDropTable<>(tableInfo, dropIfExists, tableName, maybeCorrupt);
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) SchemaUnknownException(io.crate.exceptions.SchemaUnknownException) OperationOnInaccessibleRelationException(io.crate.exceptions.OperationOnInaccessibleRelationException) RelationName(io.crate.metadata.RelationName)

Example 14 with RelationUnknown

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

the class ReservoirSampler method getSamples.

public Samples getSamples(RelationName relationName, List<Reference> columns, int maxSamples) {
    TableInfo table;
    try {
        table = schemas.getTableInfo(relationName);
    } catch (RelationUnknown e) {
        return Samples.EMPTY;
    }
    if (!(table instanceof DocTableInfo)) {
        return Samples.EMPTY;
    }
    DocTableInfo docTable = (DocTableInfo) table;
    Random random = Randomness.get();
    Metadata metadata = clusterService.state().metadata();
    CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
    List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
    List<Engine.Searcher> searchersToRelease = new ArrayList<>();
    CircuitBreaker breaker = circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY);
    RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "Reservoir-sampling"), MAX_BLOCK_SIZE_IN_BYTES);
    try {
        return getSamples(columns, maxSamples, docTable, random, metadata, coordinatorTxnCtx, streamers, searchersToRelease, ramAccounting);
    } finally {
        ramAccounting.close();
        for (Engine.Searcher searcher : searchersToRelease) {
            searcher.close();
        }
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) RamAccounting(io.crate.breaker.RamAccounting) RelationUnknown(io.crate.exceptions.RelationUnknown) Metadata(org.elasticsearch.cluster.metadata.Metadata) ArrayList(java.util.ArrayList) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Random(java.util.Random) Streamer(io.crate.Streamer) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Engine(org.elasticsearch.index.engine.Engine)

Aggregations

RelationUnknown (io.crate.exceptions.RelationUnknown)14 RelationName (io.crate.metadata.RelationName)4 TableInfo (io.crate.metadata.table.TableInfo)4 Symbol (io.crate.expression.symbol.Symbol)3 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)3 DocTableInfo (io.crate.metadata.doc.DocTableInfo)3 ArrayList (java.util.ArrayList)3 SchemaUnknownException (io.crate.exceptions.SchemaUnknownException)2 BlobSchemaInfo (io.crate.metadata.blob.BlobSchemaInfo)2 InformationSchemaInfo (io.crate.metadata.information.InformationSchemaInfo)2 PgCatalogSchemaInfo (io.crate.metadata.pgcatalog.PgCatalogSchemaInfo)2 SysSchemaInfo (io.crate.metadata.sys.SysSchemaInfo)2 SchemaInfo (io.crate.metadata.table.SchemaInfo)2 ViewsMetadata (io.crate.metadata.view.ViewsMetadata)2 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)2 Streamer (io.crate.Streamer)1 FutureActionListener (io.crate.action.FutureActionListener)1 AnalyzedRestoreSnapshot (io.crate.analyze.AnalyzedRestoreSnapshot)1 BoundRestoreSnapshot (io.crate.analyze.BoundRestoreSnapshot)1 GenericPropertiesConverter (io.crate.analyze.GenericPropertiesConverter)1