Search in sources :

Example 31 with StoredProcedure

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);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Test(org.junit.Test)

Example 32 with StoredProcedure

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());
}
Also used : Array(org.teiid.query.sql.symbol.Array) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 33 with StoredProcedure

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));
}
Also used : Function(org.teiid.query.sql.symbol.Function) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) SPParameter(org.teiid.query.sql.lang.SPParameter)

Example 34 with StoredProcedure

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));
}
Also used : Function(org.teiid.query.sql.symbol.Function) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) SPParameter(org.teiid.query.sql.lang.SPParameter)

Aggregations

StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)34 Test (org.junit.Test)10 SPParameter (org.teiid.query.sql.lang.SPParameter)10 Command (org.teiid.query.sql.lang.Command)9 Constant (org.teiid.query.sql.symbol.Constant)9 Expression (org.teiid.query.sql.symbol.Expression)9 ArrayList (java.util.ArrayList)8 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)8 List (java.util.List)7 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)7 QueryCommand (org.teiid.query.sql.lang.QueryCommand)5 Reference (org.teiid.query.sql.symbol.Reference)5 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)4 TeiidProcessingException (org.teiid.core.TeiidProcessingException)4 Call (org.teiid.language.Call)4 Insert (org.teiid.query.sql.lang.Insert)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)3 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)3