Search in sources :

Example 6 with QuerySpec

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

the class RelationSplitterTest method testSplitNotMultiRelation.

@Test
public void testSplitNotMultiRelation() throws Exception {
    QuerySpec querySpec = fromQuery("not (a = 1 and x = 2) and b = 2");
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT true"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT  WHERE (NOT ((doc.t1.a = '1') AND (doc.t1.x = 2)))"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT  WHERE (true AND (doc.t2.b = '2'))"));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with QuerySpec

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

the class RelationSplitterTest method testSplitOfSingleRelationTree.

@Test
public void testSplitOfSingleRelationTree() throws Exception {
    QuerySpec querySpec = fromQuery("t1.a = t2.b and t1.a = 'employees'");
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT true WHERE ((doc.t1.a = doc.t2.b) AND true)"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.a WHERE (doc.t1.a = 'employees')"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.b"));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with QuerySpec

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

the class RelationSplitterTest method testSplitNotMultiRelationInside.

@Test
public void testSplitNotMultiRelationInside() throws Exception {
    QuerySpec querySpec = fromQuery("not (a = 1 and b = 2)");
    assertThat(querySpec, isSQL("SELECT true WHERE (NOT ((doc.t1.a = '1') AND (doc.t2.b = '2')))"));
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT true WHERE (NOT ((doc.t1.a = '1') AND (doc.t2.b = '2')))"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.a"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.b"));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with QuerySpec

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

the class RelationSplitterTest method testScoreCannotBeFetchd.

@Test
public void testScoreCannotBeFetchd() throws Exception {
    QuerySpec querySpec = new QuerySpec().outputs(Arrays.asList(asSymbol("t1._score"), asSymbol("a")));
    RelationSplitter splitter = split(querySpec);
    assertThat(splitter.canBeFetched(), containsInAnyOrder(asSymbol("a")));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with QuerySpec

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

the class RelationSplitterTest method testMatchWithColumnsFrom2Relations.

@Test
public void testMatchWithColumnsFrom2Relations() throws Exception {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Must not use columns from more than 1 relation inside the MATCH predicate");
    QuerySpec querySpec = fromQuery("match ((a, b), 'search term')");
    split(querySpec);
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

QuerySpec (io.crate.analyze.QuerySpec)31 Test (org.junit.Test)25 CrateUnitTest (io.crate.test.integration.CrateUnitTest)15 OrderBy (io.crate.analyze.OrderBy)13 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)11 Symbol (io.crate.analyze.symbol.Symbol)4 Function (io.crate.analyze.symbol.Function)3 AbsFunction (io.crate.operation.scalar.arithmetic.AbsFunction)2 Nullable (javax.annotation.Nullable)2 SessionContext (io.crate.action.sql.SessionContext)1 EvaluatingNormalizer (io.crate.analyze.EvaluatingNormalizer)1 RelationSource (io.crate.analyze.RelationSource)1 QueriedRelation (io.crate.analyze.relations.QueriedRelation)1 Field (io.crate.analyze.symbol.Field)1 SelectSymbol (io.crate.analyze.symbol.SelectSymbol)1 DocKeys (io.crate.analyze.where.DocKeys)1 ValidationException (io.crate.exceptions.ValidationException)1 VersionInvalidException (io.crate.exceptions.VersionInvalidException)1 Reference (io.crate.metadata.Reference)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1