use of io.crate.metadata.PartitionName in project crate by crate.
the class PartitionedTableIntegrationTest method testDeleteFromPartitionedTableWrongPartitionedColumn.
@Test
public void testDeleteFromPartitionedTableWrongPartitionedColumn() throws Exception {
this.setup.partitionTableSetup();
SQLResponse response = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
assertThat(response.rowCount(), is(2L));
assertThat((String) response.rows()[0][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1388534400000"))).ident()));
assertThat((String) response.rows()[1][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1391212800000"))).ident()));
execute("delete from parted where o['dat'] = '2014-03-01'");
refresh();
// Test that no partitions were deleted
SQLResponse newResponse = execute("select partition_ident from information_schema.table_partitions " + "where table_name='parted' and schema_name='doc'" + "order by partition_ident");
assertThat(newResponse.rows(), is(response.rows()));
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class PartitionedTableIntegrationTest method testInsertPartitionedTableOnlyPartitionedColumns.
@Test
public void testInsertPartitionedTableOnlyPartitionedColumns() throws Exception {
execute("create table parted (name string, date timestamp)" + "partitioned by (name, date)");
ensureYellow();
execute("insert into parted (name, date) values (?, ?)", new Object[] { "Ford", 13959981214861L });
assertThat(response.rowCount(), is(1L));
ensureYellow();
refresh();
String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef("Ford"), new BytesRef(String.valueOf(13959981214861L)))).asIndexName();
assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName).getAliases().get("parted"));
assertThat(client().prepareSearch(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE).setSize(0).setQuery(new MatchAllQueryBuilder()).execute().actionGet().getHits().totalHits(), is(1L));
execute("select * from parted");
assertThat(response.rowCount(), is(1L));
assertThat(response.cols(), arrayContaining("date", "name"));
assertThat((Long) response.rows()[0][0], is(13959981214861L));
assertThat((String) response.rows()[0][1], is("Ford"));
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class PartitionedTableIntegrationTest method testCopyFromIntoPartitionedTable.
/**
* Test requires patch in ES 2.1 (https://github.com/crate/elasticsearch/commit/66564f88d21ad3d3be908dbe50974c448f7929d7)
* or ES 2.x (https://github.com/elastic/elasticsearch/pull/16767).
* Otherwise the rowCount returned from the copy from statement is ambiguous.
*/
@Test
// no copy rowcount
@UseJdbc(0)
public void testCopyFromIntoPartitionedTable() throws Exception {
execute("create table quotes (" + " id integer primary key, " + " quote string index using fulltext" + ") partitioned by (id)");
ensureYellow();
execute("copy quotes from ?", new Object[] { copyFilePath + "test_copy_from.json" });
assertEquals(3L, response.rowCount());
refresh();
ensureYellow();
for (String id : ImmutableList.of("1", "2", "3")) {
String partitionName = new PartitionName("quotes", ImmutableList.of(new BytesRef(id))).asIndexName();
assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName));
assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().indices().get(partitionName).getAliases().get("quotes"));
}
execute("select * from quotes");
assertEquals(3L, response.rowCount());
assertThat(response.rows()[0].length, is(2));
}
Aggregations