Search in sources :

Example 21 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class CreateBlobTableAnalyzer method analyze.

public CreateBlobTableAnalyzedStatement analyze(CreateBlobTable node, ParameterContext parameterContext) {
    CreateBlobTableAnalyzedStatement statement = new CreateBlobTableAnalyzedStatement();
    TableIdent tableIdent = BlobTableAnalyzer.tableToIdent(node.name());
    statement.table(tableIdent, schemas);
    int numShards;
    Optional<ClusteredBy> clusteredBy = node.clusteredBy();
    if (clusteredBy.isPresent()) {
        numShards = numberOfShards.fromClusteredByClause(clusteredBy.get(), parameterContext.parameters());
    } else {
        numShards = numberOfShards.defaultNumberOfShards();
    }
    statement.tableParameter().settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards);
    // apply default in case it is not specified in the genericProperties,
    // if it is it will get overwritten afterwards.
    TablePropertiesAnalyzer.analyze(statement.tableParameter(), new BlobTableParameterInfo(), node.genericProperties(), parameterContext.parameters(), true);
    return statement;
}
Also used : ClusteredBy(io.crate.sql.tree.ClusteredBy) TableIdent(io.crate.metadata.TableIdent)

Example 22 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class DocTableInfoBuilderTest method testNoTableInfoFromOrphanedPartition.

@Test
public void testNoTableInfoFromOrphanedPartition() throws Exception {
    String schemaName = randomSchema();
    PartitionName partitionName = new PartitionName(schemaName, "test", Collections.singletonList(new BytesRef("boo")));
    IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(partitionName.asIndexName()).settings(Settings.builder().put("index.version.created", Version.CURRENT).build()).numberOfReplicas(0).numberOfShards(5).putMapping(Constants.DEFAULT_MAPPING_TYPE, "{" + "  \"default\": {" + "    \"properties\":{" + "      \"id\": {" + "         \"type\": \"integer\"," + "         \"index\": \"not_analyzed\"" + "      }" + "    }" + "  }" + "}");
    MetaData metaData = MetaData.builder().put(indexMetaDataBuilder).build();
    NoopClusterService clusterService = new NoopClusterService(ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build());
    DocTableInfoBuilder builder = new DocTableInfoBuilder(functions, new TableIdent(schemaName, "test"), clusterService, new IndexNameExpressionResolver(Settings.EMPTY), mock(TransportPutIndexTemplateAction.class), executorService, false);
    expectedException.expect(TableUnknownException.class);
    expectedException.expectMessage(String.format(Locale.ENGLISH, "Table '%s.test' unknown", schemaName));
    builder.build();
}
Also used : PartitionName(io.crate.metadata.PartitionName) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) TableIdent(io.crate.metadata.TableIdent) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) BytesRef(org.apache.lucene.util.BytesRef) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 23 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class SnapshotRestoreDDLDispatcherTest method testResolveUnknownTableFromSnapshot.

@Test
public void testResolveUnknownTableFromSnapshot() throws Exception {
    expectedException.expect(TableUnknownException.class);
    expectedException.expectMessage("Table 'doc.t1' unknown");
    SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener.resolveIndexNameFromSnapshot(new TableIdent(null, "t1"), Collections.emptyList());
}
Also used : TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 24 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class SnapshotRestoreDDLDispatcherTest method testResolveMultiTablesIndexNamesFromSnapshot.

@Test
public void testResolveMultiTablesIndexNamesFromSnapshot() throws Exception {
    List<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> tables = Arrays.asList(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_table"), null), new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_partitioned_table"), null));
    List<SnapshotInfo> snapshots = Arrays.asList(new SnapshotInfo(new Snapshot("snapshot01", Collections.singletonList(".partitioned.my_partitioned_table.046jcchm6krj4e1g60o30c0"), 0)), new SnapshotInfo(new Snapshot("snapshot03", Collections.singletonList("my_table"), 0)));
    CompletableFuture<List<String>> future = new CompletableFuture<>();
    SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener actionListener = new SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener(future, tables, new HashSet<>());
    // need to mock here as constructor is not accessible
    GetSnapshotsResponse response = mock(GetSnapshotsResponse.class);
    when(response.getSnapshots()).thenReturn(snapshots);
    actionListener.onResponse(response);
    assertThat(future.get(), containsInAnyOrder("my_table", PartitionName.templateName(null, "my_partitioned_table") + "*"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) RestoreSnapshotAnalyzedStatement(io.crate.analyze.RestoreSnapshotAnalyzedStatement) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CompletableFuture(java.util.concurrent.CompletableFuture) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) List(java.util.List) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 25 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class SnapshotRestoreDDLDispatcherTest method testResolveTableIndexWithIgnoreUnavailable.

@Test
public void testResolveTableIndexWithIgnoreUnavailable() throws Exception {
    CompletableFuture<List<String>> f = SnapshotRestoreDDLDispatcher.resolveIndexNames(Collections.singletonList(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_table"), null)), true, null, "my_repo");
    assertThat(f.get(), containsInAnyOrder("my_table", PartitionName.templateName(null, "my_table") + "*"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) List(java.util.List) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

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