Search in sources :

Example 6 with RelationUnknown

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

the class TableSettingsResolver method forPartitionedTable.

private static Settings forPartitionedTable(Metadata metadata, RelationName relationName) {
    String templateName = PartitionName.templateName(relationName.schema(), relationName.name());
    IndexTemplateMetadata templateMetadata = metadata.templates().get(templateName);
    if (templateMetadata == null) {
        throw new RelationUnknown(relationName);
    }
    return templateMetadata.getSettings();
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata)

Example 7 with RelationUnknown

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

the class Schemas method resolveTableInfo.

public TableInfo resolveTableInfo(QualifiedName ident, Operation operation, User user, SearchPath searchPath) {
    String identSchema = schemaName(ident);
    String tableName = relationName(ident);
    SchemaInfo schemaInfo;
    TableInfo tableInfo = null;
    if (identSchema == null) {
        for (String pathSchema : searchPath) {
            schemaInfo = schemas.get(pathSchema);
            if (schemaInfo != null) {
                tableInfo = schemaInfo.getTableInfo(tableName);
                if (tableInfo != null) {
                    break;
                }
            }
        }
        if (tableInfo == null) {
            SchemaInfo currentSchema = schemas.get(searchPath.currentSchema());
            if (currentSchema == null) {
                throw new RelationUnknown(tableName);
            } else {
                throw RelationUnknown.of(tableName, getSimilarTables(user, tableName, currentSchema.getTables()));
            }
        }
    } else {
        schemaInfo = schemas.get(identSchema);
        if (schemaInfo == null) {
            throw SchemaUnknownException.of(identSchema, getSimilarSchemas(user, identSchema));
        } else {
            tableInfo = schemaInfo.getTableInfo(tableName);
            if (tableInfo == null) {
                throw RelationUnknown.of(ident.toString(), getSimilarTables(user, tableName, schemaInfo.getTables()));
            }
        }
    }
    Operation.blockedRaiseException(tableInfo, operation);
    return tableInfo;
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) TableInfo(io.crate.metadata.table.TableInfo) BlobSchemaInfo(io.crate.metadata.blob.BlobSchemaInfo) PgCatalogSchemaInfo(io.crate.metadata.pgcatalog.PgCatalogSchemaInfo) SysSchemaInfo(io.crate.metadata.sys.SysSchemaInfo) SchemaInfo(io.crate.metadata.table.SchemaInfo) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo)

Example 8 with RelationUnknown

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

the class InternalBlobTableInfoFactory method resolveIndexMetadata.

private IndexMetadata resolveIndexMetadata(String tableName, ClusterState state) {
    String indexName = BlobIndex.fullIndexName(tableName);
    Index index;
    try {
        index = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), indexName)[0];
    } catch (IndexNotFoundException ex) {
        throw new RelationUnknown(indexName, ex);
    }
    return state.metadata().index(index);
}
Also used : RelationUnknown(io.crate.exceptions.RelationUnknown) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) BlobIndex(io.crate.blob.v2.BlobIndex) Index(org.elasticsearch.index.Index)

Example 9 with RelationUnknown

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

the class RestoreSnapshotPlan method bind.

