private void helpFailUpdateProcedure(String procedure, String userUpdateStr, Table.TriggerEvent procedureType) { helpFailUpdateProcedure(procedure, userUpdateStr, procedureType, null); }
@Test public void testCreateAfterImplicitTempTable() throws Exception { StringBuffer proc = new StringBuffer("FOR EACH ROW") //$NON-NLS-1$ .append("\nBEGIN") //$NON-NLS-1$ .append("\n select e1 into #temp from pm1.g1;") //$NON-NLS-1$ .append("\n create local temporary table #temp (e1 string);") //$NON-NLS-1$ .append("\nEND"); //$NON-NLS-1$ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$ helpResolveUpdateProcedure(proc.toString(), userUpdateStr, Table.TriggerEvent.UPDATE); }
private Command helpResolve(String userUpdateStr, QueryMetadataInterface metadata) throws QueryParserException, QueryResolverException, TeiidComponentException { return resolveProcedure(userUpdateStr, metadata); }
@Test public void testInvalidException() throws Exception { String ddl = "create virtual procedure vproc (x integer) returns integer as begin declare object e = sqlexception 'hello'; raise e; raise sqlexception 'hello world' sqlstate 'abc', 1 chain e; end;"; try { TestProcedureResolving.createMetadata(ddl); fail(); } catch (RuntimeException e) { assertEquals("TEIID31080 test.vproc validation error: TEIID31120 An exception may only be chained to another exception. e is not valid.", e.getMessage()); } }
@Test public void testVirtualProcedureWithTempTableAndOrderBy() throws Exception { helpResolve("EXEC pm1.vsp33()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ }
@Test public void testVirtualProcedureInvalid1() throws Exception { helpResolveException("EXEC pm1.vsp32()",RealMetadataFactory.example1Cached(), "TEIID30125 Cursor or exception group names cannot begin with \"#\" as that indicates the name of a temporary table: #mycursor."); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * ensures that a processing error is trappable */ @Test public void testExceptionHandlingWithResultSet() throws Exception { String ddl = "create virtual procedure proc2 (x integer) returns table(y integer) as begin atomic select 1; begin select 1/x; end exception e end;"; TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl); String sql = "call proc2(0)"; //$NON-NLS-1$ ProcessorPlan plan = getProcedurePlan(sql, tm); HardcodedDataManager dataManager = new HardcodedDataManager(tm); helpTestProcess(plan, new List[] {Arrays.asList(1)}, dataManager, tm); }
@Test public void testVirtualProcedure() throws Exception { helpResolve("EXEC pm1.vsp1()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ }
@Test public void testInvalidVirtualProcedure2() throws Exception { helpResolveException("EXEC pm1.vsp12()", RealMetadataFactory.example1Cached(), "TEIID31119 Symbol mycursor.e2 is specified with an unknown group context"); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testCreateUpdateProcedure24() { String procedure = "FOR EACH ROW "; //$NON-NLS-1$ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$ procedure = procedure + "DECLARE integer var2.var1;\n"; //$NON-NLS-1$ procedure = procedure + "END\n"; //$NON-NLS-1$ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$ helpFailUpdateProcedure(procedure, userUpdateStr, Table.TriggerEvent.UPDATE); }
@Test public void testResultSetAtomic() throws Exception { String ddl = "create virtual procedure proc2 (x integer) returns table(y integer) as begin select 1; begin atomic select 2; end end;"; TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl); String sql = "call proc2(0)"; //$NON-NLS-1$ ProcessorPlan plan = getProcedurePlan(sql, tm); HardcodedDataManager dataManager = new HardcodedDataManager(tm); helpTestProcess(plan, new List[] {Arrays.asList(2)}, dataManager, tm); }
@Test public void testCreateUpdateProcedure26() throws Exception { String procedure = "FOR EACH ROW "; //$NON-NLS-1$ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$ procedure = procedure + "DECLARE integer VARIABLES.var1;\n"; //$NON-NLS-1$ procedure = procedure + "END\n"; //$NON-NLS-1$ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$ helpResolveUpdateProcedure(procedure, userUpdateStr, Table.TriggerEvent.UPDATE); }
@Test public void testVirtualProcedureWithNoFromAndOrderBy() throws Exception { helpResolve("EXEC pm1.vsp28()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ }
@Test public void testLoopRedefinition2() throws Exception { helpResolveException("EXEC pm1.vsp11()", RealMetadataFactory.example1Cached(), "TEIID30124 Loop cursor or exception group name mycursor already exists."); //$NON-NLS-1$ //$NON-NLS-2$ }
private TriggerAction helpResolveUpdateProcedure(String procedure, String userUpdateStr, Table.TriggerEvent procedureType) throws QueryParserException, QueryResolverException, TeiidComponentException { QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure); return (TriggerAction) resolveProcedure(userUpdateStr, metadata); }
@Test public void testCreateUpdateProcedure29() { String procedure = "FOR EACH ROW "; //$NON-NLS-1$ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$ procedure = procedure + "var1 = 1;\n"; //$NON-NLS-1$ procedure = procedure + "END\n"; //$NON-NLS-1$ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$ helpFailUpdateProcedure(procedure, userUpdateStr, Table.TriggerEvent.UPDATE); }
@Test public void testExceptionGroup() throws Exception { String ddl = "create virtual procedure vproc () returns string as begin select 1/0; exception e \"return\" = e.state || ' ' || e.errorcode || ' ' || e.teiidcode || ' ' || cast(e.exception as string) || ' ' || cast(e.chain as string); end;"; TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl); String sql = "call vproc()"; //$NON-NLS-1$ ProcessorPlan plan = getProcedurePlan(sql, tm); HardcodedDataManager dataManager = new HardcodedDataManager(tm); helpTestProcess(plan, new List[] {Arrays.asList("50000 30328 TEIID30328 org.teiid.jdbc.TeiidSQLException: TEIID30328 Unable to evaluate (1 / 0): TEIID30384 Error while evaluating function / org.teiid.api.exception.query.ExpressionEvaluationException: TEIID30328 Unable to evaluate (1 / 0): TEIID30384 Error while evaluating function /")}, dataManager, tm); }
@Test public void testCreateUpdateProcedure1() throws Exception { String procedure = "FOR EACH ROW "; //$NON-NLS-1$ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$ procedure = procedure + "var1 = Select pm1.g1.e2 from pm1.g1;\n"; //$NON-NLS-1$ procedure = procedure + "UPDATE pm1.g1 SET pm1.g1.e1 = 1, pm1.g1.e2 = var1;\n"; //$NON-NLS-1$ procedure = procedure + "END\n"; //$NON-NLS-1$ String userUpdateStr = "UPDATE vm1.g1 SET e1=1"; //$NON-NLS-1$ helpResolveUpdateProcedure(procedure, userUpdateStr, Table.TriggerEvent.UPDATE); }
@Test public void testVirtualProcedure2() throws Exception { helpResolve("EXEC pm1.vsp14()", RealMetadataFactory.example1Cached()); //$NON-NLS-1$ }
@Test public void testInvalidVirtualProcedure3() throws Exception { helpResolveException("EXEC pm1.vsp18()", RealMetadataFactory.example1Cached(), "Group does not exist: temptable"); //$NON-NLS-1$ //$NON-NLS-2$ }