use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.
the class SQLTransportIntegrationTest method getIndexMapping.
/**
* Get all mappings from an index as JSON String
*
* @param index the name of the index
* @return the index mapping as String
* @throws IOException
*/
protected String getIndexMapping(String index) throws IOException {
ClusterStateRequest request = Requests.clusterStateRequest().routingTable(false).nodes(false).metaData(true).indices(index);
ClusterStateResponse response = client().admin().cluster().state(request).actionGet();
MetaData metaData = response.getState().metaData();
XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
IndexMetaData indexMetaData = metaData.iterator().next();
for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) {
builder.field(cursor.value.type());
builder.map(cursor.value.sourceAsMap());
}
builder.endObject();
return builder.string();
}
use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterPartitionedTableKeepsMetadata.
@Test
public void testAlterPartitionedTableKeepsMetadata() throws Exception {
execute("create table dynamic_table (" + " id integer, " + " score double" + ") partitioned by (score) with (number_of_replicas=0, column_policy='dynamic')");
ensureGreen();
execute("insert into dynamic_table (id, score) values (1, 10)");
execute("refresh table dynamic_table");
ensureGreen();
MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Collections.singletonList(new BytesRef("10.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
Map<String, Object> metaMap = (Map) partitionMetaData.getSourceAsMap().get("_meta");
assertThat(String.valueOf(metaMap.get("partitioned_by")), Matchers.is("[[score, double]]"));
execute("alter table dynamic_table set (column_policy= 'dynamic')");
waitNoPendingTasksOnAll();
partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Collections.singletonList(new BytesRef("10.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
metaMap = (Map) partitionMetaData.getSourceAsMap().get("_meta");
assertThat(String.valueOf(metaMap.get("partitioned_by")), Matchers.is("[[score, double]]"));
}
use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.
the class ColumnPolicyIntegrationTest method testResetColumnPolicyPartitioned.
@Test
public void testResetColumnPolicyPartitioned() throws Exception {
execute("create table dynamic_table (" + " id integer, " + " score double" + ") partitioned by (score) with (number_of_replicas=0)");
ensureYellow();
execute("insert into dynamic_table (id, score) values (1, 10)");
execute("refresh table dynamic_table");
execute("alter table dynamic_table set (column_policy = 'strict')");
waitNoPendingTasksOnAll();
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(ColumnPolicy.STRICT.value()));
execute("alter table dynamic_table reset (column_policy)");
waitNoPendingTasksOnAll();
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())));
}
use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.
the class ColumnPolicyIntegrationTest method testResetColumnPolicy.
@Test
public void testResetColumnPolicy() throws Exception {
execute("create table dynamic_table (" + " id integer, " + " score double" + ") with (number_of_replicas=0)");
ensureYellow();
execute("alter table dynamic_table set (column_policy = 'strict')");
waitNoPendingTasksOnAll();
MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get("dynamic_table").getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(ColumnPolicy.STRICT.value()));
execute("alter table dynamic_table reset (column_policy)");
waitNoPendingTasksOnAll();
partitionMetaData = clusterService().state().metaData().indices().get("dynamic_table").getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(String.valueOf(ColumnPolicy.DYNAMIC.mappingValue())));
}
use of org.elasticsearch.cluster.metadata.MappingMetadata 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 });
}
Aggregations