Search in sources :

Example 51 with PartitionName

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

the class DDLIntegrationTest method testAlterShardsOfPartitionedTable.

@Test
public void testAlterShardsOfPartitionedTable() 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();
    execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L });
    execute("alter table quotes set (number_of_shards=5)");
    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_SHARDS, 0), is(5));
    execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[] { 3, "Time is a illusion. Lunchtime doubles so", 1495961200000L });
    String partition = new PartitionName("quotes", Arrays.asList(new BytesRef("1495961200000"))).asIndexName();
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings(partition).execute().get();
    assertThat(settingsResponse.getSetting(partition, IndexMetaData.SETTING_NUMBER_OF_SHARDS), is("5"));
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 52 with PartitionName

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

the class PartitionedTableIntegrationTest method testAlterPartitionedTablePartition.

@Test
public void testAlterPartitionedTablePartition() throws Exception {
    execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas=0)");
    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 partition (date=1395874800000) set (number_of_replicas=1)");
    ensureYellow();
    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();
    assertThat(settingsResponse.getSetting(partitions.get(0), IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("1"));
    assertThat(settingsResponse.getSetting(partitions.get(1), IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("0"));
    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(0));
    assertThat(templateSettings.get(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) BytesRef(org.apache.lucene.util.BytesRef) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 53 with PartitionName

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

the class PartitionedTableIntegrationTest method testInsertPartitionedTableSomePartitionedColumns.

@Test
public void testInsertPartitionedTableSomePartitionedColumns() throws Exception {
    // insert only some partitioned column values
    execute("create table parted (id integer, name string, date timestamp)" + "partitioned by (name, date)");
    ensureYellow();
    execute("insert into parted (id, name) values (?, ?)", new Object[] { 1, "Trillian" });
    assertThat(response.rowCount(), is(1L));
    ensureYellow();
    refresh();
    String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef("Trillian"), null)).asIndexName();
    assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName).getAliases().get("parted"));
    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("Trillian"));
    assertNull(response.rows()[0][2]);
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 54 with PartitionName

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

the class PartitionedTableIntegrationTest method testDeleteFromPartitionedTableDeleteByQuery.

@Test
public void testDeleteFromPartitionedTableDeleteByQuery() throws Exception {
    execute("create table quotes (id integer, quote string, timestamp timestamp) " + "partitioned by(timestamp) with (number_of_replicas=0)");
    ensureYellow();
    execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L });
    execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 2, "Time is an illusion. Lunchtime doubly so", 1395961200000L });
    execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 3, "I'd far rather be happy than right any day", 1396303200000L });
    execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 4, "Now panic", 1395874800000L });
    ensureYellow();
    refresh();
    SQLResponse response = execute("select partition_ident from information_schema.table_partitions " + "where table_name='quotes' and schema_name='doc'" + "order by partition_ident");
    assertThat(response.rowCount(), is(3L));
    assertThat((String) response.rows()[0][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1395874800000"))).ident()));
    assertThat((String) response.rows()[1][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1395961200000"))).ident()));
    assertThat((String) response.rows()[2][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1396303200000"))).ident()));
    execute("delete from quotes where quote = 'Don''t panic'");
    refresh();
    execute("select * from quotes where quote = 'Don''t panic'");
    assertThat(this.response.rowCount(), is(0L));
    // Test that no partitions were deleted
    SQLResponse newResponse = execute("select partition_ident from information_schema.table_partitions " + "where table_name='quotes' and schema_name='doc'" + "order by partition_ident");
    assertThat(newResponse.rows(), is(response.rows()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) SQLResponse(io.crate.testing.SQLResponse) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 55 with PartitionName

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

the class PartitionedTableIntegrationTest method testDeleteFromPartitionedTableUnknownPartition.

@Test
public void testDeleteFromPartitionedTableUnknownPartition() throws Exception {
    this.setup.partitionTableSetup();
    SQLResponse response = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
    assertThat(response.rowCount(), is(2L));
    assertThat((String) response.rows()[0][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1388534400000"))).ident()));
    assertThat((String) response.rows()[1][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1391212800000"))).ident()));
    execute("delete from parted where date = '2014-03-01'");
    refresh();
    // Test that no partitions were deleted
    SQLResponse newResponse = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
    assertThat(newResponse.rows(), is(response.rows()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) SQLResponse(io.crate.testing.SQLResponse) BytesRef(org.apache.lucene.util.BytesRef) 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