@Test public void testTypeLength() throws Exception { String ddl = "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) " + "RETURNS (r1 varchar(10), r2 decimal(11,2), r3 object(1), r4 clob(10000))" + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');"; Schema s = helpParse(ddl, "model").getSchema(); Procedure proc = s.getProcedure("myProc"); assertNotNull(proc); List<Column> cols = proc.getResultSet().getColumns(); assertEquals(10, cols.get(0).getLength()); assertEquals(11, cols.get(1).getPrecision()); assertEquals(1, cols.get(2).getLength()); assertEquals(10000, cols.get(3).getLength()); }
@Test public void testMultipleCommands() throws Exception { String ddl = "CREATE VIEW V1 AS SELECT * FROM PM1.G1 " + "CREATE PROCEDURE FOO(P1 integer) RETURNS (e1 integer, e2 varchar) AS SELECT * FROM PM1.G1;"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); Table table = tableMap.get("V1"); assertNotNull(table); assertEquals("SELECT * FROM PM1.G1", table.getSelectTransformation()); Map<String, Procedure> procedureMap = s.getProcedures(); Procedure p = procedureMap.get("FOO"); assertNotNull(p); assertEquals("SELECT * FROM PM1.G1;", p.getQueryPlan()); }
@Test public void testAlterProcedureOptions() throws Exception { String ddl = "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) " + "RETURNS (r1 varchar, r2 decimal)" + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');" + "ALTER FOREIGN PROCEDURE myProc OPTIONS(SET NAMEINSOURCE 'x')" + "ALTER FOREIGN PROCEDURE myProc ALTER PARAMETER p2 OPTIONS (ADD x 'y');" + "ALTER FOREIGN PROCEDURE myProc OPTIONS(DROP UPDATECOUNT);"; Schema s = helpParse(ddl, "model").getSchema(); Procedure proc = s.getProcedure("myProc"); assertNotNull(proc); assertEquals("x", proc.getNameInSource()); assertEquals("p2", proc.getParameters().get(1).getName()); assertEquals("y", proc.getParameters().get(1).getProperty("x", false)); assertEquals(1, proc.getUpdateCount()); }
@Test public void testSourceProcedure() throws Exception { String ddl = "CREATE FOREIGN PROCEDURE myProc(OUT p1 boolean, p2 varchar, INOUT p3 decimal) " + "RETURNS (r1 varchar, r2 decimal)" + "OPTIONS(RANDOM 'any', UUID 'uuid', NAMEINSOURCE 'nis', ANNOTATION 'desc', UPDATECOUNT '2');"; Schema s = helpParse(ddl, "model").getSchema(); Procedure proc = s.getProcedure("myProc"); assertNotNull(proc); assertFalse(proc.isVirtual()); assertFalse(proc.isFunction()); assertEquals(3, proc.getParameters().size()); assertEquals("p1", proc.getParameters().get(0).getName()); assertEquals("boolean", proc.getParameters().get(0).getDatatype().getName()); assertEquals(ProcedureParameter.Type.Out, proc.getParameters().get(0).getType()); assertEquals("p2", proc.getParameters().get(1).getName()); assertEquals("string", proc.getParameters().get(1).getDatatype().getName()); assertEquals(ProcedureParameter.Type.In, proc.getParameters().get(1).getType()); assertEquals("p3", proc.getParameters().get(2).getName()); assertEquals("bigdecimal", proc.getParameters().get(2).getDatatype().getName()); assertEquals(ProcedureParameter.Type.InOut, proc.getParameters().get(2).getType()); ColumnSet<Procedure> ret = proc.getResultSet(); assertNotNull(ret); assertEquals(2, ret.getColumns().size()); assertEquals("r1", ret.getColumns().get(0).getName()); assertEquals("string", ret.getColumns().get(0).getDatatype().getName()); assertEquals("r2", ret.getColumns().get(1).getName()); assertEquals("bigdecimal", ret.getColumns().get(1).getDatatype().getName()); assertEquals("uuid", proc.getUUID()); assertEquals("nis", proc.getNameInSource()); assertEquals("desc", proc.getAnnotation()); assertEquals(2, proc.getUpdateCount()); assertEquals("any", proc.getProperties().get("RANDOM")); }