List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testCopyFromIntoPartitionedTable() throws Exception { execute("create table quotes (" + " id integer primary key, " + " quote string index using fulltext" + ") partitioned by (id)"); ensureYellow();/*from w w w .jav a 2 s . c o m*/ String uriPath = Joiner.on("/").join(copyFilePath, "test_copy_from.json"); execute("copy quotes from ?", new Object[] { uriPath }); assertEquals(3L, response.rowCount()); assertThat(response.duration(), greaterThanOrEqualTo(0L)); 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).aliases().get("quotes")); } execute("select * from quotes"); assertEquals(3L, response.rowCount()); assertThat(response.rows()[0].length, is(2)); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testInsertPartitionedTable() throws Exception { execute("create table parted (id integer, name string, date timestamp)" + "partitioned by (date)"); ensureYellow();//from w ww . j a v a 2s .co m String templateName = PartitionName.templateName(null, "parted"); GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName) .execute().actionGet(); assertThat(templatesResponse.getIndexTemplates().get(0).template(), is(templateName + "*")); assertThat(templatesResponse.getIndexTemplates().get(0).name(), is(templateName)); assertTrue(templatesResponse.getIndexTemplates().get(0).aliases().containsKey("parted")); execute("insert into parted (id, name, date) values (?, ?, ?)", new Object[] { 1, "Ford", 13959981214861L }); assertThat(response.rowCount(), is(1L)); ensureYellow(); refresh(); assertTrue(clusterService().state().metaData().aliases().containsKey("parted")); String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef(String.valueOf(13959981214861L)))).asIndexName(); MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().metaData(); assertNotNull(metaData.indices().get(partitionName).aliases().get("parted")); assertThat(client().prepareCount(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE) .setQuery(new MatchAllQueryBuilder()).execute().actionGet().getCount(), is(1L)); execute("select id, name, date from parted"); assertThat(response.rowCount(), is(1L)); assertThat((Integer) response.rows()[0][0], is(1)); assertThat((String) response.rows()[0][1], is("Ford")); assertThat((Long) response.rows()[0][2], is(13959981214861L)); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
private void validateInsertPartitionedTable() { String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef(String.valueOf(13959981214861L)))).asIndexName(); assertTrue(internalCluster().clusterService().state().metaData().hasIndex(partitionName)); assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .indices().get(partitionName).aliases().get("parted")); assertThat(client().prepareCount(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE) .setQuery(new MatchAllQueryBuilder()).execute().actionGet().getCount(), is(1L)); partitionName = new PartitionName("parted", Arrays.asList(new BytesRef(String.valueOf(0L)))).asIndexName(); assertTrue(internalCluster().clusterService().state().metaData().hasIndex(partitionName)); assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .indices().get(partitionName).aliases().get("parted")); assertThat(client().prepareCount(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE) .setQuery(new MatchAllQueryBuilder()).execute().actionGet().getCount(), is(1L)); List<BytesRef> nullList = new ArrayList<>(); nullList.add(null);//from w w w .j a v a 2s . co m partitionName = new PartitionName("parted", nullList).asIndexName(); assertTrue(internalCluster().clusterService().state().metaData().hasIndex(partitionName)); assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .indices().get(partitionName).aliases().get("parted")); assertThat(client().prepareCount(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE) .setQuery(new MatchAllQueryBuilder()).execute().actionGet().getCount(), is(1L)); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testInsertPartitionedTableOnlyPartitionedColumns() throws Exception { execute("create table parted (name string, date timestamp)" + "partitioned by (name, date)"); ensureYellow();//from w ww . ja v a 2 s . c o m 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).aliases().get("parted")); assertThat(client().prepareCount(partitionName).setTypes(Constants.DEFAULT_MAPPING_TYPE) .setQuery(new MatchAllQueryBuilder()).execute().actionGet().getCount(), 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")); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testInsertPartitionedTableSomePartitionedColumns() throws Exception { // insert only some partitioned column values execute("create table parted (id integer, name string, date timestamp)" + "partitioned by (name, date)"); ensureYellow();//w w w . jav a 2 s . com execute("insert into parted (id, name) values (?, ?)", new Object[] { 1, "Trillian" }); assertThat(response.rowCount(), is(1L)); ensureYellow(); refresh(); String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef("Trillian"), null)) .asIndexName(); assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .indices().get(partitionName).aliases().get("parted")); execute("select id, name, date from parted"); assertThat(response.rowCount(), is(1L)); assertThat((Integer) response.rows()[0][0], is(1)); assertThat((String) response.rows()[0][1], is("Trillian")); assertNull(response.rows()[0][2]); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testInsertPartitionedTableReversedPartitionedColumns() throws Exception { execute("create table parted (id integer, name string, date timestamp)" + "partitioned by (name, date)"); ensureYellow();/*from w ww .j a v a 2s. co m*/ Long dateValue = System.currentTimeMillis(); execute("insert into parted (id, date, name) values (?, ?, ?)", new Object[] { 1, dateValue, "Trillian" }); assertThat(response.rowCount(), is(1L)); ensureYellow(); refresh(); String partitionName = new PartitionName("parted", Arrays.asList(new BytesRef("Trillian"), new BytesRef(dateValue.toString()))).asIndexName(); assertNotNull(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .indices().get(partitionName).aliases().get("parted")); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testDeleteFromPartitionedTableUnknownPartition() 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 date = '2014-03-01'"); refresh();/*from w w w . j av a 2 s . c o m*/ // 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())); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@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();// w w w . ja v a 2 s . co m // 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())); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testDeleteFromPartitionedTableDeleteByQuery() throws Exception { execute("create table quotes (id integer, quote string, timestamp timestamp) " + "partitioned by(timestamp) with (number_of_replicas=0)"); ensureYellow();/*from w w w. j a va 2 s . c o m*/ execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L }); execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 2, "Time is an illusion. Lunchtime doubly so", 1395961200000L }); execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 3, "I'd far rather be happy than right any day", 1396303200000L }); execute("insert into quotes (id, quote, timestamp) values(?, ?, ?)", new Object[] { 4, "Now panic", 1395874800000L }); ensureYellow(); refresh(); SQLResponse response = execute("select partition_ident from information_schema.table_partitions " + "where table_name='quotes' and schema_name='doc'" + "order by partition_ident"); assertThat(response.rowCount(), is(3L)); assertThat((String) response.rows()[0][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1395874800000"))).ident())); assertThat((String) response.rows()[1][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1395961200000"))).ident())); assertThat((String) response.rows()[2][0], is(new PartitionName("parted", ImmutableList.of(new BytesRef("1396303200000"))).ident())); execute("delete from quotes where quote = 'Don''t panic'"); refresh(); execute("select * from quotes where quote = 'Don''t panic'"); assertThat(this.response.rowCount(), is(0L)); // Test that no partitions were deleted SQLResponse newResponse = execute("select partition_ident from information_schema.table_partitions " + "where table_name='quotes' and schema_name='doc'" + "order by partition_ident"); assertThat(newResponse.rows(), is(response.rows())); }
From source file:io.crate.integrationtests.PartitionedTableIntegrationTest.java
License:Apache License
@Test public void testAlterPartitionTable() throws Exception { execute("create table quotes (id integer, quote string, date timestamp) " + "partitioned by(date) clustered into 3 shards with (number_of_replicas='0-all')"); ensureYellow();/*from ww w. j a v a 2 s . c om*/ assertThat(response.rowCount(), is(1L)); String templateName = PartitionName.templateName(null, "quotes"); GetIndexTemplatesResponse templatesResponse = client().admin().indices().prepareGetTemplates(templateName) .execute().actionGet(); Settings templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(1)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("0-all")); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(3)); execute("alter table quotes set (number_of_replicas=0)"); ensureYellow(); templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0), is(0)); assertThat(templateSettings.getAsBoolean(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, true), is(false)); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(3)); execute("insert into quotes (id, quote, date) values (?, ?, ?), (?, ?, ?)", new Object[] { 1, "Don't panic", 1395874800000L, 2, "Now panic", 1395961200000L }); assertThat(response.rowCount(), is(2L)); ensureYellow(); refresh(); assertTrue(clusterService().state().metaData().aliases().containsKey("quotes")); execute("select number_of_replicas, number_of_shards from information_schema.tables where table_name = 'quotes'"); assertEquals("0", response.rows()[0][0]); assertEquals(3, response.rows()[0][1]); execute("alter table quotes set (number_of_replicas='1-all')"); ensureYellow(); execute("select number_of_replicas from information_schema.tables where table_name = 'quotes'"); assertEquals("1-all", response.rows()[0][0]); templatesResponse = client().admin().indices().prepareGetTemplates(templateName).execute().actionGet(); templateSettings = templatesResponse.getIndexTemplates().get(0).getSettings(); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1), is(0)); assertThat(templateSettings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 0), is(3)); assertThat(templateSettings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all")); List<String> partitions = ImmutableList.of( new PartitionName("quotes", Arrays.asList(new BytesRef("1395874800000"))).asIndexName(), new PartitionName("quotes", Arrays.asList(new BytesRef("1395961200000"))).asIndexName()); Thread.sleep(1000); GetSettingsResponse settingsResponse = client().admin().indices() .prepareGetSettings(partitions.get(0), partitions.get(1)).execute().get(); for (String index : partitions) { assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_NUMBER_OF_REPLICAS), is("1")); assertThat(settingsResponse.getSetting(index, IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS), is("1-all")); } }