Search in sources :

Example 71 with WhereClause

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

the class WhereClauseAnalyzerTest method testOptimizationNonRoundingFunctionGreater.

@Test
public void testOptimizationNonRoundingFunctionGreater() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from double_gen_parted where x > 3");
    assertThat(whereClause.query(), isSQL("(doc.double_gen_parted.x > 3)"));
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(".partitioned.double_gen_parted.0813a0hm"));
}
Also used : WhereClause(io.crate.analyze.WhereClause) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 72 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'");
    RelationName relationName = new RelationName("doc", "generated_col");
    assertThat(whereClause.partitions(), containsInAnyOrder(new PartitionName(relationName, Arrays.asList("1420070400000", "-1")).asIndexName(), new PartitionName(relationName, Arrays.asList("1420156800000", "-2")).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 73 with WhereClause

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

the class WhereClauseAnalyzerTest method test_where_on_date_with_null_partition_or_id_can_match_all_partitions.

@Test
public void test_where_on_date_with_null_partition_or_id_can_match_all_partitions() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select id, name from parted where date = 1395961200000::timestamp or id = 1");
    assertThat(whereClause.partitions(), containsInAnyOrder(".partitioned.parted.0400", ".partitioned.parted.04732cpp6ksjcc9i60o30c1g", ".partitioned.parted.04732cpp6ks3ed1o60o30c1g"));
    assertThat(whereClause.queryOrFallback(), isSQL("((doc.parted.date = 1395961200000::bigint) OR (doc.parted.id = 1))"));
}
Also used : WhereClause(io.crate.analyze.WhereClause) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 74 with WhereClause

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

the class WhereClauseAnalyzerTest method testAnyILikeArrayLiteral.

@Test
public void testAnyILikeArrayLiteral() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from users where name ilike any(['a', 'b', 'c'])");
    assertThat(whereClause.query(), isFunction(LikeOperators.ANY_ILIKE, List.of(DataTypes.STRING, new ArrayType<>(DataTypes.STRING))));
}
Also used : WhereClause(io.crate.analyze.WhereClause) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 75 with WhereClause

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

the class WhereClauseAnalyzerTest method testGtGenColOptimization.

@Test
public void testGtGenColOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts > '2015-01-02T12:00:00'");
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(new PartitionName(new RelationName("doc", "generated_col"), Arrays.asList("1420156800000", "-2")).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

WhereClause (io.crate.analyze.WhereClause)79 Test (org.junit.Test)55 CrateUnitTest (io.crate.test.integration.CrateUnitTest)30 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)20 Symbol (io.crate.analyze.symbol.Symbol)10 PartitionName (io.crate.metadata.PartitionName)8 RelationName (io.crate.metadata.RelationName)8 TableInfo (io.crate.metadata.table.TableInfo)7 Reference (io.crate.metadata.Reference)6 DocTableRelation (io.crate.analyze.relations.DocTableRelation)5 Symbol (io.crate.expression.symbol.Symbol)5 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 SqlExpressions (io.crate.testing.SqlExpressions)5 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)4 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 ImmutableList (com.google.common.collect.ImmutableList)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3