Search in sources :

Example 1 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class PartitionedTableIntegrationTest method testInsertPartitionedTable.

@Test
public void testInsertPartitionedTable() throws Exception {
    execute("create table parted (id integer, name string, date timestamp)" + "partitioned by (date)");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "parted");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    assertThat(templatesResponse.getIndexTemplates().get(0).template(), is(templateName + "*"));
    assertThat(templatesResponse.getIndexTemplates().get(0).name(), is(templateName));
    assertTrue(templatesResponse.getIndexTemplates().get(0).getAliases().get("parted") != null);
    execute("insert into parted (id, name, date) values (?, ?, ?)", new Object[] { 1, "Ford", 13959981214861L });
    assertThat(response.rowCount(), is(1L));
    ensureYellow();
    refresh();
    assertTrue(clusterService().state().metaData().hasAlias("parted"));
    String partitionName = new PartitionName("parted", Collections.singletonList(new BytesRef(String.valueOf(13959981214861L)))).asIndexName();
    MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData();
    assertNotNull(metaData.indices().get(partitionName).getAliases().get("parted"));
    assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
    execute("select id, name, date from parted");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(1));
    assertThat((String) response.rows()[0][1], is("Ford"));
    assertThat((Long) response.rows()[0][2], is(13959981214861L));
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) MetaData(org.elasticsearch.cluster.metadata.MetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) DocIndexMetaData(io.crate.metadata.doc.DocIndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) BytesRef(org.apache.lucene.util.BytesRef) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) Test(org.junit.Test)

Example 2 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterNumberOfReplicas.

@Test
public void testAlterNumberOfReplicas() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='0-all')");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-all"));
    execute("alter table quotes set (number_of_replicas=0)");
    ensureYellow();
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0));
    assertThat(templateSettings.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false));
    execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
    assertThat(response.rowCount(), is(2L));
    ensureYellow();
    refresh();
    assertTrue(clusterService().state().metaData().hasAlias("quotes"));
    List<String> partitions = ImmutableList.of(new PartitionName("quotes", Collections.singletonList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Collections.singletonList(new BytesRef("1395961200000"))).asIndexName());
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        Settings partitionSetting = settingsResponse.getIndexToSettings().get(index);
        assertThat(partitionSetting.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0));
        assertThat(partitionSetting.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false));
    }
    execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'");
    assertEquals("0", response.rows()[0][0]);
    assertEquals(3, response.rows()[0][1]);
    execute("alter table quotes set (number_of_replicas='1-all')");
    ensureYellow();
    execute("select number_of_replicas from information_schema.tables where table_name = 'quotes'");
    assertEquals("1-all", response.rows()[0][0]);
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    }
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 3 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterTableResetEmptyPartitionedTable.

@Test
public void testAlterTableResetEmptyPartitionedTable() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1-all')");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all"));
    execute("alter table quotes reset (number_of_replicas)");
    ensureYellow();
    templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 4 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class PartitionedTableIntegrationTest method testAlterTableResetPartitionedTable.

@Test
public void testAlterTableResetPartitionedTable() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='1-all')");
    ensureYellow();
    execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
    assertThat(response.rowCount(), is(2L));
    ensureYellow();
    refresh();
    execute("alter table quotes reset (number_of_replicas)");
    ensureYellow();
    String templateName = PartitionName.templateName(null, "quotes");
    GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
    Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
    assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1));
    assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
    List<String> partitions = ImmutableList.of(new PartitionName("quotes", Collections.singletonList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Collections.singletonList(new BytesRef("1395961200000"))).asIndexName());
    Thread.sleep(1000);
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get();
    for (String index : partitions) {
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("1"));
        assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("false"));
    }
}
Also used : PartitionName(io.crate.metadata.PartitionName) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 5 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class ColumnPolicyIntegrationTest method testStrictPartitionedTableInsert.

@Test
public void testStrictPartitionedTableInsert() throws Exception {
    execute("create table numbers (" + "  num int, " + "  odd boolean," + "  prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
    ensureYellow();
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "numbers")).execute().actionGet();
    assertThat(response.getIndexTemplates().size(), is(1));
    IndexTemplateMetaData template = response.getIndexTemplates().get(0);
    CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(mappingStr, is(notNullValue()));
    Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
    @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(String.valueOf(mapping.get("dynamic")), is(ColumnPolicy.STRICT.value()));
    execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
    execute("refresh table numbers");
    MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("numbers", Arrays.asList(new BytesRef("true"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(ColumnPolicy.STRICT.value()));
    expectedException.expect(SQLActionException.class);
    expectedException.expectMessage("Column perfect unknown");
    execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[] { 28, true, false, true });
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) PartitionName(io.crate.metadata.PartitionName) XContentType(org.elasticsearch.common.xcontent.XContentType) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) HashMap(java.util.HashMap) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Aggregations

GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)35 Test (org.junit.Test)18 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)11 PartitionName (io.crate.metadata.PartitionName)10 BytesRef (org.apache.lucene.util.BytesRef)10 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)7 Settings (org.elasticsearch.common.settings.Settings)7 Map (java.util.Map)5 GetIndexTemplatesRequest (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)5 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)5 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)5 HashMap (java.util.HashMap)4 Alias (org.elasticsearch.action.admin.indices.alias.Alias)4 XContentType (org.elasticsearch.common.xcontent.XContentType)4 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)3 MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)3 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)2 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)2 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2