use of io.crate.metadata.RelationName in project crate by crate.
the class AlterTableOperation method executeAlterTableRenameTable.
public CompletableFuture<Long> executeAlterTableRenameTable(AnalyzedAlterTableRename statement) {
DocTableInfo sourceTableInfo = statement.sourceTableInfo();
RelationName sourceRelationName = sourceTableInfo.ident();
RelationName targetRelationName = statement.targetTableIdent();
return renameTable(sourceRelationName, targetRelationName, sourceTableInfo.isPartitioned());
}
use of io.crate.metadata.RelationName in project crate by crate.
the class AlterTableOperation method executeAlterTableAddColumn.
public CompletableFuture<Long> executeAlterTableAddColumn(final BoundAddColumn analysis) {
FutureActionListener<AcknowledgedResponse, Long> result = new FutureActionListener<>(r -> -1L);
if (analysis.newPrimaryKeys() || analysis.hasNewGeneratedColumns()) {
RelationName ident = analysis.table().ident();
String stmt = String.format(Locale.ENGLISH, "SELECT COUNT(*) FROM \"%s\".\"%s\"", ident.schema(), ident.name());
try {
session().quickExec(stmt, new ResultSetReceiver(analysis, result), Row.EMPTY);
} catch (Throwable t) {
result.completeExceptionally(t);
}
} else {
return addColumnToTable(analysis, result);
}
return result;
}
use of io.crate.metadata.RelationName 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.metadata.RelationName in project crate by crate.
the class SwapRelationsOperation method applyDropRelations.
private UpdatedState applyDropRelations(ClusterState state, UpdatedState updatedState, List<RelationName> dropRelations) {
ClusterState stateAfterRename = updatedState.newState;
Metadata.Builder updatedMetadata = Metadata.builder(stateAfterRename.metadata());
RoutingTable.Builder routingBuilder = RoutingTable.builder(stateAfterRename.routingTable());
for (RelationName dropRelation : dropRelations) {
for (Index index : indexNameResolver.concreteIndices(state, IndicesOptions.LENIENT_EXPAND_OPEN, dropRelation.indexNameOrAlias())) {
String indexName = index.getName();
updatedMetadata.remove(indexName);
routingBuilder.remove(indexName);
updatedState.newIndices.remove(indexName);
}
}
ClusterState stateAfterDropRelations = ClusterState.builder(stateAfterRename).metadata(updatedMetadata).routingTable(routingBuilder.build()).build();
return new UpdatedState(allocationService.reroute(applyDropTableClusterStateModifiers(stateAfterDropRelations, dropRelations), "indices drop after name switch"), updatedState.newIndices);
}
use of io.crate.metadata.RelationName in project crate by crate.
the class JoinOperations method convertImplicitJoinConditionsToJoinPairs.
/**
* Converts any implicit join conditions of the WHERE clause to explicit {@link JoinPair}.
* Every join condition that gets to be converted is removed from the {@code splitQueries}
*
* @param explicitJoinPairs The explicitJoinPairs as originally written in the query
* @param splitQueries The remaining queries of the WHERE clause split by involved relations
* @return the new list of {@link JoinPair}
*/
public static List<JoinPair> convertImplicitJoinConditionsToJoinPairs(List<JoinPair> explicitJoinPairs, Map<Set<RelationName>, Symbol> splitQueries) {
Iterator<Map.Entry<Set<RelationName>, Symbol>> queryIterator = splitQueries.entrySet().iterator();
ArrayList<JoinPair> newJoinPairs = new ArrayList<>(explicitJoinPairs.size() + splitQueries.size());
newJoinPairs.addAll(explicitJoinPairs);
while (queryIterator.hasNext()) {
Map.Entry<Set<RelationName>, Symbol> queryEntry = queryIterator.next();
Set<RelationName> relations = queryEntry.getKey();
if (relations.size() == 2) {
// If more than 2 relations are involved it cannot be converted to a JoinPair
Symbol implicitJoinCondition = queryEntry.getValue();
JoinPair newJoinPair = null;
int existingJoinPairIdx = -1;
for (int i = 0; i < explicitJoinPairs.size(); i++) {
JoinPair joinPair = explicitJoinPairs.get(i);
if (relations.contains(joinPair.left()) && relations.contains(joinPair.right())) {
existingJoinPairIdx = i;
//
if (joinPair.joinType() == JoinType.INNER || joinPair.joinType() == JoinType.CROSS) {
newJoinPair = JoinPair.of(joinPair.left(), joinPair.right(), JoinType.INNER, mergeJoinConditions(joinPair.condition(), implicitJoinCondition));
queryIterator.remove();
} else {
newJoinPair = joinPair;
}
}
}
if (newJoinPair == null) {
Iterator<RelationName> namesIter = relations.iterator();
newJoinPair = JoinPair.of(namesIter.next(), namesIter.next(), JoinType.INNER, implicitJoinCondition);
queryIterator.remove();
newJoinPairs.add(newJoinPair);
} else {
newJoinPairs.set(existingJoinPairIdx, newJoinPair);
}
}
}
return newJoinPairs;
}
Aggregations