List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.execution.engine.aggregation.impl.MinimumAggregationTest.java
License:Apache License
@Test public void testString() throws Exception { Object[][] result = executeAggregation(DataTypes.STRING, new Object[][] { { new BytesRef("Youri") }, { new BytesRef("Ruben") } }); assertEquals(new BytesRef("Ruben"), result[0][0]); }
From source file:io.crate.execution.engine.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
private void addDocToLucene(IndexWriter w, Long value) throws IOException { Document doc = new Document(); if (value != null) { fieldType.createFields("value", value, true, true, false).forEach(doc::add); } else {// w w w . ja v a 2 s. c o m // Create a placeholder field doc.add(new SortedDocValuesField("null_value", new BytesRef("null"))); } w.addDocument(doc); }
From source file:io.crate.execution.engine.collect.collectors.NodeStatsIteratorTest.java
License:Apache License
@Test public void testNodeStatsIteratorContrat() throws Exception { List<Symbol> toCollect = new ArrayList<>(); toCollect.add(idRef);/*from w ww . jav a 2 s.co m*/ when(collectPhase.toCollect()).thenReturn(toCollect); when(collectPhase.whereClause()).thenReturn(WhereClause.MATCH_ALL); when(collectPhase.orderBy()).thenReturn( new OrderBy(Collections.singletonList(idRef), new boolean[] { false }, new Boolean[] { true })); List<Object[]> expectedResult = Arrays.asList(new Object[] { new BytesRef("nodeOne") }, new Object[] { new BytesRef("nodeTwo") }); BatchIteratorTester tester = new BatchIteratorTester(() -> NodeStatsIterator .newInstance(transportNodeStatsAction, collectPhase, nodes, new InputFactory(getFunctions()))); tester.verifyResultAndEdgeCaseBehaviour(expectedResult); }
From source file:io.crate.execution.engine.collect.files.FileReadingIteratorTest.java
License:Apache License
@Test public void testIteratorContract() throws Exception { String fileUri = tempFilePath.toUri().toString(); Supplier<BatchIterator<Row>> batchIteratorSupplier = () -> createBatchIterator( Collections.singletonList(fileUri), null); byte[] firstLine = "{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}" .getBytes(StandardCharsets.UTF_8); byte[] secondLine = "{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}" .getBytes(StandardCharsets.UTF_8); List<Object[]> expectedResult = Arrays.asList(new Object[] { new BytesRef(firstLine) }, new Object[] { new BytesRef(secondLine) }); BatchIteratorTester tester = new BatchIteratorTester(batchIteratorSupplier); tester.verifyResultAndEdgeCaseBehaviour(expectedResult); }
From source file:io.crate.execution.engine.distribution.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);/* www. ja v a 2s . c o m*/ StreamInput in = out.bytes().streamInput(); 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"))); }
From source file:io.crate.execution.engine.indexing.IndexWriterProjectorTest.java
License:Apache License
@Test public void testIndexWriter() throws Throwable { execute("create table bulk_import (id int primary key, name string) with (number_of_replicas=0)"); ensureGreen();//from w w w . j ava 2 s .c om InputCollectExpression sourceInput = new InputCollectExpression(1); List<CollectExpression<Row, ?>> collectExpressions = Collections .<CollectExpression<Row, ?>>singletonList(sourceInput); TableIdent bulkImportIdent = new TableIdent(sqlExecutor.getDefaultSchema(), "bulk_import"); Settings tableSettings = TableSettingsResolver.get(clusterService().state().getMetaData(), bulkImportIdent, false); ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class); IndexWriterProjector writerProjector = new IndexWriterProjector(clusterService(), new NodeJobsCounter(), threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), internalCluster().getInstance(Functions.class), Settings.EMPTY, tableSettings, internalCluster().getInstance(TransportCreatePartitionsAction.class), internalCluster().getInstance(TransportShardUpsertAction.class)::execute, IndexNameResolver.forTable(bulkImportIdent), new Reference(new ReferenceIdent(bulkImportIdent, DocSysColumns.RAW), RowGranularity.DOC, DataTypes.STRING), Arrays.asList(ID_IDENT), Arrays.<Symbol>asList(new InputColumn(0)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID()); BatchIterator rowsIterator = InMemoryBatchIterator.of(IntStream.range(0, 100).mapToObj( i -> new RowN(new Object[] { i, new BytesRef("{\"id\": " + i + ", \"name\": \"Arthur\"}") })) .collect(Collectors.toList()), SENTINEL); TestingRowConsumer consumer = new TestingRowConsumer(); consumer.accept(writerProjector.apply(rowsIterator), null); Bucket objects = consumer.getBucket(); assertThat(objects, contains(isRow(100L))); execute("refresh table bulk_import"); execute("select count(*) from bulk_import"); assertThat(response.rowCount(), is(1L)); assertThat(response.rows()[0][0], is(100L)); }
From source file:io.crate.execution.engine.indexing.IndexWriterProjectorUnitTest.java
License:Apache License
@Test public void testNullPKValue() throws Throwable { InputCollectExpression sourceInput = new InputCollectExpression(0); List<CollectExpression<Row, ?>> collectExpressions = Collections .<CollectExpression<Row, ?>>singletonList(sourceInput); TransportCreatePartitionsAction transportCreatePartitionsAction = mock( TransportCreatePartitionsAction.class); IndexWriterProjector indexWriter = new IndexWriterProjector(clusterService, new NodeJobsCounter(), scheduler, executor, TestingHelpers.getFunctions(), Settings.EMPTY, Settings.EMPTY, transportCreatePartitionsAction, (request, listener) -> { }, IndexNameResolver.forTable(new TableIdent(Schemas.DOC_SCHEMA_NAME, "bulk_import")), rawSourceReference, Arrays.asList(ID_IDENT), Arrays.<Symbol>asList(new InputColumn(1)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID()); RowN rowN = new RowN(new Object[] { new BytesRef("{\"y\": \"x\"}"), null }); BatchIterator<Row> batchIterator = InMemoryBatchIterator.of(Collections.singletonList(rowN), SENTINEL); batchIterator = indexWriter.apply(batchIterator); TestingRowConsumer testingBatchConsumer = new TestingRowConsumer(); testingBatchConsumer.accept(batchIterator, null); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("A primary key value must not be NULL"); testingBatchConsumer.getResult();/*from w w w .j av a 2s . c om*/ }
From source file:io.crate.execution.engine.join.RamAccountingBatchIteratorTest.java
License:Apache License
@Test public void testNoCircuitBreaking() throws Exception { BatchIterator<Row> batchIterator = new RamAccountingBatchIterator<>( TestingBatchIterators//w w w . j a v a2s.com .ofValues(Arrays.asList(new BytesRef("a"), new BytesRef("b"), new BytesRef("c"))), new RowAccounting(ImmutableList.of(DataTypes.STRING), new RamAccountingContext("test", NOOP_CIRCUIT_BREAKER))); TestingRowConsumer consumer = new TestingRowConsumer(); consumer.accept(batchIterator, null); assertThat(consumer.getResult(), Matchers.contains(new Object[] { new BytesRef("a") }, new Object[] { new BytesRef("b") }, new Object[] { new BytesRef("c") })); }
From source file:io.crate.execution.engine.join.RamAccountingBatchIteratorTest.java
License:Apache License
@Test public void testCircuitBreaking() throws Exception { BatchIterator<Row> batchIterator = new RamAccountingBatchIterator<>( TestingBatchIterators.ofValues(Arrays.asList(new BytesRef("aaa"), new BytesRef("bbb"), new BytesRef("ccc"), new BytesRef("ddd"), new BytesRef("eee"), new BytesRef("fff"))), new RowAccounting(ImmutableList.of(DataTypes.STRING), new RamAccountingContext("test", new MemoryCircuitBreaker(new ByteSizeValue(34, ByteSizeUnit.BYTES), 1, Loggers.getLogger(RowAccountingTest.class))))); expectedException.expect(CircuitBreakingException.class); expectedException.expectMessage(//from w w w .jav a 2 s . c o m "Data too large, data for field [test] would be [35/35b], which is larger than the limit of [34/34b]"); TestingRowConsumer consumer = new TestingRowConsumer(); consumer.accept(batchIterator, null); consumer.getResult(); }
From source file:io.crate.execution.engine.pipeline.ProjectionToProjectorVisitorTest.java
License:Apache License
@Test public void testGroupProjector() throws Exception { // in(0) in(1) in(0), in(2) // select race, avg(age), count(race), gender ... group by race, gender List<Symbol> keys = Arrays.asList(new InputColumn(0, DataTypes.STRING), new InputColumn(2, DataTypes.STRING)); List<Aggregation> aggregations = Arrays.asList( new Aggregation(avgInfo, avgInfo.returnType(), Collections.singletonList(new InputColumn(1))), new Aggregation(countInfo, countInfo.returnType(), Collections.singletonList(new InputColumn(0)))); GroupProjection projection = new GroupProjection(keys, aggregations, AggregateMode.ITER_FINAL, RowGranularity.CLUSTER);//from www. j a v a 2s . co m Projector projector = visitor.create(projection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID()); assertThat(projector, instanceOf(GroupingProjector.class)); // use a topN projection in order to get sorted outputs List<Symbol> outputs = Arrays.asList(new InputColumn(0, DataTypes.STRING), new InputColumn(1, DataTypes.STRING), new InputColumn(2, DataTypes.DOUBLE), new InputColumn(3, DataTypes.LONG)); OrderedTopNProjection topNProjection = new OrderedTopNProjection(10, 0, outputs, ImmutableList.of(new InputColumn(2, DataTypes.DOUBLE)), new boolean[] { false }, new Boolean[] { null }); Projector topNProjector = visitor.create(topNProjection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID()); BytesRef human = new BytesRef("human"); BytesRef vogon = new BytesRef("vogon"); BytesRef male = new BytesRef("male"); BytesRef female = new BytesRef("female"); List<Object[]> rows = new ArrayList<>(); rows.add($(human, 34, male)); rows.add($(human, 22, female)); rows.add($(vogon, 40, male)); rows.add($(vogon, 48, male)); rows.add($(human, 34, male)); BatchIterator<Row> batchIterator = topNProjector .apply(projector.apply(InMemoryBatchIterator.of(new CollectionBucket(rows), SENTINEL))); TestingRowConsumer consumer = new TestingRowConsumer(); consumer.accept(batchIterator, null); Bucket bucket = consumer.getBucket(); assertThat(bucket, contains(isRow(human, female, 22.0, 1L), isRow(human, male, 34.0, 2L), isRow(vogon, male, 44.0, 2L))); }