Search in sources :

Example 16 with WhereClause

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

the class WhereClauseAnalyzerTest method testMultipleCompoundPrimaryKeys.

@Test
public void testMultipleCompoundPrimaryKeys() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from pk4 where (i1=1 and i2=2 and i3=3 and i4=4) " + "or (i1=1 and i2=5 and i3=6 and i4=4)");
    assertThat(whereClause.docKeys().get(), containsInAnyOrder(isDocKey(1, 2, 3, 4), isDocKey(1, 5, 6, 4)));
    assertFalse(whereClause.clusteredBy().isPresent());
    whereClause = analyzeSelectWhere("select * from pk4 where (i1=1 and i2=2 and i3=3 and i4=4) " + "or (i1=1 and i2=5 and i3=6 and i4=4) or i1 = 3");
    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 17 with WhereClause

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

the class WhereClauseAnalyzerTest method testAnyLikeConvertableArrayTypeLiterals.

@Test
public void testAnyLikeConvertableArrayTypeLiterals() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from users where name like any([1, 2, 3])");
    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 18 with WhereClause

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

the class WhereClauseAnalyzerTest method testClusteredBy.

@Test
public void testClusteredBy() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select name from users where id=1");
    assertThat(whereClause.clusteredBy().get(), contains(isLiteral("1")));
    assertThat(whereClause.docKeys().get().getOnlyKey(), isDocKey("1"));
    whereClause = analyzeSelectWhere("select name from users where id=1 or id=2");
    assertThat(whereClause.docKeys().get().size(), is(2));
    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 19 with WhereClause

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

the class WhereClauseAnalyzerTest method testGenColRoundingFunctionNoSwappingOperatorOptimization.

@Test
public void testGenColRoundingFunctionNoSwappingOperatorOptimization() 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("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 20 with WhereClause

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

the class WhereClauseAnalyzerTest method testColumnReferencedTwiceInGeneratedColumnPartitioned.

@Test
public void testColumnReferencedTwiceInGeneratedColumnPartitioned() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from double_gen_parted where x = 4");
    assertThat(whereClause.query(), isSQL("(doc.double_gen_parted.x = 4)"));
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(".partitioned.double_gen_parted.0813a0hm"));
}
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