use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestJoinNode method helpCreateJoin.
protected void helpCreateJoin() {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("e2");
es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List leftElements = new ArrayList();
leftElements.add(es1);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
List rightElements = new ArrayList();
rightElements.add(es2);
rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
@Override
public boolean hasBuffer() {
return false;
}
@Override
public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
fail();
throw new AssertionError();
}
};
rightNode.setElements(rightElements);
List joinElements = new ArrayList();
joinElements.add(es1);
joinElements.add(es2);
join = new JoinNode(3);
joinStrategy = new NestedLoopJoinStrategy();
join.setJoinStrategy(joinStrategy);
join.setElements(joinElements);
join.setJoinType(joinType);
switch(criteriaType) {
case NO_CRITERIA:
break;
case EQUAL_CRITERIA:
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es2));
joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
join.setJoinStrategy(joinStrategy);
break;
case FUNCTION_CRITERIA:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
// $NON-NLS-1$
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
CompareCriteria joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
join.setJoinCriteria(joinCriteria);
break;
}
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestLimitNode method getLimitNode.
private static LimitNode getLimitNode(int limit, RelationalNode child) throws Exception {
LimitNode node = new LimitNode(1, new Constant(new Integer(limit)), new Constant(new Integer(0)));
node.addChild(child);
node.open();
return node;
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestLimitNode method testClone.
@Test
public void testClone() {
LimitNode node = new LimitNode(1, new Constant(new Integer(-1)), null);
LimitNode clone = (LimitNode) node.clone();
assertEquals(node.getLimitExpr(), clone.getLimitExpr());
assertNull(clone.getOffsetExpr());
node = new LimitNode(1, null, new Constant(new Integer(-1)));
clone = (LimitNode) node.clone();
assertNull(clone.getLimitExpr());
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestFunctionResolving method testResolveConvertReference.
@Test
public void testResolveConvertReference() throws Exception {
// $NON-NLS-1$
Function function = new Function("convert", new Expression[] { new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN) });
ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
}
use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.
the class TestProcedureResolving method testVarArgs.
@Test
public void testVarArgs() throws Exception {
String ddl = "create foreign procedure proc (x integer, VARIADIC z integer) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc (1, 2, 3)";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, 2, 3)", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
// $NON-NLS-1$
sql = "call proc (1)";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1)", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(2).getExpression());
sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
Call call = (Call) lbf.translate(sp);
assertEquals("EXEC proc(1)", call.toString());
// $NON-NLS-1$
sql = "call proc (1, (2, 3))";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, (2, 3))", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
}
Aggregations