Author: shawkins
Date: 2012-09-25 20:32:18 -0400 (Tue, 25 Sep 2012)
New Revision: 4473
Added:
trunk/engine/src/main/java/org/teiid/query/processor/proc/BlockInstruction.java
Modified:
trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-2229 adding resolving and processing support for directly nested blocks
Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-25 22:15:11 UTC
(rev 4472)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java 2012-09-26 00:32:18 UTC
(rev 4473)
@@ -250,7 +250,6 @@
TEIID30240,
TEIID30241,
TEIID30242,
- TEIID30243,
TEIID30244,
TEIID30245,
TEIID30247,
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2012-09-25
22:15:11 UTC (rev 4472)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -31,7 +31,6 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.id.IDGenerator;
import org.teiid.core.util.Assertion;
-import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -318,8 +317,14 @@
instruction = new WhileInstruction(whileProgram,
whileStmt.getCondition(), whileStmt.getLabel());
break;
}
+ case Statement.TYPE_COMPOUND:
+ {
+ Block block = (Block)statement;
+ instruction = new BlockInstruction(planBlock(parentProcCommand, block,
metadata, debug, idGenerator, capFinder, analysisRecord, context));
+ break;
+ }
default:
- throw new QueryPlannerException(QueryPlugin.Event.TEIID30243,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30243, stmtType));
+ throw new AssertionError("Error while planning update procedure, unknown
statement type encountered: " + statement); //$NON-NLS-1$
}
return instruction;
}
Added: trunk/engine/src/main/java/org/teiid/query/processor/proc/BlockInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/BlockInstruction.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/processor/proc/BlockInstruction.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.processor.proc;
+
+import static org.teiid.query.analysis.AnalysisRecord.*;
+
+import org.teiid.client.plan.PlanNode;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+
+public class BlockInstruction extends ProgramInstruction {
+
+ private Program program;
+
+ public BlockInstruction(Program ifProgram) {
+ this.program = ifProgram;
+ }
+
+ public void process(ProcedurePlan procEnv)
+ throws BlockedException, TeiidComponentException, TeiidProcessingException {
+ procEnv.push(program);
+ }
+
+ public Program getProgram(){
+ return this.program;
+ }
+
+ /**
+ * Returns a deep clone
+ */
+ public BlockInstruction clone(){
+ return new BlockInstruction(this.program.clone());
+ }
+
+ public String toString() {
+ return "BLOCK INSTRUCTION:\n " + this.program; //$NON-NLS-1$
+ }
+
+ public PlanNode getDescriptionProperties() {
+ PlanNode props = new PlanNode("BLOCK"); //$NON-NLS-1$
+ props.addProperty(PROP_PROGRAM, this.program.getDescriptionProperties());
+ return props;
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/processor/proc/BlockInstruction.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2012-09-25
22:15:11 UTC (rev 4472)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -316,6 +316,9 @@
resolveBlock(command, loopStmt.getBlock(), externalGroups, metadata,
pushChild(sn));
break;
+ case Statement.TYPE_COMPOUND:
+ resolveBlock(command, (Block)statement, externalGroups, metadata, sn);
+ break;
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-09-25
22:15:11 UTC (rev 4472)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -277,12 +277,20 @@
ifStmt.setCondition(evalCrit);
if(evalCrit.equals(TRUE_CRITERIA)) {
Block ifblock = rewriteBlock(ifStmt.getIfBlock());
- newStmts.addAll(ifblock.getStatements());
+ if (ifblock.isAtomic()) {
+ newStmts.add(ifblock);
+ } else {
+ newStmts.addAll(ifblock.getStatements());
+ }
return;
} else if(evalCrit.equals(FALSE_CRITERIA) || evalCrit.equals(UNKNOWN_CRITERIA)) {
if(ifStmt.hasElseBlock()) {
Block elseBlock = rewriteBlock(ifStmt.getElseBlock());
- newStmts.addAll(elseBlock.getStatements());
+ if (elseBlock.isAtomic()) {
+ newStmts.add(elseBlock);
+ } else {
+ newStmts.addAll(elseBlock.getStatements());
+ }
return;
}
return;
@@ -1186,8 +1194,14 @@
case CompareCriteria.LE:
case CompareCriteria.GE:
case CompareCriteria.EQ:
+ if (leftExpr instanceof Constant) {
+ return TRUE_CRITERIA;
+ }
return getSimpliedCriteria(criteria, criteria.getLeftExpression(), true,
true);
default:
+ if (leftExpr instanceof Constant) {
+ return FALSE_CRITERIA;
+ }
return getSimpliedCriteria(criteria, criteria.getLeftExpression(), false,
true);
}
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-09-25 22:15:11
UTC (rev 4472)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2012-09-26 00:32:18
UTC (rev 4473)
@@ -755,7 +755,6 @@
TEIID30367=Infinite loop detected, procedure will not be executed.
TEIID30244=The batch contained an unrecognized command: {0}
-TEIID30243=Error while planning update procedure, unknown statement type encountered:
{0}
TEIID30272=Error getting modelID
TEIID30213=Cannot find namespace URI for namespace {0} of element {1}
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2012-09-25
22:15:11 UTC (rev 4472)
+++
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -2054,7 +2054,19 @@
List[] expected = new List[] { Arrays.asList("1") }; //$NON-NLS-1$
helpTestProcess(plan, expected, dataManager, tm);
}
+
+ @Test public void testNestedBlock() throws Exception {
+ String ddl = "create virtual procedure proc (z STRING) returns table (x string,
y string) as begin declare string x = z; select x; begin select x, x; end end;";
+ TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);
+ String sql = "call proc('a')"; //$NON-NLS-1$
+ ProcessorPlan plan = getProcedurePlan(sql, tm);
+
+ HardcodedDataManager dataManager = new HardcodedDataManager(tm);
+ List[] expected = new List[] { Arrays.asList("a", "a") };
//$NON-NLS-1$
+ helpTestProcess(plan, expected, dataManager, tm);
+ }
+
private static final boolean DEBUG = false;
}
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2012-09-25
22:15:11 UTC (rev 4472)
+++
trunk/engine/src/test/java/org/teiid/query/resolver/TestProcedureResolving.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -192,6 +192,24 @@
assertEquals("loopCursor", value.getGroupSymbol().getName());
//$NON-NLS-1$
}
+ @Test(expected=QueryResolverException.class) public void testBlockResolving() throws
Exception {
+ StringBuffer proc = new StringBuffer("FOR EACH ROW") //$NON-NLS-1$
+ .append("\nBEGIN") //$NON-NLS-1$
+ //note that this declare takes presedense over the proc INPUTS.e1 and CHANGING.e1
variables
+ .append("\n declare integer e1 = 1;") //$NON-NLS-1$
+ .append("\n BEGIN") //$NON-NLS-1$
+ //inside the scope of the loop, an unqualified e1 should resolve to the loop
variable group
+ .append("\n variables.e1 = e2;") //$NON-NLS-1$
+ .append("\n END") //$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);
+
+ }
+
// variable resolution, variable used in if statement, variable compared against
// different datatype element
@Test public void testCreateUpdateProcedure4() {
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2012-09-25
22:15:11 UTC (rev 4472)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2012-09-26
00:32:18 UTC (rev 4473)
@@ -1184,6 +1184,18 @@
String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nSELECT e1 FROM
pm1.g1;\nEND"; //$NON-NLS-1$
helpTestRewriteCommand(procedure1, expected);
+ }
+
+ @Test public void testRetainAtomic() {
+ String procedure1 = "CREATE virtual PROCEDURE "; //$NON-NLS-1$
+ procedure1 += "if (true)\n"; //$NON-NLS-1$
+ procedure1 += "begin atomic\n"; //$NON-NLS-1$
+ procedure1 += "select e1 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure1 += "end\n"; //$NON-NLS-1$
+
+ String expected = "CREATE VIRTUAL PROCEDURE\nBEGIN\nBEGIN ATOMIC\nSELECT e1
FROM pm1.g1;\nEND\nEND"; //$NON-NLS-1$
+
+ helpTestRewriteCommand(procedure1, expected);
}
@Test public void testRewriteDeclare() {