List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.analyze.SelectStatementAnalyzerTest.java
License:Apache License
@Test public void testLikeNoStringDataTypeInWhereQuery() { SelectAnalyzedStatement analysis = analyze("select * from sys.nodes where name like 1"); // check if the implicit cast of the pattern worked ImmutableList<DataType> argumentTypes = ImmutableList.<DataType>of(DataTypes.STRING, DataTypes.STRING); Function whereClause = (Function) analysis.relation().querySpec().where().query(); assertEquals(argumentTypes, whereClause.info().ident().argumentTypes()); assertThat(whereClause.arguments().get(1), IsInstanceOf.instanceOf(Literal.class)); Literal stringLiteral = (Literal) whereClause.arguments().get(1); assertThat((BytesRef) stringLiteral.value(), is(new BytesRef("1"))); }
From source file:io.crate.analyze.SnapshotRestoreAnalyzerTest.java
License:Apache License
@Test public void testRestoreSinglePartition() throws Exception { RestoreSnapshotAnalyzedStatement statement = (RestoreSnapshotAnalyzedStatement) analyze( "RESTORE SNAPSHOT my_repo.my_snapshot TABLE parted PARTITION (date=123)"); String partition = new PartitionName("parted", ImmutableList.of(new BytesRef("123"))).asIndexName(); assertThat(statement.indices(), contains(partition)); }
From source file:io.crate.analyze.SnapshotRestoreAnalyzerTest.java
License:Apache License
@Test public void testRestoreSinglePartitionToUnknownTable() throws Exception { RestoreSnapshotAnalyzedStatement statement = (RestoreSnapshotAnalyzedStatement) analyze( "RESTORE SNAPSHOT my_repo.my_snapshot TABLE unknown_parted PARTITION (date=123)"); String partition = new PartitionName("unknown_parted", ImmutableList.of(new BytesRef("123"))).asIndexName(); assertThat(statement.indices(), contains(partition)); }
From source file:io.crate.analyze.TableDefinitions.java
License:Apache License
public static TestingBlobTableInfo createBlobTable(TableIdent ident, ClusterService clusterService) { return new TestingBlobTableInfo(ident, ident.indexName(), clusterService, 5, new BytesRef("0"), ImmutableMap.<String, Object>of(), null, SHARD_ROUTING); }
From source file:io.crate.analyze.UpdateAnalyzerTest.java
License:Apache License
@Test public void testUpdateWherePartitionedByColumn() throws Exception { UpdateAnalysis.NestedAnalysis analysis = analyze("update parted set id = 2 where date = 1395874800000"); assertThat(analysis.whereClause().hasQuery(), is(false)); assertThat(analysis.whereClause().noMatch(), is(false)); assertEquals(//from w w w . j a v a2s . c om ImmutableList.of( new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).stringValue()), analysis.whereClause().partitions()); }
From source file:io.crate.analyze.where.EqualityExtractorTest.java
License:Apache License
@Test public void testExtractSinglePKFromAnyEq() throws Exception { Symbol query = AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") })); List<List<Symbol>> matches = analyzeExactX(query); assertThat(matches.size(), is(3));/* www .j a v a 2 s. c om*/ assertThat(matches, containsInAnyOrder(contains(isLiteral("a")), contains(isLiteral("b")), contains(isLiteral("c")))); }
From source file:io.crate.analyze.where.EqualityExtractorTest.java
License:Apache License
@Test public void testExtract2ColPKFromAnyEq() throws Exception { Symbol query = And(//from w ww . j av a2 s . co m AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") })), Eq("y", 4)); List<List<Symbol>> matches = analyzeExactXY(query); assertThat(matches.size(), is(3)); assertThat(matches, containsInAnyOrder(contains(isLiteral("a"), isLiteral(4)), contains(isLiteral("b"), isLiteral(4)), contains(isLiteral("c"), isLiteral(4)))); }
From source file:io.crate.analyze.where.EqualityExtractorTest.java
License:Apache License
@Test public void testExtractSinglePKFromAnyEqInOr() throws Exception { Symbol query = Or(/* w w w. j a va 2s. c om*/ AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") })), AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("d"), new BytesRef("e"), new BytesRef("c") }))); List<List<Symbol>> matches = analyzeExactX(query); assertThat(matches.size(), is(5)); assertThat(matches, containsInAnyOrder(contains(isLiteral("a")), contains(isLiteral("b")), contains(isLiteral("c")), contains(isLiteral("d")), contains(isLiteral("e")) )); }
From source file:io.crate.analyze.where.EqualityExtractorTest.java
License:Apache License
@Test public void testExtractSinglePK1FromAndAnyEq() throws Exception { Symbol query = And(/*from w ww . j a v a2 s .co m*/ AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") })), AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("d"), new BytesRef("e"), new BytesRef("c") }))); List<List<Symbol>> matches = analyzeExactX(query); assertThat(matches, is(notNullValue())); assertThat(matches.size(), is(1)); // STRING c assertThat(matches, contains(contains(isLiteral(new BytesRef("c"))))); }
From source file:io.crate.analyze.where.EqualityExtractorTest.java
License:Apache License
@Test public void testExtract2ColPKFromAnyEqAnd() throws Exception { Symbol query = And(//from w ww .j a v a 2 s .c o m AnyEq(Ref("x"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") })), AnyEq(Ref("y"), Literal.newLiteral(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("a"), new BytesRef("b"), new BytesRef("c") }))); List<List<Symbol>> matches = analyzeExactXY(query); assertThat(matches.size(), is(9)); // cartesian product: 3 * 3 assertThat(matches, containsInAnyOrder(contains(isLiteral("a"), isLiteral("a")), contains(isLiteral("a"), isLiteral("b")), contains(isLiteral("a"), isLiteral("c")), contains(isLiteral("b"), isLiteral("a")), contains(isLiteral("b"), isLiteral("b")), contains(isLiteral("b"), isLiteral("c")), contains(isLiteral("c"), isLiteral("a")), contains(isLiteral("c"), isLiteral("b")), contains(isLiteral("c"), isLiteral("c")))); }