@VisibleForTesting
public static BoundRestoreSnapshot bind(AnalyzedRestoreSnapshot restoreSnapshot, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row parameters, SubQueryResults subQueryResults, Schemas schemas) {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, parameters, subQueryResults);
    Settings settings = GenericPropertiesConverter.genericPropertiesToSettings(restoreSnapshot.properties().map(eval), SnapshotSettings.SETTINGS);
    HashSet<BoundRestoreSnapshot.RestoreTableInfo> restoreTables = new HashSet<>(restoreSnapshot.tables().size());
    for (Table<Symbol> table : restoreSnapshot.tables()) {
        var relationName = RelationName.of(table.getName(), txnCtx.sessionContext().searchPath().currentSchema());
        try {
            DocTableInfo docTableInfo = schemas.getTableInfo(relationName, Operation.RESTORE_SNAPSHOT);
            if (table.partitionProperties().isEmpty()) {
                throw new RelationAlreadyExists(relationName);
            }
            var partitionName = toPartitionName(docTableInfo, Lists2.map(table.partitionProperties(), x -> x.map(eval)));
            if (docTableInfo.partitions().contains(partitionName)) {
                throw new PartitionAlreadyExistsException(partitionName);
            }
            restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, partitionName));
        } catch (RelationUnknown | SchemaUnknownException e) {
            if (table.partitionProperties().isEmpty()) {
                restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, null));
            } else {
                var partitionName = toPartitionName(relationName, Lists2.map(table.partitionProperties(), x -> x.map(eval)));
                restoreTables.add(new BoundRestoreSnapshot.RestoreTableInfo(relationName, partitionName));
            }
        }
    }
    return new BoundRestoreSnapshot(restoreSnapshot.repository(), restoreSnapshot.snapshot(), restoreTables, restoreSnapshot.includeTables(), restoreSnapshot.includeCustomMetadata(), restoreSnapshot.customMetadataTypes(), restoreSnapshot.includeGlobalSettings(), restoreSnapshot.globalSettings(), settings);
}
Also used : PartitionAlreadyExistsException(io.crate.exceptions.PartitionAlreadyExistsException) IndexParts(io.crate.metadata.IndexParts) RelationName(io.crate.metadata.RelationName) CompletableFuture(java.util.concurrent.CompletableFuture) Operation(io.crate.metadata.table.Operation) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) Function(java.util.function.Function) PartitionName(io.crate.metadata.PartitionName) ArrayList(java.util.ArrayList) DependencyCarrier(io.crate.planner.DependencyCarrier) HashSet(java.util.HashSet) WAIT_FOR_COMPLETION(io.crate.analyze.SnapshotSettings.WAIT_FOR_COMPLETION) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) SchemaUnknownException(io.crate.exceptions.SchemaUnknownException) BoundRestoreSnapshot(io.crate.analyze.BoundRestoreSnapshot) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) GenericPropertiesConverter(io.crate.analyze.GenericPropertiesConverter) OneRowActionListener(io.crate.execution.support.OneRowActionListener) FutureActionListener(io.crate.action.FutureActionListener) PartitionPropertiesAnalyzer.toPartitionName(io.crate.analyze.PartitionPropertiesAnalyzer.toPartitionName) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) DocTableInfo(io.crate.metadata.doc.DocTableInfo) AnalyzedRestoreSnapshot(io.crate.analyze.AnalyzedRestoreSnapshot) NodeContext(io.crate.metadata.NodeContext) Table(io.crate.sql.tree.Table) Set(java.util.Set) Lists2(io.crate.common.collections.Lists2) SnapshotSettings(io.crate.analyze.SnapshotSettings) RowConsumer(io.crate.data.RowConsumer) List(java.util.List) Row(io.crate.data.Row) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) IGNORE_UNAVAILABLE(io.crate.analyze.SnapshotSettings.IGNORE_UNAVAILABLE) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) RelationUnknown(io.crate.exceptions.RelationUnknown) TransportGetSnapshotsAction(org.elasticsearch.action.admin.cluster.snapshots.get.TransportGetSnapshotsAction) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) BoundRestoreSnapshot(io.crate.analyze.BoundRestoreSnapshot) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationUnknown(io.crate.exceptions.RelationUnknown) Symbol(io.crate.expression.symbol.Symbol) SchemaUnknownException(io.crate.exceptions.SchemaUnknownException) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) Settings(org.elasticsearch.common.settings.Settings) SnapshotSettings(io.crate.analyze.SnapshotSettings) PartitionAlreadyExistsException(io.crate.exceptions.PartitionAlreadyExistsException) HashSet(java.util.HashSet) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 10 with RelationUnknown

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

the class RelationAnalyzer method visitTable.

@Override
protected AnalyzedRelation visitTable(Table<?> node, StatementAnalysisContext context) {
    QualifiedName tableQualifiedName = node.getName();
    SearchPath searchPath = context.sessionContext().searchPath();
    AnalyzedRelation relation;
    TableInfo tableInfo;
    try {
        tableInfo = schemas.resolveTableInfo(tableQualifiedName, context.currentOperation(), context.sessionContext().sessionUser(), searchPath);
        if (tableInfo instanceof DocTableInfo) {
            // Dispatching of doc relations is based on the returned class of the schema information.
            relation = new DocTableRelation((DocTableInfo) tableInfo);
        } else {
            relation = new TableRelation(tableInfo);
        }
    } catch (RelationUnknown e) {
        Tuple<ViewMetadata, RelationName> viewMetadata;
        try {
            viewMetadata = schemas.resolveView(tableQualifiedName, searchPath);
        } catch (RelationUnknown e1) {
            // don't shadow original exception, as looking for the view is just a fallback
            throw e;
        }
        ViewMetadata view = viewMetadata.v1();
        AnalyzedRelation resolvedView = SqlParser.createStatement(view.stmt()).accept(this, context);
        relation = new AnalyzedView(viewMetadata.v2(), view.owner(), resolvedView);
    }
    context.currentRelationContext().addSourceRelation(relation);
    return relation;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationUnknown(io.crate.exceptions.RelationUnknown) QualifiedName(io.crate.sql.tree.QualifiedName) SearchPath(io.crate.metadata.SearchPath) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Tuple(io.crate.common.collections.Tuple) ViewMetadata(io.crate.metadata.view.ViewMetadata)

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