Search in sources :

Example 21 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class TestSetQueryParsing method exampleSetQuery.

private SetQuery exampleSetQuery(Operation op) {
    // $NON-NLS-1$
    GroupSymbol g = new GroupSymbol("g");
    From from = new From();
    from.addGroup(g);
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("a"));
    Query query1 = new Query();
    query1.setSelect(select);
    query1.setFrom(from);
    // $NON-NLS-1$
    g = new GroupSymbol("h");
    from = new From();
    from.addGroup(g);
    select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("b"));
    Query query2 = new Query();
    query2.setSelect(select);
    query2.setFrom(from);
    SetQuery setQuery = new SetQuery(op);
    setQuery.setAll(false);
    setQuery.setLeftQuery(query1);
    setQuery.setRightQuery(query2);
    return setQuery;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) SetQuery(org.teiid.query.sql.lang.SetQuery) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Select(org.teiid.query.sql.lang.Select) From(org.teiid.query.sql.lang.From)

Example 22 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class TestSetQueryParsing method testIntersectPresedence.

@Test
public void testIntersectPresedence() {
    // $NON-NLS-1$  //$NON-NLS-2$
    SetQuery setQuery = new SetQuery(Operation.INTERSECT, false, createTestQuery("t2"), createTestQuery("t3"));
    // $NON-NLS-1$
    setQuery = new SetQuery(Operation.EXCEPT, false, createTestQuery("t1"), setQuery);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "select * from t1 EXCEPT select * from t2 INTERSECT select * from t3", // $NON-NLS-1$
    "SELECT * FROM t1 EXCEPT (SELECT * FROM t2 INTERSECT SELECT * FROM t3)", setQuery);
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) Test(org.junit.Test)

Example 23 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class TestSetQueryParsing method testTwoUnions.

/**
 * select c1 from g1 union select c2 from g2 union select c3 from g3
 */
@Test
public void testTwoUnions() {
    SetQuery setQuery = new SetQuery(Operation.UNION);
    setQuery.setAll(false);
    // $NON-NLS-1$
    GroupSymbol g = new GroupSymbol("g1");
    From from = new From();
    from.addGroup(g);
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c1"));
    Query query = new Query();
    query.setSelect(select);
    query.setFrom(from);
    setQuery.setLeftQuery(query);
    // $NON-NLS-1$
    g = new GroupSymbol("g2");
    from = new From();
    from.addGroup(g);
    select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c2"));
    query = new Query();
    query.setSelect(select);
    query.setFrom(from);
    setQuery.setRightQuery(query);
    // $NON-NLS-1$
    g = new GroupSymbol("g3");
    from = new From();
    from.addGroup(g);
    select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c3"));
    query = new Query();
    query.setSelect(select);
    query.setFrom(from);
    setQuery = new SetQuery(Operation.UNION, false, setQuery, query);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "select c1 from g1 union select c2 from g2 union select c3 from g3", // $NON-NLS-1$
    "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION SELECT c3 FROM g3", setQuery);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) SetQuery(org.teiid.query.sql.lang.SetQuery) Query(org.teiid.query.sql.lang.Query) SetQuery(org.teiid.query.sql.lang.SetQuery) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Select(org.teiid.query.sql.lang.Select) From(org.teiid.query.sql.lang.From) Test(org.junit.Test)

Example 24 with SetQuery

use of org.teiid.query.sql.lang.SetQuery in project teiid by teiid.

the class TestSetQueryParsing method testIntersect.

@Test
public void testIntersect() {
    SetQuery setQuery = exampleSetQuery(Operation.INTERSECT);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "SELECT a FROM g intersect select b from h", // $NON-NLS-1$
    "SELECT a FROM g INTERSECT SELECT b FROM h", setQuery);
}
Also used : SetQuery(org.teiid.query.sql.lang.SetQuery) Test(org.junit.Test)

Aggregations

SetQuery (org.teiid.query.sql.lang.SetQuery)24 Test (org.junit.Test)10 Query (org.teiid.query.sql.lang.Query)9 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 Select (org.teiid.query.sql.lang.Select)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)6 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)6 From (org.teiid.query.sql.lang.From)5 WithQueryCommand (org.teiid.query.sql.lang.WithQueryCommand)5 ArrayList (java.util.ArrayList)4 Expression (org.teiid.query.sql.symbol.Expression)4 List (java.util.List)3 Constant (org.teiid.query.sql.symbol.Constant)3 Insert (org.teiid.query.sql.lang.Insert)2 Limit (org.teiid.query.sql.lang.Limit)2 QueryCommand (org.teiid.query.sql.lang.QueryCommand)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1