List of usage examples for org.apache.lucene.util BytesRef BytesRef
public BytesRef(CharSequence text)
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testLikeInWhereQuery() { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from sys.nodes where name like 'foo'"); assertNotNull(analysis.whereClause()); Function whereClause = (Function) analysis.whereClause().query(); assertEquals(LikeOperator.NAME, whereClause.info().ident().name()); ImmutableList<DataType> argumentTypes = ImmutableList.<DataType>of(DataTypes.STRING, DataTypes.STRING); assertEquals(argumentTypes, whereClause.info().ident().argumentTypes()); assertThat(whereClause.arguments().get(0), IsInstanceOf.instanceOf(Reference.class)); assertThat(whereClause.arguments().get(1), IsInstanceOf.instanceOf(Literal.class)); Literal stringLiteral = (Literal) whereClause.arguments().get(1); assertThat((BytesRef) stringLiteral.value(), is(new BytesRef(("foo")))); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testLikeNoStringDataTypeInWhereQuery() { SelectAnalysis analysis = (SelectAnalysis) 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.whereClause().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.SelectAnalyzerTest.java
License:Apache License
@Test public void testLikeLongDataTypeInWhereQuery() { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from sys.nodes where 1 like 2"); // check if implicit cast worked of both, expression and pattern. Function function = (Function) analysis.functions().toArray()[0]; assertEquals(LikeOperator.NAME, function.info().ident().name()); ImmutableList<DataType> argumentTypes = ImmutableList.<DataType>of(DataTypes.STRING, DataTypes.STRING); assertEquals(argumentTypes, function.info().ident().argumentTypes()); assertThat(function.arguments().get(0), IsInstanceOf.instanceOf(Literal.class)); assertThat(function.arguments().get(1), IsInstanceOf.instanceOf(Literal.class)); Literal expressionLiteral = (Literal) function.arguments().get(0); Literal patternLiteral = (Literal) function.arguments().get(1); assertThat((BytesRef) expressionLiteral.value(), is(new BytesRef("1"))); assertThat((BytesRef) patternLiteral.value(), is(new BytesRef("2"))); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testSelectFromPartitionedTable() throws Exception { String partition1 = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).stringValue(); String partition2 = new PartitionName("parted", Arrays.asList(new BytesRef("1395961200000"))).stringValue(); String partition3 = new PartitionName("parted", new ArrayList<BytesRef>() { {/*ww w .j av a2s . c o m*/ add(null); } }).stringValue(); SelectAnalysis analysis = (SelectAnalysis) analyze( "select id, name from parted where date = 1395874800000"); assertEquals(ImmutableList.of(partition1), analysis.whereClause().partitions()); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze("select id, name from parted where date >= 1395874800000"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze("select id, name from parted where date < 1395874800000"); assertEquals(ImmutableList.of(), analysis.whereClause().partitions()); assertTrue(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date = 1395874800000 and date = 1395961200000"); assertEquals(ImmutableList.of(), analysis.whereClause().partitions()); assertTrue(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date = 1395874800000 or date = 1395961200000"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date < 1395874800000 or date > 1395874800000"); assertEquals(ImmutableList.of(partition2), analysis.whereClause().partitions()); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date in (1395874800000, 1395961200000)"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date in (1395874800000, 1395961200000) and id = 1"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertTrue(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date in (1395874800000) or date in (1395961200000)"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze("select id, name from parted where date = 1395961200000 and id = 1"); assertEquals(ImmutableList.of(partition2), analysis.whereClause().partitions()); assertTrue(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where (date =1395874800000 or date = 1395961200000) and id = 1"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertTrue(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where date = 1395874800000 and id is null"); assertEquals(ImmutableList.of(partition1), analysis.whereClause().partitions()); assertTrue(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze("select id, name from parted where date is null and id = 1"); assertEquals(ImmutableList.of(partition3), analysis.whereClause().partitions()); assertTrue(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); analysis = (SelectAnalysis) analyze( "select id, name from parted where 1395874700000 < date and date < 1395961200001"); assertThat(analysis.whereClause().partitions(), containsInAnyOrder(partition1, partition2)); assertFalse(analysis.whereClause().hasQuery()); assertFalse(analysis.noMatch()); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testAnyLike() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from users where 'awesome' LIKE ANY (tags)"); assertThat(analysis.whereClause().hasQuery(), is(true)); Function query = (Function) analysis.whereClause().query(); assertThat(query.info().ident().name(), is("any_like")); assertThat(query.arguments().size(), is(2)); assertThat(query.arguments().get(0), Matchers.instanceOf(Reference.class)); assertThat(((Reference) query.arguments().get(0)).info().ident().columnIdent().fqn(), is("tags")); assertThat(query.arguments().get(1), instanceOf(Literal.class)); assertThat(((Literal<?>) query.arguments().get(1)).value(), Matchers.<Object>is(new BytesRef("awesome"))); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testAnyNotLike() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze( "select * from users where 'awesome' NOT LIKE ANY (tags)"); assertThat(analysis.whereClause().hasQuery(), is(true)); Function query = (Function) analysis.whereClause().query(); assertThat(query.info().ident().name(), is("any_not_like")); assertThat(query.arguments().size(), is(2)); assertThat(query.arguments().get(0), Matchers.instanceOf(Reference.class)); assertThat(((Reference) query.arguments().get(0)).info().ident().columnIdent().fqn(), is("tags")); assertThat(query.arguments().get(1), instanceOf(Literal.class)); assertThat(((Literal<?>) query.arguments().get(1)).value(), Matchers.<Object>is(new BytesRef("awesome"))); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testWhereMatchOnColumn() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from users where match(name, 'Arthur Dent')"); Function query = (Function) analysis.whereClause.query(); assertThat(query.info().ident().name(), is("match")); assertThat(query.arguments().size(), is(4)); assertThat(query.arguments().get(0), Matchers.instanceOf(Literal.class)); Literal<Map<String, Object>> idents = (Literal<Map<String, Object>>) query.arguments().get(0); assertThat(idents.value().size(), is(1)); assertThat(idents.value().get("name"), is(nullValue())); assertThat(query.arguments().get(1), Matchers.instanceOf(Literal.class)); assertThat((BytesRef) ((Literal) query.arguments().get(1)).value(), is(new BytesRef("Arthur Dent"))); assertThat((BytesRef) ((Literal) query.arguments().get(2)).value(), is(new BytesRef("best_fields"))); Literal<Map<String, Object>> options = (Literal<Map<String, Object>>) query.arguments().get(3); assertThat(options.value(), Matchers.instanceOf(Map.class)); assertThat(options.value().size(), is(0)); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testMatchOnIndex() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze( "select * from users where match(name_text_ft, 'Arthur Dent')"); Function query = (Function) analysis.whereClause.query(); assertThat(query.info().ident().name(), is("match")); assertThat(query.arguments().size(), is(4)); assertThat(query.arguments().get(0), Matchers.instanceOf(Literal.class)); Literal<Map<String, Object>> idents = (Literal<Map<String, Object>>) query.arguments().get(0); assertThat(idents.value().size(), is(1)); assertThat(idents.value().get("name_text_ft"), is(nullValue())); assertThat(query.arguments().get(1), Matchers.instanceOf(Literal.class)); assertThat((BytesRef) ((Literal) query.arguments().get(1)).value(), is(new BytesRef("Arthur Dent"))); assertThat((BytesRef) ((Literal) query.arguments().get(2)).value(), is(new BytesRef("best_fields"))); Literal<Map<String, Object>> options = (Literal<Map<String, Object>>) query.arguments().get(3); assertThat(options.value(), Matchers.instanceOf(Map.class)); assertThat(options.value().size(), is(0)); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testSelectWhereSimpleMatchPredicate() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from users where match (text, 'awesome')"); assertThat(analysis.whereClause().hasQuery(), is(true)); Function query = (Function) analysis.whereClause().query(); assertThat(query.info().ident().name(), is(MatchPredicate.NAME)); assertThat(query.arguments().size(), is(4)); assertThat(query.arguments().get(0), Matchers.instanceOf(Literal.class)); Literal<Map<String, Object>> idents = (Literal<Map<String, Object>>) query.arguments().get(0); assertThat(idents.value().keySet(), hasItem("text")); assertThat(idents.value().get("text"), is(nullValue())); assertThat(query.arguments().get(1), instanceOf(Literal.class)); assertThat(((Literal<?>) query.arguments().get(1)).value(), Matchers.<Object>is(new BytesRef("awesome"))); }
From source file:io.crate.analyze.SelectAnalyzerTest.java
License:Apache License
@Test public void testSelectWhereFullMatchPredicate() throws Exception { SelectAnalysis analysis = (SelectAnalysis) analyze("select * from users " + "where match ((name 1.2, text), 'awesome') using best_fields with (analyzer='german')"); assertThat(analysis.whereClause().hasQuery(), is(true)); Function query = (Function) analysis.whereClause().query(); assertThat(query.info().ident().name(), is(MatchPredicate.NAME)); assertThat(query.arguments().size(), is(4)); assertThat(query.arguments().get(0), Matchers.instanceOf(Literal.class)); Literal<Map<String, Object>> idents = (Literal<Map<String, Object>>) query.arguments().get(0); assertThat(idents.value().size(), is(2)); assertThat((Double) idents.value().get("name"), is(1.2d)); assertThat(idents.value().get("text"), is(Matchers.nullValue())); assertThat((BytesRef) ((Literal) query.arguments().get(1)).value(), is(new BytesRef("awesome"))); assertThat((BytesRef) ((Literal) query.arguments().get(2)).value(), is(new BytesRef("best_fields"))); Literal<Map<String, Object>> options = (Literal<Map<String, Object>>) query.arguments().get(3); assertThat(options.value().size(), is(1)); assertThat((String) options.value().get("analyzer"), is("german")); }