Search in sources :

Example 16 with TableIdent

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;
}
Also used : PartitionName(io.crate.metadata.PartitionName) TableIdent(io.crate.metadata.TableIdent) HashSet(java.util.HashSet)

Example 17 with TableIdent

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());
        }
    }
}
Also used : TableIdent(io.crate.metadata.TableIdent)

Example 18 with TableIdent

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());
}
Also used : BlobTableInfo(io.crate.metadata.blob.BlobTableInfo) TableIdent(io.crate.metadata.TableIdent) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException)

Example 19 with TableIdent

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());
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableIdent(io.crate.metadata.TableIdent) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException)

Example 20 with TableIdent

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);
    }
}
Also used : TableAlreadyExistsException(io.crate.exceptions.TableAlreadyExistsException) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Table(io.crate.sql.tree.Table) TableIdent(io.crate.metadata.TableIdent) PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Settings(org.elasticsearch.common.settings.Settings) PartitionAlreadyExistsException(io.crate.exceptions.PartitionAlreadyExistsException) HashSet(java.util.HashSet)

Aggregations

TableIdent (io.crate.metadata.TableIdent)41 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)15 PartitionName (io.crate.metadata.PartitionName)8 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)7 Before (org.junit.Before)7 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 List (java.util.List)5 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 BytesRef (org.apache.lucene.util.BytesRef)4 TableRelation (io.crate.analyze.relations.TableRelation)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 TestingTableInfo (io.crate.metadata.table.TestingTableInfo)3 SqlExpressions (io.crate.testing.SqlExpressions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 SharedShardContexts (io.crate.action.job.SharedShardContexts)2