refresh();
execute("alter table t partition (date='2014-01-01') add name string");
GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0);
String mappingSource = metaData.mappings().get(Constants.DEFAULT_MAPPING_TYPE).toString();
Map mapping = (Map) XContentFactory.xContent(mappingSource)
.createParser(mappingSource)
.mapAndClose()
.get(Constants.DEFAULT_MAPPING_TYPE);
assertNull(((Map) mapping.get("properties")).get("name"));
execute("insert into t (id, date, name) values (2, '2014-01-01', 100)"); // insert integer as name
refresh();
execute("select name from t where id = 2 and date = '2014-01-01'");
assertThat((String) response.rows()[0][0], is("100")); // is returned as string
execute("alter table t add name2 string"); // now template is also updated
execute("select * from t");
assertThat(Arrays.asList(response.cols()), Matchers.contains("date", "id", "name", "name2"));
templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
metaData = templatesResponse.getIndexTemplates().get(0);
mappingSource = metaData.mappings().get(Constants.DEFAULT_MAPPING_TYPE).toString();
mapping = (Map) XContentFactory.xContent(mappingSource)
.createParser(mappingSource)
.mapAndClose().get(Constants.DEFAULT_MAPPING_TYPE);
assertNotNull(((Map) mapping.get("properties")).get("name2"));
}