Search in sources :

Example 31 with WhereClause

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();
}
Also used : WhereClause(io.crate.analyze.WhereClause)

Example 32 with WhereClause

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);
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) Row(io.crate.data.Row)

Example 33 with WhereClause

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()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) DeleteAnalyzedStatement(io.crate.analyze.DeleteAnalyzedStatement) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 34 with WhereClause

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))));
}
Also used : ArrayType(io.crate.types.ArrayType) WhereClause(io.crate.analyze.WhereClause) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 35 with WhereClause

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());
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

WhereClause (io.crate.analyze.WhereClause)61 Test (org.junit.Test)46 CrateUnitTest (io.crate.test.integration.CrateUnitTest)43 Symbol (io.crate.analyze.symbol.Symbol)10 PartitionName (io.crate.metadata.PartitionName)8 BytesRef (org.apache.lucene.util.BytesRef)8 DataType (io.crate.types.DataType)6 TableInfo (io.crate.metadata.table.TableInfo)5 SqlExpressions (io.crate.testing.SqlExpressions)5 QualifiedName (io.crate.sql.tree.QualifiedName)4 ArrayType (io.crate.types.ArrayType)4 ImmutableList (com.google.common.collect.ImmutableList)3 OrderBy (io.crate.analyze.OrderBy)3 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 TableRelation (io.crate.analyze.relations.TableRelation)3 Function (io.crate.analyze.symbol.Function)3 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)3 CrateRegexQuery (io.crate.lucene.match.CrateRegexQuery)3 Literal (io.crate.analyze.symbol.Literal)2 Bucket (io.crate.data.Bucket)2