List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.analyze.where.WhereClauseAnalyzerTest.java
License:Apache License
@Test public void testSelectWherePartitionedByColumn() throws Exception { WhereClause whereClause = analyzeSelectWhere("select id from parted where date = 1395874800000"); assertThat(whereClause.hasQuery(), is(false)); assertThat(whereClause.noMatch(), is(false)); assertThat(whereClause.partitions(), Matchers .contains(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName())); }
From source file:io.crate.analyze.where.WhereClauseAnalyzerTest.java
License:Apache License
@Test public void testWherePartitionedByColumn() throws Exception { DeleteAnalyzedStatement statement = analyzeDelete("delete from parted where date = 1395874800000"); WhereClause whereClause = statement.whereClauses().get(0); assertThat(whereClause.hasQuery(), is(false)); assertThat(whereClause.noMatch(), is(false)); assertThat(whereClause.partitions(), Matchers .contains(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName())); }
From source file:io.crate.analyze.where.WhereClauseAnalyzerTest.java
License:Apache License
@Test public void testUpdateWherePartitionedByColumn() throws Exception { UpdateAnalyzedStatement updateAnalyzedStatement = analyzeUpdate( "update parted set id = 2 where date = 1395874800000"); UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalyzedStatement = updateAnalyzedStatement .nestedStatements().get(0);//ww w.j a va 2s . com assertThat(nestedAnalyzedStatement.whereClause().hasQuery(), is(false)); assertThat(nestedAnalyzedStatement.whereClause().noMatch(), is(false)); assertEquals( ImmutableList.of( new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName()), nestedAnalyzedStatement.whereClause().partitions()); }
From source file:io.crate.analyze.where.WhereClauseAnalyzerTest.java
License:Apache License
@Test public void testSelectFromPartitionedTable() throws Exception { String partition1 = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName(); String partition2 = new PartitionName("parted", Arrays.asList(new BytesRef("1395961200000"))).asIndexName(); String partition3 = new PartitionName("parted", new ArrayList<BytesRef>() { {//from ww w .ja va 2s . c o m add(null); } }).asIndexName(); WhereClause whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000"); assertEquals(ImmutableList.of(partition1), whereClause.partitions()); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date = 1395874800000 " + "and substr(name, 0, 4) = 'this'"); assertEquals(ImmutableList.of(partition1), whereClause.partitions()); assertThat(whereClause.hasQuery(), is(true)); assertThat(whereClause.noMatch(), is(false)); whereClause = analyzeSelectWhere("select id, name from parted where date >= 1395874800000"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere("select id, name from parted where date < 1395874800000"); assertEquals(ImmutableList.of(), whereClause.partitions()); assertTrue(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date = 1395874800000 and date = 1395961200000"); assertEquals(ImmutableList.of(), whereClause.partitions()); assertTrue(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date = 1395874800000 or date = 1395961200000"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date < 1395874800000 or date > 1395874800000"); assertEquals(ImmutableList.of(partition2), whereClause.partitions()); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date in (1395874800000, 1395961200000)"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where date in (1395874800000, 1395961200000) and id = 1"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertTrue(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); /** * * col = 'undefined' -> null as col doesn't exist * -> * not (true and null) -> not (null) -> match * not (null and null) -> not (null) -> match * not (false and null) -> not (false) -> match */ whereClause = analyzeSelectWhere( "select id, name from parted where not (date = 1395874800000 and obj['col'] = 'undefined')"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2, partition3)); assertThat(whereClause.hasQuery(), is(false)); assertThat(whereClause.noMatch(), is(false)); whereClause = analyzeSelectWhere( "select id, name from parted where date in (1395874800000) or date in (1395961200000)"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere("select id, name from parted where date = 1395961200000 and id = 1"); assertEquals(ImmutableList.of(partition2), whereClause.partitions()); assertTrue(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where (date =1395874800000 or date = 1395961200000) and id = 1"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertTrue(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere("select id, name from parted where date = 1395874800000 and id is null"); assertEquals(ImmutableList.of(partition1), whereClause.partitions()); assertTrue(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere("select id, name from parted where date is null and id = 1"); assertEquals(ImmutableList.of(partition3), whereClause.partitions()); assertTrue(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where 1395874700000 < date and date < 1395961200001"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); whereClause = analyzeSelectWhere( "select id, name from parted where '2014-03-16T22:58:20' < date and date < '2014-03-27T23:00:01'"); assertThat(whereClause.partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(whereClause.hasQuery()); assertFalse(whereClause.noMatch()); }
From source file:io.crate.analyze.WhereClause.java
License:Apache License
@Override public void writeTo(StreamOutput out) throws IOException { if (query != null) { out.writeBoolean(true);//from w ww . j a va 2 s.co m query.writeTo(out); } else { out.writeBoolean(false); out.writeBoolean(noMatch); } if (clusteredBy != null) { out.writeBoolean(true); out.writeBytesRef(new BytesRef(clusteredBy)); } else { out.writeBoolean(false); } if (version != null) { out.writeBoolean(true); out.writeVLong(version); } else { out.writeBoolean(false); } }
From source file:io.crate.benchmark.BulkDeleteBenchmark.java
License:Apache License
private HashMap<String, String> createSampleData() { Object[][] bulkArgs = new Object[ROWS][]; HashMap<String, String> ids = new HashMap<>(); ColumnIdent idColumn = new ColumnIdent("id"); Function<List<BytesRef>, String> idFunction = Id.compile(ImmutableList.of(idColumn), new ColumnIdent("id")); for (int i = 0; i < ROWS; i++) { Object[] object = getRandomObject(); bulkArgs[i] = object;// w ww. j av a 2 s. co m String id = (String) object[0]; String esId = idFunction.apply(ImmutableList.of(new BytesRef(id))); ids.put(id, esId); } SQLBulkRequest request = new SQLBulkRequest(SINGLE_INSERT_SQL_STMT, bulkArgs); client().execute(SQLBulkAction.INSTANCE, request).actionGet(); refresh(client()); return ids; }
From source file:io.crate.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 = Aggregation.finalAggregation(minStringFuncInfo, Arrays.<Symbol>asList(new InputColumn(0)), Aggregation.Step.ITER); 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); NoOpRowReceiver finalReceiver = new NoOpRowReceiver(); groupingProjector.downstream(finalReceiver); groupingProjector.prepare(mock(ExecutionState.class)); List<BytesRef> keys = new ArrayList<>(Locale.getISOCountries().length); for (String s : Locale.getISOCountries()) { keys.add(new BytesRef(s)); }// w ww .j a va 2 s.co m SpareRow row = new SpareRow(); for (int i = 0; i < 20_000_000; i++) { row.value = keys.get(i % keys.size()); groupingProjector.setNextRow(row); } groupingProjector.finish(); }
From source file:io.crate.benchmark.SubStrBenchmark.java
License:Apache License
private static BytesRef[] toBytesRefs(String[] strings) { BytesRef[] res = new BytesRef[strings.length]; for (int i = 0; i < res.length; i++) { res[i] = new BytesRef(strings[i]); }//from ww w . j av a2s . c o m return res; }
From source file:io.crate.breaker.SizeEstimatorTest.java
License:Apache License
@Test public void testBytesRef() throws Exception { SizeEstimator sizeEstimator = SizeEstimatorFactory.create(DataTypes.STRING); assertThat(sizeEstimator.estimateSize(null), is(8L)); assertThat(sizeEstimator.estimateSize(new BytesRef("hello")), is(69L)); assertThat(sizeEstimator.estimateSizeDelta(new BytesRef("hello"), new BytesRef("hello world")), is(6L)); }
From source file:io.crate.core.collections.RowsTest.java
License:Apache License
@Test public void testSerialization() throws Exception { Rows rows = new Rows(new DataType[] { DataTypes.LONG, DataTypes.STRING, DataTypes.STRING }, Arrays.asList(0, 1, 2)); for (int i = 0; i < randomInt(100); i++) { rows.addSafe(new RowN(new Object[] { randomLong(), new BytesRef(randomUnicodeOfLength(5)), new BytesRef(randomUnicodeOfLength(5)) })); }// w w w . j ava2 s .c o m Rows toWrite = rows; for (int i = 0; i < 3; i++) { BytesStreamOutput out = new BytesStreamOutput(); toWrite.writeTo(out); BytesStreamInput in = new BytesStreamInput(out.bytes()); Rows streamedRows = new Rows(); streamedRows.readFrom(in); List<Row> rowList = new ArrayList<>(); Iterables.addAll(rowList, toWrite); List<Row> streamedRowList = new ArrayList<>(); Iterables.addAll(streamedRowList, streamedRows); assertThat(streamedRowList.size(), is(rowList.size())); for (int j = 0; j < streamedRowList.size(); j++) { assertThat(streamedRowList.get(j).materialize(), is(rowList.get(j).materialize())); } toWrite = streamedRows; } }