[teiid-commits] teiid SVN: r3563 - in trunk/engine/src: main/java/org/teiid/query/optimizer and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Oct 18 12:53:54 EDT 2011


Author: shawkins
Date: 2011-10-18 12:53:54 -0400 (Tue, 18 Oct 2011)
New Revision: 3563

Modified:
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/BatchedUpdatePlanner.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
Log:
TEIID-1787 fix for batched update

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2011-10-18 16:43:21 UTC (rev 3562)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/PreparedStatementRequest.java	2011-10-18 16:53:54 UTC (rev 3563)
@@ -220,8 +220,8 @@
 			} else { //just accumulate copies of the command/plan - clones are not necessary
 				if (command == null) {
 					command = this.prepPlan.getCommand();
-					command.setProcessorPlan(this.processPlan);
 				}
+				command.setProcessorPlan(this.processPlan);
 				commands.add(command);
 			}
 		}

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/BatchedUpdatePlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/BatchedUpdatePlanner.java	2011-10-18 16:43:21 UTC (rev 3562)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/BatchedUpdatePlanner.java	2011-10-18 16:53:54 UTC (rev 3563)
@@ -90,8 +90,8 @@
                                   AnalysisRecord analysisRecord, CommandContext context)
     throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
         BatchedUpdateCommand batchedUpdateCommand = (BatchedUpdateCommand)command;
-        List childPlans = new ArrayList(batchedUpdateCommand.getUpdateCommands().size());
-        List updateCommands = batchedUpdateCommand.getUpdateCommands();
+        List<ProcessorPlan> childPlans = new ArrayList<ProcessorPlan>(batchedUpdateCommand.getUpdateCommands().size());
+        List<Command> updateCommands = batchedUpdateCommand.getUpdateCommands();
         int numCommands = updateCommands.size();
         List<VariableContext> allContexts = batchedUpdateCommand.getVariableContexts();
         List<VariableContext> planContexts = null;
@@ -100,7 +100,7 @@
         }
         for (int commandIndex = 0; commandIndex < numCommands; commandIndex++) {
             // Potentially the first command of a batch
-            Command updateCommand = (Command)updateCommands.get(commandIndex);
+            Command updateCommand = updateCommands.get(commandIndex);
             boolean commandWasBatched = false;
             // If this command can be placed in a batch
             if (isEligibleForBatching(updateCommand, metadata)) {
@@ -125,7 +125,7 @@
                     // Find out if there are other commands called on the same physical model
                     // immediately and contiguously after this one
                     batchLoop: for (int batchIndex = commandIndex+1; batchIndex < numCommands; batchIndex++) {
-                        Command batchingCandidate = (Command)updateCommands.get(batchIndex);
+                        Command batchingCandidate = updateCommands.get(batchIndex);
                         // If this command updates the same model, and is eligible for batching, add it to the batch
                         if (canBeAddedToBatch(batchingCandidate, batchModelID, metadata, capFinder)) {
                             batch.add(batchingCandidate);
@@ -165,7 +165,7 @@
                 }
             }
             if (!commandWasBatched) { // If the command wasn't batched, just add the plan for this command to the list of plans
-            	Command cmd = (Command)batchedUpdateCommand.getUpdateCommands().get(commandIndex);
+            	Command cmd = batchedUpdateCommand.getUpdateCommands().get(commandIndex);
             	ProcessorPlan plan = cmd.getProcessorPlan();
             	if (plan == null) {
             		plan = QueryOptimizer.optimizePlan(cmd, metadata, idGenerator, capFinder, analysisRecord, context);

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java	2011-10-18 16:43:21 UTC (rev 3562)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatementBatchedUpdate.java	2011-10-18 16:53:54 UTC (rev 3563)
@@ -79,6 +79,37 @@
     	assertTrue(((Constant)update.getChangeList().getClauses().get(0).getValue()).isMultiValued());
     }
     
+    @Test public void testBatchedUpdateNotPushdown() throws Exception {
+        // Create query 
+		String preparedSql = "UPDATE pm1.g1 SET pm1.g1.e1=?, pm1.g1.e3=? WHERE pm1.g1.e2=?"; //$NON-NLS-1$
+        
+		// Create a testable prepared plan cache
+		SessionAwareCache<PreparedPlan> prepPlanCache = new SessionAwareCache<PreparedPlan>();
+		
+		// Construct data manager with data
+        HardcodedDataManager dataManager = new HardcodedDataManager();
+		dataManager.addData("UPDATE pm1.g1 SET e1 = 'a', e3 = FALSE WHERE pm1.g1.e2 = 0", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
+		dataManager.addData("UPDATE pm1.g1 SET e1 = null, e3 = FALSE WHERE pm1.g1.e2 = 1", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
+		// Source capabilities must support batched updates
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
+        caps.setCapabilitySupport(Capability.BULK_UPDATE, false);
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+        
+        // batch with two commands
+		ArrayList<ArrayList<Object>> values = new ArrayList<ArrayList<Object>>(2);
+		values.add(new ArrayList<Object>(Arrays.asList(new Object[] { "a",  Boolean.FALSE, new Integer(0) })));  //$NON-NLS-1$
+    	values.add(new ArrayList<Object>(Arrays.asList(new Object[] { null, Boolean.FALSE, new Integer(1) })));
+    	
+    	List<?>[] expected = new List[] { 
+                Arrays.asList(2),
+                Arrays.asList(2)
+        };
+    	
+    	// Create the plan and process the query
+    	TestPreparedStatement.helpTestProcessing(preparedSql, values, expected, dataManager, capFinder, RealMetadataFactory.example1Cached(), prepPlanCache, false, false, false,RealMetadataFactory.example1VDB());
+    }
+    
     /**
      * Test prepared statements that use batched updates using the same prepared
      * command with same number of commands in the batch.



More information about the teiid-commits mailing list