use of org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType 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(sqlExecutor.getCurrentSchema(), "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, XContentType.JSON);
@SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
assertThat(decodeMappingValue(mapping.get("dynamic")), is(ColumnPolicy.DYNAMIC));
execute("insert into dynamic_table (id, score, new_col) values (?, ?, ?)", new Object[] { 6, 3, "hello" });
execute("refresh table dynamic_table");
ensureYellow();
Map<String, Object> sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "dynamic_table"), Arrays.asList("10.0")).asIndexName());
assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC));
sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "dynamic_table"), Arrays.asList("5.0")).asIndexName());
assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC));
sourceMap = getSourceMap(new PartitionName(new RelationName("doc", "dynamic_table"), Arrays.asList("3.0")).asIndexName());
assertThat(decodeMappingValue(sourceMap.get("dynamic")), is(ColumnPolicy.DYNAMIC));
}
Aggregations