Search in sources :

Example 1 with QuerySpec

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

the class RelationSplitterTest method testSplitQuerySpecOutputsOnly.

@Test
public void testSplitQuerySpecOutputsOnly() throws Exception {
    QuerySpec querySpec = new QuerySpec().outputs(Arrays.asList(asSymbol("x"), asSymbol("y")));
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT doc.t1.x, doc.t2.y"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y"));
    assertThat(splitter.canBeFetched(), containsInAnyOrder(isField("x"), isField("y")));
    querySpec.limit(Optional.of(Literal.of(10)));
    splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT doc.t1.x, doc.t2.y LIMIT 10"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x LIMIT 10"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y LIMIT 10"));
    querySpec.offset(Optional.of(Literal.of(10)));
    splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT doc.t1.x, doc.t2.y LIMIT 10 OFFSET 10"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x LIMIT add(10, 10)"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y LIMIT add(10, 10)"));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with QuerySpec

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

the class RelationSplitterTest method testQuerySpecSplitNoRelationQuery.

@Test
public void testQuerySpecSplitNoRelationQuery() throws Exception {
    QuerySpec querySpec = fromQuery("x + y + z = 5").limit(Optional.of(Literal.of(30)));
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT true WHERE (add(add(doc.t1.x, doc.t2.y), doc.t3.z) = 5) LIMIT 30"));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y"));
    assertThat(splitter.getSpec(T3.TR_3), isSQL("SELECT doc.t3.z"));
}
Also used : QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with QuerySpec

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

the class RelationSplitterTest method testOnlyDocTablesCanBeFetched.

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

Example 4 with QuerySpec

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

the class RelationSplitterTest method testSplitOrderByWith3RelationsButOutputsOnly2Relations.

@Test
public void testSplitOrderByWith3RelationsButOutputsOnly2Relations() throws Exception {
    QuerySpec querySpec = fromQuery("x = 1 and y = 2 and z = 3").limit(Optional.of(Literal.of(30)));
    List<Symbol> orderBySymbols = Arrays.asList(asSymbol("x"), asSymbol("y"), asSymbol("z"));
    OrderBy orderBy = new OrderBy(orderBySymbols, new boolean[] { false, false, false }, new Boolean[] { null, null, null });
    querySpec.orderBy(orderBy).limit(Optional.of((Symbol) Literal.of(20))).outputs(Arrays.asList(asSymbol("x"), asSymbol("y")));
    RelationSplitter splitter = split(querySpec);
    assertThat(querySpec, isSQL("SELECT doc.t1.x, doc.t2.y ORDER BY doc.t1.x, doc.t2.y, doc.t3.z LIMIT 20"));
    assertThat(splitter.remainingOrderBy().isPresent(), is(false));
    assertThat(splitter.getSpec(T3.TR_1), isSQL("SELECT doc.t1.x WHERE (doc.t1.x = 1) ORDER BY doc.t1.x LIMIT 20"));
    assertThat(splitter.getSpec(T3.TR_2), isSQL("SELECT doc.t2.y WHERE (true AND (doc.t2.y = 2)) ORDER BY doc.t2.y LIMIT 20"));
    assertThat(splitter.getSpec(T3.TR_3), isSQL("SELECT doc.t3.z WHERE (true AND (doc.t3.z = 3)) ORDER BY doc.t3.z LIMIT 20"));
}
Also used : OrderBy(io.crate.analyze.OrderBy) Symbol(io.crate.analyze.symbol.Symbol) QuerySpec(io.crate.analyze.QuerySpec) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with QuerySpec

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

the class RelationSplitterTest method testWhereClauseSplitWithMatchFunction.

@Test
public void testWhereClauseSplitWithMatchFunction() throws Exception {
    QuerySpec querySpec = fromQuery("match (a, 'search term') and b=1");
    RelationSplitter splitter = split(querySpec);
    QuerySpec splitQuerySpec = splitter.getSpec(T3.TR_1);
    assertThat(querySpec.where().hasQuery(), is(false));
    assertThat(splitQuerySpec.where().query(), instanceOf(io.crate.analyze.symbol.MatchPredicate.class));
    splitQuerySpec = splitter.getSpec(T3.TR_2);
    assertThat(splitQuerySpec.where().query(), isFunction("op_and"));
}
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