List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.executor.BytesRefUtilsTest.java
License:Apache License
@Test public void testEnsureStringTypesAreStringsSetString() throws Exception { DataType[] dataTypes = new DataType[] { new SetType(DataTypes.STRING) }; Object[][] rows = new Object[1][1]; Set<BytesRef> refs = new HashSet<>(Arrays.asList(new BytesRef("foo"), new BytesRef("bar"))); rows[0][0] = refs;//from w ww . j av a2 s .c o m BytesRefUtils.ensureStringTypesAreStrings(dataTypes, rows); assertThat((String[]) rows[0][0], Matchers.arrayContainingInAnyOrder("foo", "bar")); }
From source file:io.crate.executor.BytesRefUtilsTest.java
License:Apache License
@Test public void testEnsureStringTypesAreStringsArrayString() throws Exception { DataType[] dataTypes = new DataType[] { new ArrayType(DataTypes.STRING) }; Object[][] rows = new Object[1][1]; BytesRef[] refs = new BytesRef[] { new BytesRef("foo"), new BytesRef("bar") }; rows[0][0] = refs;/*from w w w. j a v a2 s .c o m*/ BytesRefUtils.ensureStringTypesAreStrings(dataTypes, rows); assertThat(commaJoiner.join((String[]) rows[0][0]), is("foo, bar")); }
From source file:io.crate.executor.RowsResponseBuilderTest.java
License:Apache License
@Test public void testBuildResponseSetString() throws Exception { boolean convertBytesRef = true; RowsResponseBuilder rrb = new RowsResponseBuilder(convertBytesRef); String[] outputNames = new String[] { "col" }; DataType[] dataTypes = new DataType[] { DataType.STRING_SET }; Object[][] rows = new Object[1][1]; Set<BytesRef> refs = new HashSet<>(Arrays.asList(new BytesRef("foo"), new BytesRef("bar"))); rows[0][0] = refs;/* w ww . j av a 2s. c om*/ SQLResponse response = rrb.buildResponse(dataTypes, outputNames, rows, 0L); assertThat(commaJoiner.join((Collection<?>) response.rows()[0][0]), is("foo, bar")); }
From source file:io.crate.executor.RowsResponseBuilderTest.java
License:Apache License
@Test public void testBuildResponseArrayString() throws Exception { boolean convertBytesRef = true; RowsResponseBuilder rrb = new RowsResponseBuilder(convertBytesRef); String[] outputNames = new String[] { "col" }; DataType[] dataTypes = new DataType[] { DataType.STRING_ARRAY }; Object[][] rows = new Object[1][1]; BytesRef[] refs = new BytesRef[] { new BytesRef("foo"), new BytesRef("bar") }; rows[0][0] = refs;/* ww w . ja va2s. c o m*/ SQLResponse response = rrb.buildResponse(dataTypes, outputNames, rows, 0L); assertThat(commaJoiner.join((String[]) response.rows()[0][0]), is("foo, bar")); }
From source file:io.crate.executor.transport.DependencyCarrierDDLTest.java
License:Apache License
@Test public void testCreateTableWithOrphanedPartitions() throws Exception { String partitionName = new PartitionName(sqlExecutor.getDefaultSchema(), "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();/*from ww w. ja va2 s .c o m*/ 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)); }
From source file:io.crate.executor.transport.DependencyCarrierDDLTest.java
License:Apache License
@Test @UseJdbc(0) // create table has no rowcount public void testCreateTableWithOrphanedAlias() throws Exception { String partitionName = new PartitionName(sqlExecutor.getDefaultSchema(), "test", Collections.singletonList(new BytesRef("foo"))).asIndexName(); client().admin().indices().prepareCreate(partitionName) .addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS) .addAlias(new Alias("test")).execute().actionGet(); ensureGreen();/*from w w w . ja va2s . co m*/ execute("create table test (id integer, name string, names string) " + "clustered into 2 shards " + "partitioned by (id) with (number_of_replicas=0)"); assertThat(response.rowCount(), is(1L)); ensureGreen(); 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 alias has been deleted assertThat(client().admin().cluster().prepareState().execute().actionGet().getState().metaData() .hasAlias("test"), is(false)); // check that orphaned partition has been deleted assertThat( client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false)); }
From source file:io.crate.executor.transport.DependencyCarrierDDLTest.java
License:Apache License
/** * 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>// w w w . ja v a 2s . c om * 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 schema = sqlExecutor.getDefaultSchema(); String partitionName = new PartitionName(schema, "t", ImmutableList.of(new BytesRef("1"))).asIndexName(); PlanForNode plan = plan("delete from t where id = ?"); assertTrue(client().admin().indices().prepareClose(partitionName).execute().actionGet().isAcknowledged()); Bucket bucket = executePlan(plan.plan, new Row1(1)); assertThat(bucket, contains(isRow(-1L))); execute("select * from information_schema.table_partitions where table_name = 't'"); assertThat(response.rowCount(), is(0L)); }
From source file:io.crate.executor.transport.distributed.DistributedResultRequestTest.java
License:Apache License
@Test public void testStreaming() throws Exception { DistributedRequestContextManager cm = mock(DistributedRequestContextManager.class); Streamer<?>[] streamers = new Streamer[] { DataTypes.STRING.streamer() }; when(cm.getStreamer((UUID) anyObject())).thenReturn(Optional.of(streamers)); Object[][] rows = new Object[][] { { new BytesRef("ab") }, { null }, { new BytesRef("cd") } }; UUID uuid = UUID.randomUUID(); DistributedResultRequest r1 = new DistributedResultRequest(uuid, streamers); r1.rows(rows);/*from w ww. j av a2 s . co m*/ BytesStreamOutput out = new BytesStreamOutput(); r1.writeTo(out); BytesStreamInput in = new BytesStreamInput(out.bytes()); DistributedResultRequest r2 = new DistributedResultRequest(cm); r2.readFrom(in); assertEquals(r1.rows().length, r2.rows().length); assertThat(r1.rows(), is(r2.rows())); }
From source file:io.crate.executor.transport.distributed.DistributingDownstreamTest.java
License:Apache License
@Test public void testPauseResume() throws Exception { final SettableFuture<Boolean> allRowsReceived = SettableFuture.create(); final List<Row> receivedRows = Collections.synchronizedList(new ArrayList<Row>()); TransportDistributedResultAction transportDistributedResultAction = new TransportDistributedResultAction( mock(Transports.class), mock(JobContextService.class), mock(ThreadPool.class), mock(TransportService.class)) { @Override//from w ww . j a v a 2 s .co m public void pushResult(String node, final DistributedResultRequest request, final ActionListener<DistributedResultResponse> listener) { executorService.submit(new Runnable() { @Override public void run() { try { Thread.sleep(randomIntBetween(10, 50)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } final Bucket rows = request.rows(); for (Row row : rows) { receivedRows.add(row); } if (request.isLast()) { allRowsReceived.set(true); } listener.onResponse(new DistributedResultResponse(true)); } }); } }; Streamer[] streamers = new Streamer[] { DataTypes.STRING.streamer() }; int pageSize = 10; final DistributingDownstream distributingDownstream = new DistributingDownstream(UUID.randomUUID(), new BroadcastingBucketBuilder(streamers, 1), 1, (byte) 0, 0, ImmutableList.of("n1"), transportDistributedResultAction, mock(KeepAliveTimers.class, Answers.RETURNS_MOCKS.get()), streamers, pageSize); final List<Row> rows = new ArrayList<>(); for (int i = 65; i < 91; i++) { rows.add(new Row1(new BytesRef(Character.toString((char) i)))); rows.add(new Row1(new BytesRef(Character.toString((char) (i + 32))))); } final RowSender task1 = new RowSender(rows, distributingDownstream, executorService); final ListenableFuture<?> f1 = executorService.submit(task1); Futures.allAsList(f1).get(2, TimeUnit.SECONDS); allRowsReceived.get(2, TimeUnit.SECONDS); assertThat(receivedRows.size(), is(52)); assertThat(task1.numPauses(), Matchers.greaterThan(0)); assertThat(task1.numResumes(), Matchers.greaterThan(0)); }
From source file:io.crate.executor.transport.merge.DistributedResultRequestTest.java
License:Apache License
@Test public void testStreaming() throws Exception { Streamer<?>[] streamers = new Streamer[] { DataTypes.STRING.streamer() }; Object[][] rows = new Object[][] { { new BytesRef("ab") }, { null }, { new BytesRef("cd") } }; UUID uuid = UUID.randomUUID(); DistributedResultRequest r1 = new DistributedResultRequest(uuid, 1, (byte) 3, 1, streamers, new ArrayBucket(rows), false); BytesStreamOutput out = new BytesStreamOutput(); r1.writeTo(out);/*from w ww .ja v a 2 s . co m*/ BytesStreamInput in = new BytesStreamInput(out.bytes()); DistributedResultRequest r2 = new DistributedResultRequest(); r2.readFrom(in); r2.streamers(streamers); assertTrue(r2.rowsCanBeRead()); assertEquals(r1.rows().size(), r2.rows().size()); assertThat(r1.isLast(), is(r2.isLast())); assertThat(r1.executionPhaseInputId(), is(r2.executionPhaseInputId())); assertThat(r2.rows(), contains(isRow("ab"), isNullRow(), isRow("cd"))); }