List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.metadata.sys.TableHealthServiceTest.java
License:Apache License
@Test public void testTableIsDeletedWhileComputing() { TableHealthService.TablePartitionIdent tablePartitionIdent = new TableHealthService.TablePartitionIdent( new BytesRef("t1"), new BytesRef("doc"), null); TableIdent tableIdent = new TableIdent("doc", "t1"); Schemas schemas = mock(Schemas.class); when(schemas.getTableInfo(tableIdent)).thenThrow(new TableUnknownException(tableIdent)); TableHealthService tableHealthService = new TableHealthService(Settings.EMPTY, clusterService, schemas, null);// w ww . ja v a2 s . c om Map<TableHealthService.TablePartitionIdent, TableHealthService.ShardsInfo> tables = Collections .singletonMap(tablePartitionIdent, new TableHealthService.ShardsInfo()); List<TableHealth> tableHealthList = tableHealthService.buildTablesHealth(tables); assertThat(tableHealthList.size(), is(0)); }
From source file:io.crate.metadata.TableIdentTest.java
License:Apache License
@Test public void testFromIndexName() throws Exception { assertThat(TableIdent.fromIndexName("t"), is(new TableIdent(null, "t"))); assertThat(TableIdent.fromIndexName("s.t"), is(new TableIdent("s", "t"))); PartitionName pn = new PartitionName("s", "t", ImmutableList.of(new BytesRef("v1"))); assertThat(TableIdent.fromIndexName(pn.asIndexName()), is(new TableIdent("s", "t"))); pn = new PartitionName(null, "t", ImmutableList.of(new BytesRef("v1"))); assertThat(TableIdent.fromIndexName(pn.asIndexName()), is(new TableIdent(null, "t"))); }
From source file:io.crate.module.sql.benchmark.BulkDeleteBenchmark.java
License:Apache License
private HashMap<String, String> createSampleData() { Object[][] bulkArgs = new Object[ROWS][]; HashMap<String, String> ids = new HashMap<>(); for (int i = 0; i < ROWS; i++) { Object[] object = getRandomObject(); bulkArgs[i] = object;/*from w w w. java 2 s . co m*/ String id = (String) object[0]; Id esId = new Id(ImmutableList.of(new ColumnIdent("id")), ImmutableList.of(new BytesRef(id)), new ColumnIdent("id"), true); ids.put(id, esId.stringValue()); } SQLRequest request = new SQLRequest(SINGLE_INSERT_SQL_STMT, bulkArgs); client().execute(SQLAction.INSTANCE, request).actionGet(); refresh(client()); return ids; }
From source file:io.crate.module.sql.benchmark.GroupingProjectorBenchmark.java
License:Apache License
@Test public void testGroupByMinBytesRef() throws Exception { Functions functions = new ModulesBuilder().add(new AggregationImplModule()).createInjector() .getInstance(Functions.class); InputCollectExpression keyInput = new InputCollectExpression(0); List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput); CollectExpression[] collectExpressions = new CollectExpression[] { keyInput }; FunctionIdent minStringFuncIdent = new FunctionIdent(MinimumAggregation.NAME, Arrays.<DataType>asList(DataTypes.STRING)); FunctionInfo minStringFuncInfo = new FunctionInfo(minStringFuncIdent, DataTypes.STRING, FunctionInfo.Type.AGGREGATE); AggregationFunction minAgg = (AggregationFunction) functions.get(minStringFuncIdent); Aggregation aggregation = new Aggregation(minStringFuncInfo, Arrays.<Symbol>asList(new InputColumn(0)), Aggregation.Step.ITER, Aggregation.Step.FINAL); AggregationContext aggregationContext = new AggregationContext(minAgg, aggregation); aggregationContext.addInput(keyInput); AggregationContext[] aggregations = new AggregationContext[] { aggregationContext }; GroupingProjector groupingProjector = new GroupingProjector(Arrays.<DataType>asList(DataTypes.STRING), keyInputs, collectExpressions, aggregations, RAM_ACCOUNTING_CONTEXT); groupingProjector.registerUpstream(null); groupingProjector.startProjection(); List<BytesRef> keys = new ArrayList<>(Locale.getISOCountries().length); for (String s : Locale.getISOCountries()) { keys.add(new BytesRef(s)); }/*from w w w . j a va 2s .co m*/ for (int i = 0; i < 20_000_000; i++) { groupingProjector.setNextRow(keys.get(i % keys.size())); } groupingProjector.upstreamFinished(); }
From source file:io.crate.operation.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
private void addDocToLucene(IndexWriter w, Long value) throws IOException { Document doc = new Document(); if (value != null) { doc.add(new LegacyLongFieldMapper.CustomLongNumericField(value, valueFieldType)); doc.add(new SortedNumericDocValuesField("value", value)); } else {// www. j a v a2s . c o m // Create a placeholder field doc.add(new SortedDocValuesField("null_value", new BytesRef("null"))); } w.addDocument(doc); }
From source file:io.crate.operation.collect.files.BlobDocCollectorTest.java
License:Apache License
@Test public void testBlobFound() throws Exception { BlobContainer container = new BlobContainer(tempFolder.newFolder()); String digest = "417de3231e23dcd6d224ff60918024bc6c59aa58"; long mtime = createFile(container, digest).lastModified(); Input<Boolean> condition = Literal.BOOLEAN_TRUE; CollectingRowReceiver projector = getProjector(container, Arrays.<Input<?>>asList(digestExpression, ctimeExpression), Arrays.<CollectExpression<File, ?>>asList(digestExpression, ctimeExpression), condition); Bucket result = projector.result();/*from w ww . ja va2s. co m*/ assertThat(result, contains(isRow(new BytesRef(digest), mtime))); }
From source file:io.crate.operation.collect.files.FileReadingIteratorTest.java
License:Apache License
@Test public void testIteratorContract() throws Exception { String fileUri = tempFilePath.toUri().toString(); Supplier<BatchIterator> 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.operation.collect.LocalDataCollectTest.java
License:Apache License
@Test public void testCollectLiterals() throws Exception { CollectNode collectNode = new CollectNode("literals", testRouting); collectNode.toCollect(Arrays.<Symbol>asList(Literal.newLiteral("foobar"), Literal.newLiteral(true), Literal.newLiteral(1), Literal.newLiteral(4.2))); Object[][] result = operation.collect(collectNode).get(); assertThat(result.length, equalTo(1)); assertThat((BytesRef) result[0][0], equalTo(new BytesRef("foobar"))); assertThat((Boolean) result[0][1], equalTo(true)); assertThat((Integer) result[0][2], equalTo(1)); assertThat((Double) result[0][3], equalTo(4.2)); }
From source file:io.crate.operation.collect.ModuloBucketingIteratorTest.java
License:Apache License
@Test public void testBytesRefHashing() throws Exception { ModuloBucketingIterator moduloBucketingIterator = new ModuloBucketingIterator(4, null); int bucket = moduloBucketingIterator.getBucket(new Object[] { new BytesRef("foo") }); assertThat(bucket, is(2));// w w w . j a v a2 s. co m }
From source file:io.crate.operation.collect.SimpleOneRowCollectorTest.java
License:Apache License
@Test public void testCollectOneRow() throws Exception { Projector downStream = mock(Projector.class); SimpleOneRowCollector collector = new SimpleOneRowCollector(inputs, Collections.<CollectExpression<?>>emptySet(), downStream); collector.doCollect();//w ww .j av a 2s. co m verify(downStream, never()).startProjection(); verify(downStream, times(1)).setNextRow(true, new BytesRef("foo")); verify(downStream, times(1)).upstreamFinished(); }