use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.
the class TableAliasIntegrationTest method testPartitionedTableKeepsAliasAfterSchemaUpdate.
@Test
public void testPartitionedTableKeepsAliasAfterSchemaUpdate() throws Exception {
execute("create table t (name string, p string) partitioned by (p) " + "clustered into 2 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name, p) values ('Arthur', 'a')");
execute("insert into t (name, p) values ('Trillian', 'a')");
execute("alter table t add column age integer");
execute("insert into t (name, p) values ('Marvin', 'b')");
waitNoPendingTasksOnAll();
refresh();
execute("select count(*) from t");
assertThat(response.rowCount(), is(1L));
assertThat((Long) response.rows()[0][0], is(3L));
GetIndexTemplatesResponse indexTemplatesResponse = client().admin().indices().prepareGetTemplates(".partitioned.t.").execute().actionGet();
IndexTemplateMetaData indexTemplateMetaData = indexTemplatesResponse.getIndexTemplates().get(0);
AliasMetaData t = indexTemplateMetaData.aliases().get("t");
assertThat(t.alias(), is("t"));
execute("select partitioned_by from information_schema.tables where table_name = 't'");
assertThat((String) ((Object[]) response.rows()[0][0])[0], is("p"));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.
the class ColumnPolicyIntegrationTest method testStrictPartitionedTableUpdate.
@Test
public void testStrictPartitionedTableUpdate() 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("update numbers set num=?, perfect=? where num=6", new Object[] { 28, true });
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.
the class ColumnPolicyIntegrationTest method testDynamicPartitionedTable.
@Test
public void testDynamicPartitionedTable() throws Exception {
execute("create table numbers (" + " num int, " + " odd boolean," + " prime boolean" + ") partitioned by (odd) with (column_policy='dynamic', number_of_replicas=0)");
ensureYellow();
GetIndexTemplatesResponse templateResponse = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "numbers")).execute().actionGet();
assertThat(templateResponse.getIndexTemplates().size(), is(1));
IndexTemplateMetaData template = templateResponse.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("true"));
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", Collections.singletonList(new BytesRef("true"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is("true"));
execute("insert into numbers (num, odd, prime, perfect) values (?, ?, ?, ?)", new Object[] { 28, true, false, true });
ensureYellow();
execute("refresh table numbers");
waitForMappingUpdateOnAll("numbers", "perfect");
execute("select * from numbers order by num");
assertThat(response.rowCount(), is(2L));
assertThat(response.cols(), arrayContaining("num", "odd", "perfect", "prime"));
assertThat(TestingHelpers.printedTable(response.rows()), is("6| true| NULL| false\n" + "28| true| true| false\n"));
execute("update numbers set prime=true, changed='2014-10-23T10:20', author='troll' where num=28");
assertThat(response.rowCount(), is(1L));
waitForMappingUpdateOnAll("numbers", "changed");
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.
the class ColumnPolicyIntegrationTest method testAlterColumnPolicyOnPartitionedTableWithExistingPartitions.
@Test
public void testAlterColumnPolicyOnPartitionedTableWithExistingPartitions() throws Exception {
execute("create table dynamic_table (" + " id integer, " + " score double" + ") partitioned by (score) with (number_of_replicas=0, column_policy='strict')");
ensureYellow();
// create at least 2 partitions to test real multi partition logic (1 partition would behave similar to 1 normal table)
execute("insert into dynamic_table (id, score) values (1, 10)");
execute("insert into dynamic_table (id, score) values (1, 20)");
execute("refresh table dynamic_table");
ensureYellow();
execute("alter table dynamic_table set (column_policy = 'dynamic')");
waitNoPendingTasksOnAll();
// After changing the column_policy it's possible to add new columns to existing and new
// partitions
execute("insert into dynamic_table (id, score, comment) values (2, 10, 'this is a new column')");
execute("insert into dynamic_table (id, score, new_comment) values (2, 5, 'this is a new column on a new partition')");
execute("refresh table dynamic_table");
ensureYellow();
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "dynamic_table")).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(String.valueOf(ColumnPolicy.DYNAMIC.mappingValue())));
execute("insert into dynamic_table (id, score, new_col) values (?, ?, ?)", new Object[] { 6, 3, "hello" });
execute("refresh table dynamic_table");
ensureYellow();
MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Arrays.asList(new BytesRef("10.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(String.valueOf(ColumnPolicy.DYNAMIC.mappingValue())));
partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Arrays.asList(new BytesRef("5.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(String.valueOf(ColumnPolicy.DYNAMIC.mappingValue())));
partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Arrays.asList(new BytesRef("3.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(String.valueOf(ColumnPolicy.DYNAMIC.mappingValue())));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterNumberOfShards.
@Test
public void testAlterNumberOfShards() 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.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(3));
execute("alter table quotes set (number_of_shards=6)");
ensureGreen();
templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(6));
execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L });
assertThat(response.rowCount(), is(1L));
refresh();
assertTrue(clusterService().state().metaData().hasAlias("quotes"));
execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'");
assertEquals("0-all", response.rows()[0][0]);
assertEquals(6, response.rows()[0][1]);
execute("select number_of_shards from information_schema.table_partitions where table_name='quotes'");
assertThat(response.rowCount(), is(1L));
assertThat((Integer) response.rows()[0][0], is(6));
execute("alter table quotes set (number_of_shards=2)");
ensureYellow();
execute("insert into quotes (id, quote, date) values (?, ?, ?)", new Object[] { 2, "Now panic", 1395961200000L });
assertThat(response.rowCount(), is(1L));
ensureYellow();
refresh();
execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'");
assertEquals("0-all", response.rows()[0][0]);
assertEquals(2, response.rows()[0][1]);
execute("select number_of_shards from information_schema.table_partitions where table_name='quotes' order by number_of_shards ASC");
assertThat(response.rowCount(), is(2L));
assertThat((Integer) response.rows()[0][0], is(2));
assertThat((Integer) response.rows()[1][0], is(6));
templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet();
templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings();
assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(2));
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();
String index = partitions.get(0);
assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_SHARDS), is("6"));
index = partitions.get(1);
assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_SHARDS), is("2"));
}
Aggregations