use of io.crate.analyze.WhereClause in project crate by crate.
the class RoutedCollectPhase method readFrom.
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
distributionInfo = DistributionInfo.fromStream(in);
toCollect = Symbols.listFromStream(in);
maxRowGranularity = RowGranularity.fromStream(in);
if (in.readBoolean()) {
routing = Routing.fromStream(in);
}
whereClause = new WhereClause(in);
if (in.readBoolean()) {
nodePageSizeHint = in.readVInt();
}
if (in.readBoolean()) {
orderBy = OrderBy.fromStream(in);
}
isPartitioned = in.readBoolean();
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class RowsTransformer method toRowsIterable.
public static Iterable<Row> toRowsIterable(InputFactory inputFactory, ReferenceResolver<?> referenceResolver, RoutedCollectPhase collectPhase, Iterable<?> iterable) {
WhereClause whereClause = collectPhase.whereClause();
if (whereClause.noMatch()) {
return Collections.emptyList();
}
InputFactory.Context ctx = inputFactory.ctxForRefs(referenceResolver);
ctx.add(collectPhase.toCollect());
OrderBy orderBy = collectPhase.orderBy();
if (orderBy != null) {
for (Symbol symbol : orderBy.orderBySymbols()) {
ctx.add(symbol);
}
}
Input<Boolean> condition;
if (whereClause.hasQuery()) {
assert DataTypes.BOOLEAN.equals(whereClause.query().valueType()) : "whereClause.query() must be of type " + DataTypes.BOOLEAN;
//noinspection unchecked whereClause().query() is a symbol of type boolean so it must become Input<Boolean>
condition = (Input<Boolean>) ctx.add(whereClause.query());
} else {
condition = Literal.BOOLEAN_TRUE;
}
@SuppressWarnings("unchecked") Iterable<Row> rows = Iterables.filter(Iterables.transform(iterable, new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.expressions())), InputCondition.asPredicate(condition));
if (orderBy == null) {
return rows;
}
return sortRows(Iterables.transform(rows, Row::materialize), collectPhase);
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testWherePartitionedByColumn.
@Test
public void testWherePartitionedByColumn() throws Exception {
DeleteAnalyzedStatement statement = e.analyze("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()));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testAnyLikeArrayLiteral.
@Test
public void testAnyLikeArrayLiteral() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from users where name like any(['a', 'b', 'c'])");
assertThat(whereClause.query(), isFunction(AnyLikeOperator.NAME, ImmutableList.<DataType>of(DataTypes.STRING, new ArrayType(DataTypes.STRING))));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method testSelectPartitionedByPK.
@Test
public void testSelectPartitionedByPK() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select id from parted_pk where id = 1 and date = 1395874800000");
assertThat(whereClause.docKeys().get(), contains(isDocKey(1, 1395874800000L)));
// not partitions if docKeys are there
assertThat(whereClause.partitions(), empty());
}
Aggregations