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);
}
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);
}
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());
}
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());
}
}
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());
}
Aggregations