Search in sources :

Example 11 with WhereClause

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

the class WhereClauseAnalyzerTest method testNonPartitionedNotOptimized.

@Test
public void testNonPartitionedNotOptimized() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where x = 1");
    assertThat(whereClause.query(), isSQL("(doc.generated_col.x = 1)"));
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with WhereClause

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

the class WhereClauseAnalyzerTest method test4ColPrimaryKey.

@Test
public void test4ColPrimaryKey() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from pk4 where i1=10 and i2=20 and i3=30 and i4=40");
    assertThat(whereClause.docKeys().get(), contains(isDocKey(10, 20, 30, 40)));
    assertFalse(whereClause.noMatch());
    whereClause = analyzeSelectWhere("select * from pk4 where i1=10 and i2=20 and i3=30 and i4=40 and i1=10");
    assertThat(whereClause.docKeys().get(), contains(isDocKey(10, 20, 30, 40)));
    assertFalse(whereClause.noMatch());
    whereClause = analyzeSelectWhere("select * from pk4 where i1=1");
    assertFalse(whereClause.docKeys().isPresent());
    assertFalse(whereClause.noMatch());
    whereClause = analyzeSelectWhere("select * from pk4 where i1=10 and i2=20 and i3=30 and i4=40 and i1=11");
    assertFalse(whereClause.docKeys().isPresent());
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with WhereClause

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

the class WhereClauseAnalyzerTest method testCompositePrimaryKey.

@Test
public void testCompositePrimaryKey() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users_multi_pk where id=1");
    assertFalse(whereClause.docKeys().isPresent());
    assertThat(whereClause.clusteredBy().get(), contains(isLiteral(1L)));
    whereClause = analyzeSelectWhere("select name from users_multi_pk where id=1 and name='Douglas'");
    assertThat(whereClause.docKeys().get(), contains(isDocKey(1L, "Douglas")));
    assertThat(whereClause.clusteredBy().get(), contains(isLiteral(1L)));
    whereClause = analyzeSelectWhere("select name from users_multi_pk where id=1 or id=2 and name='Douglas'");
    assertFalse(whereClause.docKeys().isPresent());
    assertThat(whereClause.clusteredBy().get(), containsInAnyOrder(isLiteral(1L), isLiteral(2L)));
    whereClause = analyzeSelectWhere("select name from users_multi_pk where id=1 and name='Douglas' or name='Arthur'");
    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 14 with WhereClause

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

the class WhereClauseAnalyzerTest method testMultiplePrimaryKeys.

@Test
public void testMultiplePrimaryKeys() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users where id = 2 or id = 1");
    assertThat(whereClause.docKeys().get(), containsInAnyOrder(isDocKey("1"), isDocKey("2")));
    assertThat(whereClause.clusteredBy().get(), containsInAnyOrder(isLiteral("1"), isLiteral("2")));
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with WhereClause

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

the class WhereClauseAnalyzerTest method testSelectByIdWithPartitions.

@Test
public void testSelectByIdWithPartitions() throws Exception {
    WhereClause whereClause = analyzeSelect("select id from parted where _id=1");
    assertFalse(whereClause.docKeys().isPresent());
}
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