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)"));
}
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"));
}
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")));
}
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"));
}
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"));
}
Aggregations