Search in sources :

Example 6 with MultiSourceSelect

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

the class RelationNormalizerTest method testSubSelectOnJoinsWithFilter.

@Test
public void testSubSelectOnJoinsWithFilter() throws Exception {
    QueriedRelation relation = normalize("select col1, col2 from ( " + "  select t1.a as col1, t2.i as col2, t2.y as col3 " + "  from t1, t2 where t2.y > 60) as t " + "where col1 = 'a' order by col3");
    assertThat(relation, instanceOf(MultiSourceSelect.class));
    assertThat(relation.querySpec(), isSQL("SELECT doc.t1.a, doc.t2.i ORDER BY doc.t2.y"));
    // make sure that where clause was pushed down and didn't disappear somehow
    RelationSource t1 = ((MultiSourceSelect) relation).sources().get(T3.T1);
    assertThat(t1.querySpec().where().query(), isSQL("(doc.t1.a = 'a')"));
    RelationSource t2 = ((MultiSourceSelect) relation).sources().get(T3.T2);
    assertThat(t2.querySpec().where().query(), isSQL("(true AND (doc.t2.y > 60))"));
}
Also used : RelationSource(io.crate.analyze.RelationSource) MultiSourceSelect(io.crate.analyze.MultiSourceSelect) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with MultiSourceSelect

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

the class RelationNormalizerTest method testSubSelectOnRightJoinWithFilterRewrittenToInner.

@Test
public void testSubSelectOnRightJoinWithFilterRewrittenToInner() throws Exception {
    QueriedRelation relation = normalize("select col1, col2 from ( " + "  select t1.a as col1, t2.i as col2, t2.y as col3 " + "  from t1 right join t2 on t1.a = t2.b where t1.x > 60) as t " + "where col2 = 10 order by col3");
    assertThat(relation, instanceOf(MultiSourceSelect.class));
    MultiSourceSelect mss = (MultiSourceSelect) relation;
    assertThat(mss.querySpec(), isSQL("SELECT doc.t1.a, doc.t2.i ORDER BY doc.t2.y"));
    assertThat(mss.joinPairs().get(0).joinType(), is(JoinType.INNER));
    assertThat(mss.joinPairs().get(0).condition(), isSQL("(doc.t1.a = doc.t2.b)"));
    // make sure that where clause was pushed down and didn't disappear somehow
    RelationSource t1 = mss.sources().get(T3.T1);
    assertThat(t1.querySpec().where().query(), isSQL("(doc.t1.x > 60)"));
    RelationSource t2 = mss.sources().get(T3.T2);
    assertThat(t2.querySpec().where().query(), isSQL("(doc.t2.i = 10)"));
}
Also used : RelationSource(io.crate.analyze.RelationSource) MultiSourceSelect(io.crate.analyze.MultiSourceSelect) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with MultiSourceSelect

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

the class MultiSourceFetchPushDownTest method pushDown.

private void pushDown(String stmt) {
    SelectAnalyzedStatement a = e.analyze(stmt);
    assertThat(a.relation(), instanceOf(MultiSourceSelect.class));
    mss = (MultiSourceSelect) a.relation();
    pd = new MultiSourceFetchPushDown(mss);
    pd.process();
}
Also used : MultiSourceSelect(io.crate.analyze.MultiSourceSelect) SelectAnalyzedStatement(io.crate.analyze.SelectAnalyzedStatement)

Aggregations

MultiSourceSelect (io.crate.analyze.MultiSourceSelect)8 RelationSource (io.crate.analyze.RelationSource)7 CrateUnitTest (io.crate.test.integration.CrateUnitTest)7 Test (org.junit.Test)7 SelectAnalyzedStatement (io.crate.analyze.SelectAnalyzedStatement)1