use of io.crate.metadata.RelationName in project crate by crate.
the class NodeFetchOperation method doFetch.
private CompletableFuture<? extends IntObjectMap<StreamBucket>> doFetch(FetchTask fetchTask, IntObjectMap<IntArrayList> toFetch) throws Exception {
HashMap<RelationName, TableFetchInfo> tableFetchInfos = getTableFetchInfos(fetchTask);
// RamAccounting is per doFetch call instead of per FetchTask/fetchPhase
// To be able to free up the memory count when the operation is complete
final var ramAccounting = ConcurrentRamAccounting.forCircuitBreaker("fetch-" + fetchTask.id(), circuitBreaker);
ArrayList<Supplier<StreamBucket>> collectors = new ArrayList<>(toFetch.size());
for (IntObjectCursor<IntArrayList> toFetchCursor : toFetch) {
final int readerId = toFetchCursor.key;
final IntArrayList docIds = toFetchCursor.value;
RelationName ident = fetchTask.tableIdent(readerId);
final TableFetchInfo tfi = tableFetchInfos.get(ident);
assert tfi != null : "tfi must not be null";
var collector = tfi.createCollector(readerId, new BlockBasedRamAccounting(ramAccounting::addBytes, BlockBasedRamAccounting.MAX_BLOCK_SIZE_IN_BYTES));
collectors.add(() -> collector.collect(docIds));
}
return ThreadPools.runWithAvailableThreads(executor, ThreadPools.numIdleThreads(executor, numProcessors), collectors).thenApply(buckets -> {
var toFetchIt = toFetch.iterator();
assert toFetch.size() == buckets.size() : "Must have a bucket per reader and they must be in the same order";
IntObjectHashMap<StreamBucket> bucketByReader = new IntObjectHashMap<>(toFetch.size());
for (var bucket : buckets) {
assert toFetchIt.hasNext() : "toFetchIt must have an element if there is one in buckets";
int readerId = toFetchIt.next().key;
bucketByReader.put(readerId, bucket);
}
return bucketByReader;
}).whenComplete((result, err) -> ramAccounting.close());
}
use of io.crate.metadata.RelationName in project crate by crate.
the class ProjectionToProjectorVisitor method visitSysUpdateProjection.
@Override
public Projector visitSysUpdateProjection(SysUpdateProjection projection, Context context) {
Map<Reference, Symbol> assignments = projection.assignments();
assert !assignments.isEmpty() : "at least one assignment is required";
List<Input<?>> valueInputs = new ArrayList<>(assignments.size());
List<ColumnIdent> assignmentCols = new ArrayList<>(assignments.size());
RelationName relationName = null;
InputFactory.Context<NestableCollectExpression<?, ?>> readCtx = null;
for (Map.Entry<Reference, Symbol> e : assignments.entrySet()) {
Reference ref = e.getKey();
assert relationName == null || relationName.equals(ref.ident().tableIdent()) : "mixed table assignments found";
relationName = ref.ident().tableIdent();
if (readCtx == null) {
StaticTableDefinition<?> tableDefinition = staticTableDefinitionGetter.apply(relationName);
readCtx = inputFactory.ctxForRefs(context.txnCtx, tableDefinition.getReferenceResolver());
}
assignmentCols.add(ref.column());
Input<?> sourceInput = readCtx.add(e.getValue());
valueInputs.add(sourceInput);
}
SysRowUpdater<?> rowUpdater = sysUpdaterGetter.apply(relationName);
assert readCtx != null : "readCtx must not be null";
assert rowUpdater != null : "row updater needs to exist";
Consumer<Object> rowWriter = rowUpdater.newRowWriter(assignmentCols, valueInputs, readCtx.expressions());
if (projection.returnValues() == null) {
return new SysUpdateProjector(rowWriter);
} else {
InputFactory.Context<NestableCollectExpression<SysNodeCheck, ?>> cntx = new InputFactory(nodeCtx).ctxForRefs(context.txnCtx, new StaticTableReferenceResolver<>(SysNodeChecksTableInfo.create().expressions()));
cntx.add(List.of(projection.returnValues()));
return new SysUpdateResultSetProjector(rowUpdater, rowWriter, cntx.expressions(), cntx.topLevelInputs());
}
}
use of io.crate.metadata.RelationName in project crate by crate.
the class AbstractOpenCloseTableClusterStateTaskExecutor method prepare.
protected Context prepare(ClusterState currentState, OpenCloseTableOrPartitionRequest request) {
RelationName relationName = request.tableIdent();
String partitionIndexName = request.partitionIndexName();
Metadata metadata = currentState.metadata();
String indexToResolve = partitionIndexName != null ? partitionIndexName : relationName.indexNameOrAlias();
PartitionName partitionName = partitionIndexName != null ? PartitionName.fromIndexOrTemplate(partitionIndexName) : null;
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(currentState, IndicesOptions.lenientExpandOpen(), indexToResolve);
Set<IndexMetadata> indicesMetadata = DDLClusterStateHelpers.indexMetadataSetFromIndexNames(metadata, concreteIndices, indexState());
IndexTemplateMetadata indexTemplateMetadata = null;
if (partitionIndexName == null) {
indexTemplateMetadata = DDLClusterStateHelpers.templateMetadata(metadata, relationName);
}
return new Context(indicesMetadata, indexTemplateMetadata, partitionName);
}
use of io.crate.metadata.RelationName 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.metadata.RelationName in project crate by crate.
the class CreateAlterPartitionedTableAnalyzerTest method testAlterPartitionedTablePartition.
@Test
public void testAlterPartitionedTablePartition() {
BoundAlterTable analysis = analyze("alter table parted partition (date=1395874800000) set (number_of_replicas='0-all')");
assertThat(analysis.partitionName().isPresent(), is(true));
assertThat(analysis.partitionName().get(), is(new PartitionName(new RelationName("doc", "parted"), Collections.singletonList("1395874800000"))));
assertEquals("0-all", analysis.tableParameter().settings().get(AutoExpandReplicas.SETTING.getKey()));
}
Aggregations