Search in sources :

Example 31 with Reference

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

the class TestLimitParsing method testLimitWithReferences1.

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

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

the class TestOptionsAndHints method testInsertWithOption.

@Test
public void testInsertWithOption() {
    Insert insert = new Insert();
    // $NON-NLS-1$
    insert.setGroup(new GroupSymbol("m.g"));
    List<ElementSymbol> vars = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    vars.add(new ElementSymbol("a"));
    insert.setVariables(vars);
    List<Reference> values = new ArrayList<Reference>();
    values.add(new Reference(0));
    insert.setValues(values);
    Option option = new Option();
    option.setNoCache(true);
    insert.setOption(option);
    // $NON-NLS-1$
    TestParser.helpTest(// $NON-NLS-1$
    "INSERT INTO m.g (a) VALUES (?) OPTION NOCACHE", // $NON-NLS-1$
    "INSERT INTO m.g (a) VALUES (?) OPTION NOCACHE", insert);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MultipleElementSymbol(org.teiid.query.sql.symbol.MultipleElementSymbol) Reference(org.teiid.query.sql.symbol.Reference) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 33 with Reference

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

the class TestDependentCriteriaProcessor method testEvaluatedSetCriteria.

@Test
public void testEvaluatedSetCriteria() throws Exception {
    DependentAccessNode dan = new DependentAccessNode(0);
    CommandContext cc = new CommandContext();
    dan.setContext(cc);
    List<Reference> references = Arrays.asList(new Reference(1), new Reference(2));
    for (Reference reference : references) {
        cc.getVariableContext().setGlobalValue(reference.getContextSymbol(), 1);
    }
    // $NON-NLS-1$
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), references);
    sc.setAllConstants(true);
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    // $NON-NLS-1$
    assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result);
    assertFalse(dcp.hasNextCommand());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Test(org.junit.Test)

Example 34 with Reference

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

the class TestFunctionResolving method testResolveAmbiguousFunction.

@Test
public void testResolveAmbiguousFunction() throws Exception {
    // $NON-NLS-1$
    Function function = new Function("LCASE", new Expression[] { new Reference(0) });
    try {
        ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
        // $NON-NLS-1$
        fail("excpetion expected");
    } catch (QueryResolverException err) {
        // $NON-NLS-1$
        assertEquals("TEIID30069 The function 'LCASE(?)' has more than one possible signature.", err.getMessage());
    }
}
Also used : Function(org.teiid.query.sql.symbol.Function) Reference(org.teiid.query.sql.symbol.Reference) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) Test(org.junit.Test)

Example 35 with Reference

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

the class TestQueryRewriter method testRewriteCorrelatedSubqueryInHaving.

@Test
public void testRewriteCorrelatedSubqueryInHaving() throws Exception {
    // $NON-NLS-1$
    String sql = "select pm1.g1.e1 from pm1.g1 group by pm1.g1.e1 having pm1.g1.e1 in (select pm1.g1.e1 from pm1.g2)";
    // $NON-NLS-1$
    String expected = "SELECT pm1.g1.e1 FROM pm1.g1 GROUP BY pm1.g1.e1 HAVING pm1.g1.e1 IN (SELECT pm1.g1.e1 FROM pm1.g2)";
    Query query = (Query) helpTestRewriteCommand(sql, expected);
    List<Reference> refs = new LinkedList<Reference>();
    GroupSymbol gs = new GroupSymbol("pm1.g1");
    ResolverUtil.resolveGroup(gs, RealMetadataFactory.example1Cached());
    // $NON-NLS-1$
    CorrelatedReferenceCollectorVisitor.collectReferences(query.getHaving(), Arrays.asList(gs), refs, RealMetadataFactory.example1Cached());
    assertEquals(1, refs.size());
}
Also used : Reference(org.teiid.query.sql.symbol.Reference) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Reference (org.teiid.query.sql.symbol.Reference)42 Test (org.junit.Test)15 Constant (org.teiid.query.sql.symbol.Constant)14 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)14 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)12 Expression (org.teiid.query.sql.symbol.Expression)11 Limit (org.teiid.query.sql.lang.Limit)7 Query (org.teiid.query.sql.lang.Query)7 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)7 ArrayList (java.util.ArrayList)6 Criteria (org.teiid.query.sql.lang.Criteria)6 LinkedList (java.util.LinkedList)5 From (org.teiid.query.sql.lang.From)5 Select (org.teiid.query.sql.lang.Select)5 SetQuery (org.teiid.query.sql.lang.SetQuery)5 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)5 UnaryFromClause (org.teiid.query.sql.lang.UnaryFromClause)5 Column (org.teiid.metadata.Column)4 Command (org.teiid.query.sql.lang.Command)4 SPParameter (org.teiid.query.sql.lang.SPParameter)4