use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectFromPartitionedTableWithoutPKInWhereClause.
@Test
public void testSelectFromPartitionedTableWithoutPKInWhereClause() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select id from parted where match(name, 'name')");
assertThat(whereClause.docKeys().isPresent(), is(false));
assertThat(whereClause.partitions(), empty());
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testMultiplePrimaryKeysAndInvalidColumn.
@Test
public void testMultiplePrimaryKeysAndInvalidColumn() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select name from users where id = 2 or id = 1 and name = 'foo'");
assertFalse(whereClause.docKeys().isPresent());
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectFromPartitionedTable.
@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>() {
{
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());
/**
*
* obj['col'] = 'undefined' => null as col doesn't exist
*
* partition1: not (true and null) -> not (null) -> null -> no match
* partition2: not (false and null) -> not (false) -> true -> match
* partition3: not (null and null) -> not (null) -> null -> no match
*/
whereClause = analyzeSelectWhere("select id, name from parted where not (date = 1395874800000 and obj['col'] = 'undefined')");
assertThat(whereClause.partitions(), containsInAnyOrder(partition2));
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());
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectWherePartitionedByColumn.
@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()));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testAnyEqConvertableArrayTypeLiterals.
@Test
public void testAnyEqConvertableArrayTypeLiterals() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from users where name = any([1, 2, 3])");
assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME, ImmutableList.<DataType>of(DataTypes.STRING, new ArrayType(DataTypes.STRING))));
}
Aggregations