Search in sources :

Example 26 with PartitionName

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

the class WhereClauseAnalyzerTest method testGenColRoundingFunctionNoSwappingOperatorOptimization.

@Test
public void testGenColRoundingFunctionNoSwappingOperatorOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts >= '2015-01-02T12:00:00'");
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420156800000"), new BytesRef("-2"))).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with PartitionName

use of io.crate.metadata.PartitionName 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 28 with PartitionName

use of io.crate.metadata.PartitionName 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 29 with PartitionName

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

the class FetchProjectorContext method partitionValues.

private Object[] partitionValues(String index, List<Reference> partitionByColumns) {
    if (partitionByColumns.isEmpty()) {
        return null;
    }
    PartitionName pn = PartitionName.fromIndexOrTemplate(index);
    List<BytesRef> partitionRowValues = pn.values();
    Object[] partitionValues = new Object[partitionRowValues.size()];
    for (int i = 0; i < partitionRowValues.size(); i++) {
        partitionValues[i] = partitionByColumns.get(i).valueType().value(partitionRowValues.get(i));
    }
    return partitionValues;
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef)

Example 30 with PartitionName

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

the class TransportExecutorDDLTest method testCreateTableWithOrphanedAlias.

@Test
public void testCreateTableWithOrphanedAlias() throws Exception {
    String partitionName = new PartitionName("test", Collections.singletonList(new BytesRef("foo"))).asIndexName();
    client().admin().indices().prepareCreate(partitionName).addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS).addAlias(new Alias("test")).execute().actionGet();
    ensureGreen();
    execute("create table test (id integer, name string, names string) " + "clustered into 2 shards " + "partitioned by (id) with (number_of_replicas=0)");
    assertThat(response.rowCount(), is(1L));
    ensureGreen();
    execute("select * from information_schema.tables where table_name = 'test'");
    assertThat(response.rowCount(), is(1L));
    execute("select count(*) from information_schema.columns where table_name = 'test'");
    assertThat((Long) response.rows()[0][0], is(3L));
    // check that orphaned alias has been deleted
    assertThat(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().hasAlias("test"), is(false));
    // check that orphaned partition has been deleted
    assertThat(client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Alias(org.elasticsearch.action.admin.indices.alias.Alias) BytesRef(org.apache.lucene.util.BytesRef) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

PartitionName (io.crate.metadata.PartitionName)58 BytesRef (org.apache.lucene.util.BytesRef)50 Test (org.junit.Test)44 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)10 WhereClause (io.crate.analyze.WhereClause)8 TableIdent (io.crate.metadata.TableIdent)8 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)7 Settings (org.elasticsearch.common.settings.Settings)7 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)5 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)5 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)4 SQLResponse (io.crate.testing.SQLResponse)4 Map (java.util.Map)4 Table (io.crate.sql.tree.Table)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 MetaData (org.elasticsearch.cluster.metadata.MetaData)3