Search in sources :

Example 41 with WhereClause

use of io.crate.analyze.WhereClause in project crate by crate.

the class WhereClauseAnalyzerTest method testMultipleColumnsOptimization.

@Test
public void testMultipleColumnsOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts > '2015-01-01T12:00:00' and y = 1");
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420070400000"), new BytesRef("-1"))).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 42 with WhereClause

use of io.crate.analyze.WhereClause in project crate by crate.

the class WhereClauseAnalyzerTest method testClusteredByOnly.

@Test
public void testClusteredByOnly() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users_clustered_by_only where id=1");
    assertFalse(whereClause.docKeys().isPresent());
    assertThat(whereClause.clusteredBy().get(), contains(isLiteral(1L)));
    whereClause = analyzeSelectWhere("select name from users_clustered_by_only where id=1 or id=2");
    assertFalse(whereClause.docKeys().isPresent());
    assertThat(whereClause.clusteredBy().get(), containsInAnyOrder(isLiteral(1L), isLiteral(2L)));
    whereClause = analyzeSelectWhere("select name from users_clustered_by_only where id in (3,4,5)");
    assertFalse(whereClause.docKeys().isPresent());
    assertThat(whereClause.clusteredBy().get(), containsInAnyOrder(isLiteral(3L), isLiteral(4L), isLiteral(5L)));
    // TODO: optimize this case: there are two routing values here, which are currently not set
    whereClause = analyzeSelectWhere("select name from users_clustered_by_only where id=1 and id=2");
    assertFalse(whereClause.docKeys().isPresent());
    assertFalse(whereClause.clusteredBy().isPresent());
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 43 with WhereClause

use of io.crate.analyze.WhereClause in project crate by crate.

the class WhereClauseAnalyzerTest method testMultiplicationGenColNoOptimization.

@Test
public void testMultiplicationGenColNoOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where y > 1");
    // no optimization is done
    assertThat(whereClause.partitions().size(), is(0));
    assertThat(whereClause.noMatch(), is(false));
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 44 with WhereClause

use of io.crate.analyze.WhereClause in project crate by crate.

the class WhereClauseAnalyzerTest method testEqualGenColOptimization.

@Test
public void testEqualGenColOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where y = 1");
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420070400000"), new BytesRef("-1"))).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 45 with WhereClause

use of io.crate.analyze.WhereClause in project crate by crate.

the class WhereClauseAnalyzerTest method testInConvertedToAnyIfOnlyLiterals.

@Test
public void testInConvertedToAnyIfOnlyLiterals() throws Exception {
    StringBuilder sb = new StringBuilder("select id from sys.shards where id in (");
    int i = 0;
    for (; i < 1500; i++) {
        sb.append(i);
        sb.append(',');
    }
    sb.append(i++);
    sb.append(')');
    String s = sb.toString();
    WhereClause whereClause = analyzeSelectWhere(s);
    assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, new ArrayType(DataTypes.INTEGER))));
}
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)

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