Search in sources :

Example 21 with Select

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

the class TestLimitParsing method testLimitWithReferences2.

@Test
public void testLimitWithReferences2() {
    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(new Integer(50)), new Reference(0)));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Select * from a limit 50,?", "SELECT * FROM a LIMIT 50, ?", 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) Reference(org.teiid.query.sql.symbol.Reference) 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 22 with Select

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

the class TestLimitParsing method testFetchFirstRow.

@Test
public void testFetchFirstRow() {
    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(null, new Constant(1)));
    // $NON-NLS-1$ //$NON-NLS-2$
    helpTest("Select * from a fetch first row only", "SELECT * FROM a LIMIT 1", 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 23 with Select

use of org.teiid.query.sql.lang.Select 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 24 with Select

use of org.teiid.query.sql.lang.Select 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 25 with Select

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

the class TestSetQueryParsing method createTestQuery.

private Query createTestQuery(String group) {
    GroupSymbol g = new GroupSymbol(group);
    From from = new From();
    from.addGroup(g);
    Select select = new Select();
    select.addSymbol(new MultipleElementSymbol());
    Query query1 = new Query();
    query1.setSelect(select);
    query1.setFrom(from);
    return query1;
}
Also used : MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) 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)

Aggregations

Select (org.teiid.query.sql.lang.Select)50 Query (org.teiid.query.sql.lang.Query)30 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)26 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)26 From (org.teiid.query.sql.lang.From)25 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)24 Test (org.junit.Test)17 SetQuery (org.teiid.query.sql.lang.SetQuery)17 Constant (org.teiid.query.sql.symbol.Constant)15 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)11 Limit (org.teiid.query.sql.lang.Limit)10 ArrayList (java.util.ArrayList)5 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)5 Reference (org.teiid.query.sql.symbol.Reference)5 Element (org.jdom.Element)4 Expression (org.teiid.query.sql.symbol.Expression)4 List (java.util.List)3 Attribute (org.jdom.Attribute)3 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)3 LanguageObject (org.teiid.query.sql.LanguageObject)3