Search in sources :

Example 46 with WhereClause

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

the class WhereClauseAnalyzerTest method testGenColRangeOptimization.

@Test
public void testGenColRangeOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts >= '2015-01-01T12:00:00' and ts <= '2015-01-02T00:00:00'");
    assertThat(whereClause.partitions().size(), is(2));
    assertThat(whereClause.partitions().get(0), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420070400000"), new BytesRef("-1"))).asIndexName()));
    assertThat(whereClause.partitions().get(1), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420156800000"), new BytesRef("-2"))).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 47 with WhereClause

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

the class WhereClauseAnalyzerTest method test1ColPrimaryKeyNotSetLiteral.

@Test
public void test1ColPrimaryKeyNotSetLiteral() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users where id not in ('jalla', 'kelle')");
    assertFalse(whereClause.noMatch());
    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 48 with WhereClause

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

the class WhereClauseAnalyzerTest method testInNormalizedToAnyWithScalars.

@Test
public void testInNormalizedToAnyWithScalars() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from users where id in (null, 1+2, 3+4, abs(-99))");
    assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME));
    assertThat(whereClause.docKeys().isPresent(), is(true));
    assertThat(whereClause.docKeys().get(), containsInAnyOrder(isNullDocKey(), isDocKey("3"), isDocKey("7"), isDocKey("99")));
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 49 with WhereClause

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

the class WhereClauseAnalyzerTest method test1ColPrimaryKeySetLiteralDiffMatches.

@Test
public void test1ColPrimaryKeySetLiteralDiffMatches() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users where id in ('jalla', 'kelle') and id in ('jalla', 'something')");
    assertFalse(whereClause.noMatch());
    assertThat(whereClause.docKeys().get(), contains(isDocKey("jalla")));
}
Also used : WhereClause(io.crate.analyze.WhereClause) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 50 with WhereClause

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

the class WhereClauseAnalyzerTest method testEmptyClusteredByValue.

@Test
public void testEmptyClusteredByValue() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from bystring where name = ''");
    assertThat(whereClause.clusteredBy().get(), contains(isLiteral("")));
    assertThat(whereClause.docKeys().get().getOnlyKey(), isDocKey(""));
}
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