use of io.crate.exceptions.RelationAlreadyExists in project crate by crate.
the class CreateViewPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
User owner = createViewStmt.owner();
String formattedQuery = SqlFormatter.formatSql(createViewStmt.query(), makeExpressions(params));
ensureFormattedQueryCanStillBeAnalyzed(createViewStmt.name(), dependencies.nodeContext(), dependencies.schemas(), plannerContext.transactionContext(), formattedQuery, createViewStmt.replaceExisting());
CreateViewRequest request = new CreateViewRequest(createViewStmt.name(), formattedQuery, createViewStmt.replaceExisting(), owner == null ? null : owner.name());
dependencies.createViewAction().execute(request, new OneRowActionListener<>(consumer, resp -> {
if (resp.alreadyExistsFailure()) {
throw new RelationAlreadyExists(createViewStmt.name());
}
return new Row1(1L);
}));
}
use of io.crate.exceptions.RelationAlreadyExists in project crate by crate.
the class TransportCreateTableAction method masterOperation.
@Override
protected void masterOperation(final CreateTableRequest request, final ClusterState state, final ActionListener<CreateTableResponse> listener) {
final RelationName relationName = request.getTableName();
if (viewsExists(relationName, state)) {
listener.onFailure(new RelationAlreadyExists(relationName));
return;
}
if (request.getCreateIndexRequest() != null) {
CreateIndexRequest createIndexRequest = request.getCreateIndexRequest();
ActionListener<CreateIndexResponse> wrappedListener = ActionListener.wrap(response -> listener.onResponse(new CreateTableResponse(response.isShardsAcknowledged())), listener::onFailure);
transportCreateIndexAction.masterOperation(createIndexRequest, state, wrappedListener);
} else if (request.getPutIndexTemplateRequest() != null) {
PutIndexTemplateRequest putIndexTemplateRequest = request.getPutIndexTemplateRequest();
ActionListener<AcknowledgedResponse> wrappedListener = ActionListener.wrap(response -> listener.onResponse(new CreateTableResponse(response.isAcknowledged())), listener::onFailure);
transportPutIndexTemplateAction.masterOperation(putIndexTemplateRequest, state, wrappedListener);
} else {
throw new IllegalStateException("Unknown table request");
}
}
use of io.crate.exceptions.RelationAlreadyExists 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);
}
use of io.crate.exceptions.RelationAlreadyExists in project crate by crate.
the class CreateBlobTableAnalyzer method analyze.
public AnalyzedCreateBlobTable analyze(CreateBlobTable<Expression> node, ParamTypeHints paramTypeHints, CoordinatorTxnCtx txnCtx) {
var exprAnalyzerWithoutFields = new ExpressionAnalyzer(txnCtx, nodeCtx, paramTypeHints, FieldProvider.UNSUPPORTED, null);
var exprCtx = new ExpressionAnalysisContext(txnCtx.sessionContext());
CreateBlobTable<Symbol> createBlobTable = node.map(x -> exprAnalyzerWithoutFields.convert(x, exprCtx));
RelationName relationName = RelationName.fromBlobTable(createBlobTable.name());
relationName.ensureValidForRelationCreation();
if (schemas.tableExists(relationName)) {
throw new RelationAlreadyExists(relationName);
}
return new AnalyzedCreateBlobTable(relationName, createBlobTable);
}
Aggregations