Search in sources :

Example 11 with MultipleElementSymbol

use of org.teiid.query.sql.symbol.MultipleElementSymbol in project teiid by teiid.

the class TestLimitParsing method testOffsetFetch.

@Test
public void testOffsetFetch() {
    Query query = new Query();
    Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
    // $NON-NLS-1$
    From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
    query.setSelect(select);
    query.setFrom(from);
    query.setLimit(new Limit(new Constant(2), new Constant(5)));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Select * from a offset 2 rows fetch first 5 rows only", "SELECT * FROM a LIMIT 2, 5", query);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Query(org.teiid.query.sql.lang.Query) SetQuery(org.teiid.query.sql.lang.SetQuery) UnaryFromClause(org.teiid.query.sql.lang.UnaryFromClause) Constant(org.teiid.query.sql.symbol.Constant) Select(org.teiid.query.sql.lang.Select) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) From(org.teiid.query.sql.lang.From) Limit(org.teiid.query.sql.lang.Limit) Test(org.junit.Test)

Example 12 with MultipleElementSymbol

use of org.teiid.query.sql.symbol.MultipleElementSymbol in project teiid by teiid.

the class TestOptionsAndHints method testOptionalFromClause5.

@Test
public void testOptionalFromClause5() {
    // $NON-NLS-1$
    String sql = "SELECT * FROM t1, /*+ optional */ (select * from t1, t2) as x";
    Query query = new Query();
    Select select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query.setSelect(select);
    From from = new From();
    Query query2 = new Query();
    select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query2.setSelect(select);
    From from2 = new From();
    // $NON-NLS-1$
    from2.addGroup(new GroupSymbol("t1"));
    // $NON-NLS-1$
    from2.addGroup(new GroupSymbol("t2"));
    query2.setFrom(from2);
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause("x", query2);
    sfc.setOptional(true);
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("t1"));
    from.addClause(sfc);
    query.setFrom(from);
    // $NON-NLS-1$
    TestParser.helpTest(sql, "SELECT * FROM t1, /*+ optional */ (SELECT * FROM t1, t2) AS x", query);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 13 with MultipleElementSymbol

use of org.teiid.query.sql.symbol.MultipleElementSymbol in project teiid by teiid.

the class TestOptionsAndHints method testOptionalFromClause8.

@Test
public void testOptionalFromClause8() {
    // $NON-NLS-1$
    String sql = "SELECT b FROM t1, /*+ optional */ (/*+ optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)";
    Query query = new Query();
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("b"));
    query.setSelect(select);
    From from = new From();
    Query query2 = new Query();
    select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    From from2 = new From();
    // $NON-NLS-1$
    from2.addGroup(new GroupSymbol("t1"));
    // $NON-NLS-1$
    from2.addGroup(new GroupSymbol("t2"));
    query2.setSelect(select);
    query2.setFrom(from2);
    // $NON-NLS-1$
    SubqueryFromClause sfc = new SubqueryFromClause("x", query2);
    sfc.setOptional(true);
    UnaryFromClause ufc2 = new UnaryFromClause();
    // $NON-NLS-1$
    ufc2.setGroup(new GroupSymbol("t3"));
    List<Object> criteria = new ArrayList<Object>();
    // $NON-NLS-1$//$NON-NLS-2$
    criteria.add(new CompareCriteria(new ElementSymbol("x.a"), AbstractCompareCriteria.EQ, new ElementSymbol("t3.a")));
    JoinPredicate joinPredicate = new JoinPredicate(sfc, ufc2, JoinType.JOIN_INNER, criteria);
    joinPredicate.setOptional(true);
    UnaryFromClause ufc3 = new UnaryFromClause();
    // $NON-NLS-1$
    ufc3.setGroup(new GroupSymbol("t1"));
    from.addClause(ufc3);
    from.addClause(joinPredicate);
    query.setFrom(from);
    // $NON-NLS-1$
    TestParser.helpTest(sql, "SELECT b FROM t1, /*+ optional */ (/*+ optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)", query);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) ArrayList(java.util.ArrayList) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 14 with MultipleElementSymbol

use of org.teiid.query.sql.symbol.MultipleElementSymbol in project teiid by teiid.

the class TestOptionsAndHints method testCacheHintUnion.

@Test
public void testCacheHintUnion() {
    // $NON-NLS-1$
    String sql = "/*+ cache( pref_mem) */ SELECT * FROM t1 union select * from t2";
    Query query = new Query();
    Select select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query.setSelect(select);
    From from = new From();
    UnaryFromClause ufc = new UnaryFromClause();
    from.addClause(ufc);
    // $NON-NLS-1$
    ufc.setGroup(new GroupSymbol("t1"));
    query.setFrom(from);
    Query query1 = new Query();
    select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query1.setSelect(select);
    from = new From();
    ufc = new UnaryFromClause();
    from.addClause(ufc);
    // $NON-NLS-1$
    ufc.setGroup(new GroupSymbol("t2"));
    query1.setFrom(from);
    SetQuery sq = new SetQuery(Operation.UNION, false, query, query1);
    CacheHint hint = new CacheHint();
    hint.setPrefersMemory(true);
    sq.setCacheHint(hint);
    // $NON-NLS-1$
    TestParser.helpTest(sql, "/*+ cache(pref_mem) */ SELECT * FROM t1 UNION SELECT * FROM t2", sq);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 15 with MultipleElementSymbol

use of org.teiid.query.sql.symbol.MultipleElementSymbol in project teiid by teiid.

the class TestOptionsAndHints method testOptionalFromClause1_4.

@Test
public void testOptionalFromClause1_4() {
    // $NON-NLS-1$
    String sql = "SELECT * /*+ optional */ FROM /*+ OptiOnal  */ t1, t2";
    Query query = new Query();
    Select select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    query.setSelect(select);
    From from = new From();
    UnaryFromClause ufc = new UnaryFromClause();
    // $NON-NLS-1$
    ufc.setGroup(new GroupSymbol("t1"));
    ufc.setOptional(true);
    from.addClause(ufc);
    // $NON-NLS-1$
    from.addGroup(new GroupSymbol("t2"));
    query.setFrom(from);
    // $NON-NLS-1$
    TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query);
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Aggregations

MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)29 Test (org.junit.Test)27 Select (org.teiid.query.sql.lang.Select)19 Query (org.teiid.query.sql.lang.Query)14 From (org.teiid.query.sql.lang.From)12 SetQuery (org.teiid.query.sql.lang.SetQuery)11 ArrayList (java.util.ArrayList)10 Limit (org.teiid.query.sql.lang.Limit)10 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)10 Constant (org.teiid.query.sql.symbol.Constant)7 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)7 Reference (org.teiid.query.sql.symbol.Reference)5 List (java.util.List)3 Expression (org.teiid.query.sql.symbol.Expression)2 Collection (java.util.Collection)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 MultiSourceElement (org.teiid.dqp.internal.process.multisource.MultiSourceElement)1 TempMetadataID (org.teiid.query.metadata.TempMetadataID)1 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)1