use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testReturnAndResultSet.
@Test
public void testReturnAndResultSet() throws Exception {
// $NON-NLS-1$
String ddl = "CREATE FOREIGN PROCEDURE proc (OUT param STRING RESULT) RETURNS TABLE (a INTEGER, b STRING);";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "y");
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve("exec proc()", tm);
assertEquals(2, sp.getProjectedSymbols().size());
assertEquals("y.proc.b", sp.getProjectedSymbols().get(1).toString());
assertTrue(sp.returnsResultSet());
sp.setCallableStatement(true);
assertEquals(3, sp.getProjectedSymbols().size());
assertEquals("y.proc.param", sp.getProjectedSymbols().get(2).toString());
CreateProcedureCommand cpc = (CreateProcedureCommand) TestResolver.helpResolve("begin exec proc(); end", tm);
assertEquals(2, cpc.getProjectedSymbols().size());
assertEquals(2, ((CommandStatement) cpc.getBlock().getStatements().get(0)).getCommand().getProjectedSymbols().size());
assertTrue(cpc.returnsResultSet());
TestValidator.helpValidate("begin declare string var; var = exec proc(); select var; end", new String[] { "SELECT var;" }, tm);
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestProcedureResolving method testVarArgs1.
@Test
public void testVarArgs1() throws Exception {
String ddl = "create foreign procedure proc (VARIADIC z integer) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc ()";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc()", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(1).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()", call.toString());
// we pass to the translator level flattened, so no argument
assertEquals(0, call.getArguments().size());
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestStaticSymbolMappingVisitor method testExecParamFunction.
public void testExecParamFunction() {
StoredProcedure exec = new StoredProcedure();
// $NON-NLS-1$
exec.setProcedureName("pm1.proc1");
// $NON-NLS-1$
exec.setProcedureID("proc");
// $NON-NLS-1$
Function f = new Function("length", new Expression[] { exampleElement(true, 1) });
SPParameter param1 = new SPParameter(1, f);
exec.setParameter(param1);
// Run symbol mapper
StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
DeepPreOrderNavigator.doVisit(exec, visitor);
// Check that element got switched
Function afterFunc = (Function) param1.getExpression();
// $NON-NLS-1$
assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), afterFunc.getArg(0));
}
use of org.teiid.query.sql.lang.StoredProcedure in project teiid by teiid.
the class TestStaticSymbolMappingVisitor method testExecParamNestedFunction.
public void testExecParamNestedFunction() {
StoredProcedure exec = new StoredProcedure();
// $NON-NLS-1$
exec.setProcedureName("pm1.proc1");
// $NON-NLS-1$
exec.setProcedureID("proc");
// $NON-NLS-1$
Function f = new Function("length", new Expression[] { exampleElement(true, 1) });
// $NON-NLS-1$
Function f2 = new Function("+", new Expression[] { f, new Constant(new Integer(1)) });
SPParameter param1 = new SPParameter(1, f2);
exec.setParameter(param1);
// Run symbol mapper
StaticSymbolMappingVisitor visitor = new StaticSymbolMappingVisitor(getSymbolMap());
DeepPreOrderNavigator.doVisit(exec, visitor);
// Check that element got switched
Function afterFunc = (Function) param1.getExpression();
Function innerFunc = (Function) afterFunc.getArgs()[0];
// $NON-NLS-1$
assertEquals("Stored proc param did not get mapped correctly: ", exampleElement(false, 1), innerFunc.getArg(0));
}
Aggregations