use of io.crate.metadata.PartitionName in project crate by crate.
the class TransportExecutorDDLTest method testDeletePartitionTask.
@Test
public void testDeletePartitionTask() throws Exception {
execute("create table t (id integer primary key, name string) partitioned by (id)");
ensureYellow();
execute("insert into t (id, name) values (1, 'Ford')");
assertThat(response.rowCount(), is(1L));
ensureYellow();
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(1L));
String partitionName = new PartitionName("t", ImmutableList.of(new BytesRef("1"))).asIndexName();
ESDeletePartition plan = new ESDeletePartition(UUID.randomUUID(), partitionName);
TestingBatchConsumer consumer = new TestingBatchConsumer();
executor.execute(plan, consumer, Row.EMPTY);
Bucket objects = consumer.getBucket();
assertThat(objects, contains(isRow(-1L)));
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(0L));
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class TransportExecutorDDLTest method testDeletePartitionTaskClosed.
/**
* this case should not happen as closed indices aren't listed as TableInfo
* but if it does maybe because of stale cluster state - validate behaviour here
* <p>
* cannot prevent this task from deleting closed indices.
*/
@Test
public void testDeletePartitionTaskClosed() throws Exception {
execute("create table t (id integer primary key, name string) partitioned by (id)");
ensureYellow();
execute("insert into t (id, name) values (1, 'Ford')");
assertThat(response.rowCount(), is(1L));
ensureYellow();
String partitionName = new PartitionName("t", ImmutableList.of(new BytesRef("1"))).asIndexName();
assertTrue(client().admin().indices().prepareClose(partitionName).execute().actionGet().isAcknowledged());
ESDeletePartition plan = new ESDeletePartition(UUID.randomUUID(), partitionName);
TestingBatchConsumer consumer = new TestingBatchConsumer();
executor.execute(plan, consumer, Row.EMPTY);
Bucket bucket = consumer.getBucket();
assertThat(bucket, contains(isRow(-1L)));
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(0L));
}
use of io.crate.metadata.PartitionName 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 io.crate.metadata.PartitionName 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 });
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class TransportExecutorDDLTest method testCreateTableWithOrphanedPartitions.
@Test
public void testCreateTableWithOrphanedPartitions() throws Exception {
String partitionName = new PartitionName("test", Collections.singletonList(new BytesRef("foo"))).asIndexName();
client().admin().indices().prepareCreate(partitionName).addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS).execute().actionGet();
ensureGreen();
execute("create table test (id integer, name string, names string) partitioned by (id)");
ensureYellow();
execute("select * from information_schema.tables where table_name = 'test'");
assertThat(response.rowCount(), is(1L));
execute("select count(*) from information_schema.columns where table_name = 'test'");
assertThat((Long) response.rows()[0][0], is(3L));
// check that orphaned partition has been deleted
assertThat(client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false));
}
Aggregations