Search in sources :

Example 6 with SetQuery

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

the class TestSetQueryParsing method testUnionAll.

/**
 * SELECT a FROM g UNION ALL select b from h
 */
@Test
public void testUnionAll() {
    // $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(Operation.UNION);
    setQuery.setAll(true);
    setQuery.setLeftQuery(query1);
    setQuery.setRightQuery(query2);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "SELECT a FROM g UNION ALL select b from h", // $NON-NLS-1$
    "SELECT a FROM g UNION ALL SELECT b FROM h", 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 7 with SetQuery

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

the class TestSetQueryParsing method testUnion.

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

Example 8 with SetQuery

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

the class TestSetQueryParsing method testMultipleValues.

@Test
public void testMultipleValues() {
    SetQuery setQuery = new SetQuery(Operation.UNION);
    setQuery.setAll(true);
    Select select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c1"));
    Query query = new Query();
    query.setSelect(select);
    setQuery.setLeftQuery(query);
    select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c2"));
    query = new Query();
    query.setSelect(select);
    setQuery.setRightQuery(query);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "values (c1), (c2)", // $NON-NLS-1$
    "SELECT c1 UNION ALL SELECT c2", 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) Select(org.teiid.query.sql.lang.Select) Test(org.junit.Test)

Example 9 with SetQuery

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

the class TestSetQueryParsing method testExcept.

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

Example 10 with SetQuery

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

the class TestSetQueryParsing method testThreeUnions.

/**
 * select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4
 */
@Test
public void testThreeUnions() {
    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(SetQuery.Operation.UNION, true, setQuery, query);
    // $NON-NLS-1$
    g = new GroupSymbol("g4");
    from = new From();
    from.addGroup(g);
    select = new Select();
    // $NON-NLS-1$
    select.addSymbol(new ElementSymbol("c4"));
    query = new Query();
    query.setSelect(select);
    query.setFrom(from);
    setQuery = new SetQuery(SetQuery.Operation.UNION, false, setQuery, query);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "select c1 from g1 union select c2 from g2 union all select c3 from g3 union select c4 from g4", // $NON-NLS-1$
    "SELECT c1 FROM g1 UNION SELECT c2 FROM g2 UNION ALL SELECT c3 FROM g3 UNION SELECT c4 FROM g4", 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)

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