use of io.crate.metadata.TableIdent in project crate by crate.
the class DocSchemaInfo method tableNames.
private Collection<String> tableNames() {
Set<String> tables = new HashSet<>();
Stream.of(clusterService.state().metaData().concreteAllOpenIndices()).filter(NO_BLOB).filter(NO_PARTITION).filter(this::indexMatchesSchema).map(DocSchemaInfo::getTableNameFromIndexName).forEach(tables::add);
// Search for partitioned table templates
UnmodifiableIterator<String> templates = clusterService.state().metaData().getTemplates().keysIt();
while (templates.hasNext()) {
String templateName = templates.next();
if (!PartitionName.isPartition(templateName)) {
continue;
}
try {
PartitionName partitionName = PartitionName.fromIndexOrTemplate(templateName);
TableIdent ti = partitionName.tableIdent();
if (schemaName.equalsIgnoreCase(ti.schema())) {
tables.add(ti.name());
}
} catch (IllegalArgumentException e) {
// do nothing
}
}
return tables;
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class FetchPhase method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
executionPhaseId = in.readVInt();
int n = in.readVInt();
executionNodes = new HashSet<>(n);
for (int i = 0; i < n; i++) {
executionNodes.add(in.readString());
}
n = in.readVInt();
bases = new TreeMap<>();
for (int i = 0; i < n; i++) {
bases.put(in.readString(), in.readVInt());
}
n = in.readVInt();
fetchRefs = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
fetchRefs.add(Reference.fromStream(in));
}
n = in.readVInt();
tableIndices = HashMultimap.create(n, 1);
for (int i = 0; i < n; i++) {
TableIdent ti = new TableIdent(in);
int nn = in.readVInt();
for (int j = 0; j < nn; j++) {
tableIndices.put(ti, in.readString());
}
}
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class DropBlobTableAnalyzer method analyze.
public DropBlobTableAnalyzedStatement analyze(DropBlobTable node) {
TableIdent tableIdent = tableToIdent(node.table());
BlobTableInfo tableInfo = null;
boolean isNoop = false;
try {
tableInfo = (BlobTableInfo) schemas.getTableInfo(tableIdent);
} catch (ResourceUnknownException e) {
if (node.ignoreNonExistentTable()) {
isNoop = true;
} else {
throw e;
}
}
return new DropBlobTableAnalyzedStatement(tableInfo, isNoop, node.ignoreNonExistentTable());
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class DropTableAnalyzer method analyze.
public DropTableAnalyzedStatement analyze(DropTable node, @Nullable String defaultSchema) {
TableIdent tableIdent = TableIdent.of(node.table(), defaultSchema);
DocTableInfo tableInfo = null;
boolean isNoop = false;
try {
tableInfo = schemas.getDroppableTable(tableIdent);
} catch (ResourceUnknownException e) {
if (node.dropIfExists()) {
isNoop = true;
} else {
throw e;
}
}
if (!isNoop) {
Operation.blockedRaiseException(tableInfo, Operation.DROP);
}
return new DropTableAnalyzedStatement(tableInfo, isNoop, node.dropIfExists());
}
use of io.crate.metadata.TableIdent in project crate by crate.
the class RestoreSnapshotAnalyzer method analyze.
public RestoreSnapshotAnalyzedStatement analyze(RestoreSnapshot node, Analysis analysis) {
List<String> nameParts = node.name().getParts();
Preconditions.checkArgument(nameParts.size() == 2, "Snapshot name not supported, only <repository>.<snapshot> works.");
String repositoryName = nameParts.get(0);
repositoryService.failIfRepositoryDoesNotExist(repositoryName);
// validate and extract settings
Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
if (node.tableList().isPresent()) {
List<Table> tableList = node.tableList().get();
Set<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> restoreTables = new HashSet<>(tableList.size());
for (Table table : tableList) {
TableIdent tableIdent = TableIdent.of(table, analysis.sessionContext().defaultSchema());
boolean tableExists = schemas.tableExists(tableIdent);
if (tableExists) {
if (table.partitionProperties().isEmpty()) {
throw new TableAlreadyExistsException(tableIdent);
}
TableInfo tableInfo = schemas.getTableInfo(tableIdent);
if (!(tableInfo instanceof DocTableInfo)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot restore snapshot of tables in schema '%s'", tableInfo.ident().schema()));
}
DocTableInfo docTableInfo = ((DocTableInfo) tableInfo);
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
if (docTableInfo.partitions().contains(partitionName)) {
throw new PartitionAlreadyExistsException(partitionName);
}
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
} else {
if (table.partitionProperties().isEmpty()) {
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, null));
} else {
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, null, table.partitionProperties(), analysis.parameterContext().parameters());
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
}
}
}
return RestoreSnapshotAnalyzedStatement.forTables(nameParts.get(1), repositoryName, settings, ImmutableList.copyOf(restoreTables));
} else {
return RestoreSnapshotAnalyzedStatement.all(nameParts.get(1), repositoryName, settings);
}
}
Aggregations