Author: shawkins
Date: 2010-10-07 22:24:14 -0400 (Thu, 07 Oct 2010)
New Revision: 2638
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
branches/7.1.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1293 tightening validation related to updates.
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-10-08
02:23:51 UTC (rev 2637)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-10-08
02:24:14 UTC (rev 2638)
@@ -97,6 +97,7 @@
import org.teiid.query.sql.proc.DeclareStatement;
import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
+import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.TranslateCriteria;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
@@ -1366,7 +1367,13 @@
validateSubquery(obj);
}
- public void validateSubquery(SubqueryContainer subQuery) {
+ @Override
+ public void visit(LoopStatement obj) {
+ validateSubquery(obj);
+ }
+
+ //TODO: it may be simplier to catch this in the parser
+ private void validateSubquery(SubqueryContainer subQuery) {
if (subQuery.getCommand() instanceof Query &&
((Query)subQuery.getCommand()).getInto() != null) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.subquery_insert"),
subQuery.getCommand()); //$NON-NLS-1$
}
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
---
branches/7.1.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-10-08
02:23:51 UTC (rev 2637)
+++
branches/7.1.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-10-08
02:24:14 UTC (rev 2638)
@@ -345,32 +345,37 @@
try {
ValidatorReport report = Validator.validate(command, metadata);
- // Get invalid objects from report
- Collection actualObjs = new ArrayList();
- report.collectInvalidObjects(actualObjs);
-
- // Compare expected and actual objects
- Set expectedStrings = new HashSet(Arrays.asList(expectedStringArray));
- Set actualStrings = new HashSet();
- Iterator objIter = actualObjs.iterator();
- while(objIter.hasNext()) {
- LanguageObject obj = (LanguageObject) objIter.next();
- actualStrings.add(SQLStringVisitor.getSQLString(obj));
- }
-
- if(expectedStrings.size() == 0 && actualStrings.size() > 0) {
- fail("Expected no failures but got some: " +
report.getFailureMessage()); //$NON-NLS-1$
- } else if(actualStrings.size() == 0 && expectedStrings.size() > 0)
{
- fail("Expected some failures but got none for sql = " +
command); //$NON-NLS-1$
- } else {
- assertEquals("Expected and actual sets of strings are not the same:
", expectedStrings, actualStrings); //$NON-NLS-1$
- }
+ examineReport(command, expectedStringArray, report);
return report;
} catch(TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
+ private static void examineReport(Object command,
+ String[] expectedStringArray, ValidatorReport report) {
+ // Get invalid objects from report
+ Collection actualObjs = new ArrayList();
+ report.collectInvalidObjects(actualObjs);
+
+ // Compare expected and actual objects
+ Set<String> expectedStrings = new HashSet(Arrays.asList(expectedStringArray));
+ Set<String> actualStrings = new HashSet<String>();
+ Iterator objIter = actualObjs.iterator();
+ while(objIter.hasNext()) {
+ LanguageObject obj = (LanguageObject) objIter.next();
+ actualStrings.add(SQLStringVisitor.getSQLString(obj));
+ }
+
+ if(expectedStrings.size() == 0 && actualStrings.size() > 0) {
+ fail("Expected no failures but got some: " + report.getFailureMessage());
//$NON-NLS-1$
+ } else if(actualStrings.size() == 0 && expectedStrings.size() > 0) {
+ fail("Expected some failures but got none for sql = " + command);
//$NON-NLS-1$
+ } else {
+ assertEquals("Expected and actual sets of strings are not the same: ",
expectedStrings, actualStrings); //$NON-NLS-1$
+ }
+ }
+
private void helpValidateProcedure(String procedure, String userUpdateStr, String
procedureType) {
QueryMetadataInterface metadata =
FakeMetadataFactory.exampleUpdateProc(procedureType, procedure);
@@ -2045,4 +2050,17 @@
@Test public void testInvalidIntoSubquery3() {
helpValidate("SELECT e2 FROM pm1.g2 WHERE e2 in (SELECT e1, e2 INTO #x FROM
pm1.g1 WHERE e2 = '3')", new String[] {"SELECT e1, e2 INTO #x FROM
pm1.g1 WHERE e2 = '3'"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
//$NON-NLS-2$
}
+
+ @Test public void testInvalidIntoSubquery4() throws Exception {
+ StringBuffer procedure = new StringBuffer("CREATE VIRTUAL PROCEDURE\n")
//$NON-NLS-1$
+ .append("BEGIN\n") //$NON-NLS-1$
+ .append("loop on (SELECT e1, e2 INTO #x FROM pm1.g1
WHERE e2 = '3') as x\n") //$NON-NLS-1$
+ .append("BEGIN\nSELECT 1;\nEND\nSELECT
1\n;END\n"); //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
+
+ // Validate
+ ValidatorReport report = helpValidateInModeler("pm1.vsp36",
procedure.toString(), metadata); //$NON-NLS-1$
+ examineReport(procedure, new String[] {"SELECT e1, e2 INTO #x FROM pm1.g1
WHERE e2 = '3'"}, report);
+ }
}
Show replies by date