Author: shawkins
Date: 2009-09-21 13:29:59 -0400 (Mon, 21 Sep 2009)
New Revision: 1428
Added:
trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/GroupSymbol.java
trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
TEIID-162 adding support for updatable temp tables. the implementation creates a new
tuple source as the target for the update.
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2009-09-21
17:29:59 UTC (rev 1428)
@@ -648,10 +648,6 @@
<para>temp tables are non-transactional.
</para>
</listitem>
- <listitem>
- <para>Temp tables do not support update or delete operations.
- </para>
- </listitem>
</itemizedlist>
<para>The following example is a series of statements that loads a temporary
table with data from 2 sources, and with a manually inserted record, and then uses that
temp table in a subsequent query.</para>
<programlisting>...
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/LoopInstruction.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -71,10 +71,6 @@
}
}
- public Program getLoopProgram() { //Defect 13291 - added method to support changes to
ProcedurePlan
- return loopProgram;
- }
-
/**
* Returns a deep clone
*/
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/proc/ProcedurePlan.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -404,11 +404,7 @@
if(rowCount == null) {
rowCount = new Integer(NO_ROWS_UPDATED);
}
-
- final List updateResult = new ArrayList(1);
- updateResult.add(rowCount);
-
- return new UpdateCountTupleSource(updateResult);
+ return new UpdateCountTupleSource((Integer)rowCount);
}
/**
Modified:
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/main/java/com/metamatrix/query/processor/relational/RelationalNode.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -357,7 +357,7 @@
* @param elements List of elements
* @return Map of element to Integer, which is the index
*/
- protected Map createLookupMap(List elements) {
+ public static Map createLookupMap(List elements) {
Map lookupMap = new HashMap();
for(int i=0; i<elements.size(); i++) {
Object element = elements.get(i);
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-09-20
16:31:50 UTC (rev 1427)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/lang/Command.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -107,7 +107,7 @@
public static final int TYPE_DROP = 12;
- private static List updateCommandSymbol;
+ private static List<SingleElementSymbol> updateCommandSymbol;
/**
* All temporary group IDs discovered while resolving this
@@ -305,11 +305,11 @@
*/
public abstract boolean areResultsCachable();
- public static List getUpdateCommandSymbol() {
+ public static List<SingleElementSymbol> getUpdateCommandSymbol() {
if (updateCommandSymbol == null ) {
ElementSymbol symbol = new ElementSymbol("Count"); //$NON-NLS-1$
symbol.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- updateCommandSymbol = Arrays.asList(new ElementSymbol[] {symbol});
+ updateCommandSymbol = Arrays.asList((SingleElementSymbol)symbol);
}
return updateCommandSymbol;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/GroupSymbol.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/GroupSymbol.java 2009-09-20
16:31:50 UTC (rev 1427)
+++ trunk/engine/src/main/java/com/metamatrix/query/sql/symbol/GroupSymbol.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -151,7 +151,7 @@
}
/**
- * Returns true if this is a symbol for a temporary group (i.e. if it starts with a
'#')
+ * Returns true if this is a symbol for a temporary (implicit or explicit) group
* @return
* @since 5.5
*/
Modified:
trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/main/java/com/metamatrix/query/tempdata/TempTableStoreImpl.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -23,14 +23,15 @@
package com.metamatrix.query.tempdata;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.api.exception.query.QueryMetadataException;
import com.metamatrix.api.exception.query.QueryProcessingException;
@@ -48,25 +49,107 @@
import com.metamatrix.query.metadata.TempMetadataAdapter;
import com.metamatrix.query.metadata.TempMetadataStore;
import com.metamatrix.query.processor.proc.UpdateCountTupleSource;
+import com.metamatrix.query.processor.relational.RelationalNode;
+import com.metamatrix.query.processor.relational.TupleCollector;
import com.metamatrix.query.resolver.util.ResolverUtil;
import com.metamatrix.query.sql.lang.Command;
import com.metamatrix.query.sql.lang.Create;
+import com.metamatrix.query.sql.lang.Criteria;
+import com.metamatrix.query.sql.lang.Delete;
import com.metamatrix.query.sql.lang.Drop;
import com.metamatrix.query.sql.lang.Insert;
+import com.metamatrix.query.sql.lang.ProcedureContainer;
import com.metamatrix.query.sql.lang.Query;
+import com.metamatrix.query.sql.lang.Update;
import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
import com.metamatrix.query.sql.symbol.Expression;
import com.metamatrix.query.sql.symbol.GroupSymbol;
+import com.metamatrix.query.sql.symbol.SingleElementSymbol;
import com.metamatrix.query.util.TypeRetrievalUtil;
/**
* @since 5.5
*/
-public class TempTableStoreImpl implements TempTableStore{
- private BufferManager buffer;
+public class TempTableStoreImpl implements TempTableStore {
+
+ private abstract class UpdateTupleSource implements TupleSource {
+ private final String groupKey;
+ private final TupleSourceID tsId;
+ private final TupleSource ts;
+ protected final Map lookup;
+ private final TupleCollector tc;
+ private final TupleSourceID newTs;
+ protected final Evaluator eval;
+ private final Criteria crit;
+ protected int updateCount = 0;
+ private boolean done;
+
+ private UpdateTupleSource(String groupKey, TupleSourceID tsId, Criteria crit) throws
TupleSourceNotFoundException, MetaMatrixComponentException {
+ this.groupKey = groupKey;
+ this.tsId = tsId;
+ this.ts = buffer.getTupleSource(tsId);
+ List columns = buffer.getTupleSchema(tsId);
+ this.lookup = RelationalNode.createLookupMap(columns);
+ this.newTs = buffer.createTupleSource(columns,
TypeRetrievalUtil.getTypeNames(columns), sessionID, TupleSourceType.PROCESSOR);
+ this.tc = new TupleCollector(newTs, buffer);
+ this.eval = new Evaluator(lookup, null, null);
+ this.crit = crit;
+ }
+
+ @Override
+ public List<?> nextTuple() throws MetaMatrixComponentException,
+ MetaMatrixProcessingException {
+ if (done) {
+ return null;
+ }
+
+ List<?> tuple = null;
+ //still have to worry about blocked exceptions...
+ while ((tuple = ts.nextTuple()) != null) {
+ if (eval.evaluate(crit, tuple)) {
+ tuplePassed(tuple);
+ } else {
+ tupleFailed(tuple);
+ }
+ }
+ tc.close();
+ groupToTupleSourceID.put(groupKey, newTs);
+ try {
+ buffer.removeTupleSource(tsId);
+ }catch(TupleSourceNotFoundException e) {
+
+ }
+ done = true;
+ return Arrays.asList(updateCount);
+ }
+
+ protected void addTuple(List<?> tuple) throws MetaMatrixComponentException {
+ try {
+ tc.addTuple(tuple);
+ } catch (TupleSourceNotFoundException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ }
+
+ protected abstract void tuplePassed(List<?> tuple) throws
ExpressionEvaluationException, BlockedException, MetaMatrixComponentException;
+
+ protected abstract void tupleFailed(List<?> tuple) throws
MetaMatrixComponentException;
+
+ @Override
+ public List<SingleElementSymbol> getSchema() {
+ return Command.getUpdateCommandSymbol();
+ }
+
+ @Override
+ public void closeSource() throws MetaMatrixComponentException {
+
+ }
+ }
+
+ private BufferManager buffer;
private TempMetadataStore tempMetadataStore = new TempMetadataStore();
- private Map groupToTupleSourceID = new HashMap();
+ private Map<String, TupleSourceID> groupToTupleSourceID = new
HashMap<String, TupleSourceID>();
private String sessionID;
private TempTableStore parentTempTableStore;
@@ -96,7 +179,7 @@
}
groupToTupleSourceID.put(tempTableName, tsId);
}
-
+
public void removeTempTable(Command command) throws MetaMatrixComponentException{
if(command.getType() == Command.TYPE_DROP) {
String tempTableName = ((Drop)command).getTable().getName().toUpperCase();
@@ -106,7 +189,7 @@
public void removeTempTableByName(String tempTableName) throws
MetaMatrixComponentException {
tempMetadataStore.removeTempGroup(tempTableName);
- TupleSourceID tsId =
(TupleSourceID)this.groupToTupleSourceID.remove(tempTableName);
+ TupleSourceID tsId = this.groupToTupleSourceID.remove(tempTableName);
if(tsId != null) {
try {
buffer.removeTupleSource(tsId);
@@ -119,52 +202,90 @@
}
public TupleSource registerRequest(Command command) throws
MetaMatrixComponentException, ExpressionEvaluationException, QueryProcessingException{
- if(!hasTempTable(command)) {
- return null;
- }
-
- switch (command.getType()) {
- case Command.TYPE_INSERT:
- {
- return addTuple((Insert)command);
+ if (command instanceof Query) {
+ Query query = (Query)command;
+ GroupSymbol group = (GroupSymbol)query.getFrom().getGroups().get(0);
+ if (!group.isTempGroupSymbol()) {
+ return null;
}
- case Command.TYPE_QUERY:
- {
- Query query = (Query)command;
- GroupSymbol group = (GroupSymbol)query.getFrom().getGroups().get(0);
- TupleSourceID tsId =
getTupleSourceID(group.getNonCorrelationName().toUpperCase(), command);
- try {
- return buffer.getTupleSource(tsId);
- }catch(TupleSourceNotFoundException e) {
- throw new MetaMatrixComponentException(e);
- }
+ TupleSourceID tsId =
getTupleSourceID(group.getNonCorrelationName().toUpperCase(), command);
+ try {
+ return buffer.getTupleSource(tsId);
+ }catch(TupleSourceNotFoundException e) {
+ throw new MetaMatrixComponentException(e);
}
- case Command.TYPE_CREATE:
- {
- addTempTable(((Create)command).getTable().getName().toUpperCase(),
((Create)command).getColumns(), false);
- return new UpdateCountTupleSource(0);
- }
- case Command.TYPE_DROP:
- {
- removeTempTable(command);
- return new UpdateCountTupleSource(0);
- }
}
- throw new AssertionError("unhandled temp table reqest"); //$NON-NLS-1$
+ if (command instanceof ProcedureContainer) {
+ GroupSymbol group = ((ProcedureContainer)command).getGroup();
+ if (!group.isTempGroupSymbol()) {
+ return null;
+ }
+ final String groupKey = group.getNonCorrelationName().toUpperCase();
+ final TupleSourceID tsId = getTupleSourceID(groupKey, command);
+ if (command instanceof Insert) {
+ return addTuple((Insert)command, tsId);
+ }
+ try {
+ if (command instanceof Update) {
+ final Update update = (Update)command;
+ final Criteria crit = update.getCriteria();
+ return new UpdateTupleSource(groupKey, tsId, crit) {
+ @Override
+ protected void tuplePassed(List<?> tuple)
+ throws ExpressionEvaluationException,
+ BlockedException, MetaMatrixComponentException {
+ List<Object> newTuple = new ArrayList<Object>(tuple);
+ for (Map.Entry<ElementSymbol, Expression> entry :
update.getChangeList().getClauseMap().entrySet()) {
+ newTuple.set((Integer)lookup.get(entry.getKey()),
eval.evaluate(entry.getValue(), tuple));
+ }
+ updateCount++;
+ addTuple(newTuple);
+ }
+
+ protected void tupleFailed(java.util.List<?> tuple) throws
MetaMatrixComponentException {
+ addTuple(tuple);
+ }
+ };
+ }
+ if (command instanceof Delete) {
+ final Delete delete = (Delete)command;
+ final Criteria crit = delete.getCriteria();
+ return new UpdateTupleSource(groupKey, tsId, crit) {
+ @Override
+ protected void tuplePassed(List<?> tuple)
+ throws ExpressionEvaluationException,
+ BlockedException, MetaMatrixComponentException {
+ updateCount++;
+ }
+
+ protected void tupleFailed(java.util.List<?> tuple) throws
MetaMatrixComponentException {
+ addTuple(tuple);
+ }
+ };
+ }
+ } catch (TupleSourceNotFoundException e) {
+ throw new MetaMatrixComponentException(e);
+ }
+ }
+ if (command instanceof Create) {
+ addTempTable(((Create)command).getTable().getName().toUpperCase(),
((Create)command).getColumns(), false);
+ return new UpdateCountTupleSource(0);
+ }
+ if (command instanceof Drop) {
+ removeTempTable(command);
+ return new UpdateCountTupleSource(0);
+ }
+ return null;
}
public void removeTempTables() throws MetaMatrixComponentException{
- List names = new ArrayList( groupToTupleSourceID.keySet() );
- Iterator iter = names.iterator();
-
- while(iter.hasNext()) {
- removeTempTableByName((String)iter.next());
+ for (String name : new ArrayList<String>( groupToTupleSourceID.keySet() ))
{
+ removeTempTableByName(name);
}
}
private TupleSourceID getTupleSourceID(String tempTableID, Command command) throws
MetaMatrixComponentException, QueryProcessingException{
-
- TupleSourceID tsID = (TupleSourceID)groupToTupleSourceID.get(tempTableID);
+ TupleSourceID tsID = groupToTupleSourceID.get(tempTableID);
if(tsID != null) {
return tsID;
}
@@ -195,42 +316,23 @@
throw new
QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_doesnt_exist_error",
tempTableID)); //$NON-NLS-1$
}
addTempTable(tempTableID, columns, true);
- return (TupleSourceID)groupToTupleSourceID.get(tempTableID);
+ return groupToTupleSourceID.get(tempTableID);
}
- private TupleSource addTuple(Insert insert) throws MetaMatrixComponentException,
ExpressionEvaluationException, QueryProcessingException {
+ private TupleSource addTuple(Insert insert, TupleSourceID tsId) throws
MetaMatrixComponentException, ExpressionEvaluationException {
GroupSymbol group = insert.getGroup();
- TupleSourceID tsId =
getTupleSourceID(group.getNonCorrelationName().toUpperCase(), insert);
int tuplesAdded = 0;
try {
int rowCount = buffer.getRowCount(tsId);
TupleBatch tupleBatch;
- List elements = ResolverUtil.resolveElementsInGroup(group, new
TempMetadataAdapter(null, tempMetadataStore));
+ List<ElementSymbol> elements =
ResolverUtil.resolveElementsInGroup(group, new TempMetadataAdapter(null,
tempMetadataStore));
- if ( insert.isBulk() ) {
- List<List<Object>> tuples = getBulkRows(insert);
-
- tuplesAdded = tuples.size();
+ List<List<Object>> tuples = getBulkRows(insert, elements);
+
+ tuplesAdded = tuples.size();
- // Buffer manager has 1 based index for the tuple sources
- tupleBatch = new TupleBatch((++rowCount), tuples);
-
- } else {
-
- tuplesAdded = 1;
- List tuple = new ArrayList(elements.size());
- for(Iterator i = elements.iterator(); i.hasNext();){
- ElementSymbol symbol = (ElementSymbol)i.next();
- int index = insert.getVariables().indexOf(symbol);
- Object value = null;
- if (index != -1) {
- Expression expr = (Expression)insert.getValues().get(index);
- value = Evaluator.evaluate(expr);
- }
- tuple.add(value);
- }
- tupleBatch = new TupleBatch(++rowCount, new List[]{tuple});
- }
+ // Buffer manager has 1 based index for the tuple sources
+ tupleBatch = new TupleBatch((++rowCount), tuples);
buffer.addTupleBatch(tsId, tupleBatch);
} catch (TupleSourceNotFoundException err) {
@@ -244,18 +346,31 @@
return new UpdateCountTupleSource(tuplesAdded);
}
- public static List<List<Object>> getBulkRows(Insert insert) {
- Constant c = (Constant)insert.getValues().get(0);
- int bulkRowCount = ((List<?>)c.getValue()).size();
+ public static List<List<Object>> getBulkRows(Insert insert,
List<ElementSymbol> elements) throws ExpressionEvaluationException,
BlockedException, MetaMatrixComponentException {
+ int bulkRowCount = 1;
+ if (insert.isBulk()) {
+ Constant c = (Constant)insert.getValues().get(0);
+ bulkRowCount = ((List<?>)c.getValue()).size();
+ }
List<List<Object>> tuples = new
ArrayList<List<Object>>(bulkRowCount);
for (int row = 0; row < bulkRowCount; row++) {
List<Object> currentRow = new
ArrayList<Object>(insert.getValues().size());
- for (int i = 0; i < insert.getValues().size(); i++) {
- Constant multiValue = (Constant)insert.getValues().get(i);
- currentRow.add(((List<?>)multiValue.getValue()).get(row));
- }
+ for (ElementSymbol symbol : elements) {
+ int index = insert.getVariables().indexOf(symbol);
+ Object value = null;
+ if (index != -1) {
+ if (insert.isBulk()) {
+ Constant multiValue = (Constant)insert.getValues().get(index);
+ value = ((List<?>)multiValue.getValue()).get(row);
+ } else {
+ Expression expr = (Expression)insert.getValues().get(index);
+ value = Evaluator.evaluate(expr);
+ }
+ }
+ currentRow.add(value);
+ }
tuples.add(currentRow);
}
return tuples;
@@ -286,11 +401,11 @@
return false;
}
- public Set getAllTempTables() {
- return new HashSet(this.groupToTupleSourceID.keySet());
+ public Set<String> getAllTempTables() {
+ return new HashSet<String>(this.groupToTupleSourceID.keySet());
}
public TupleSourceID getTupleSourceID(String tempTableName) {
- return (TupleSourceID)groupToTupleSourceID.get(tempTableName.toUpperCase());
+ return groupToTupleSourceID.get(tempTableName.toUpperCase());
}
}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -163,9 +163,6 @@
validateNoXMLUpdates(obj);
validateHasProjectedSymbols(obj);
validateGroupSupportsUpdate(obj.getGroup());
- if (obj.getGroup().isTempTable()) {
-
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.update_temp",
obj.getGroup()), obj.getGroup()); //$NON-NLS-1$
- }
}
public void visit(GroupBy obj) {
@@ -834,10 +831,6 @@
}
validateSetClauseList(update.getChangeList());
-
- if (update.getGroup().isTempTable()) {
-
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.update_temp",
update.getGroup()), update.getGroup()); //$NON-NLS-1$
- }
}
/**
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -59,6 +59,7 @@
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.mapping.relational.QueryNode;
+import com.metamatrix.query.metadata.QueryMetadataInterface;
import com.metamatrix.query.optimizer.FakeFunctionMetadataSource;
import com.metamatrix.query.optimizer.QueryOptimizer;
import com.metamatrix.query.optimizer.TestOptimizer;
@@ -105,11 +106,11 @@
}
}
- public static ProcessorPlan helpGetPlan(String sql, FakeMetadataFacade metadata) {
+ public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata) {
return helpGetPlan(sql, metadata, null);
}
- public static ProcessorPlan helpGetPlan(String sql, FakeMetadataFacade metadata,
String[] bindings) {
+ public static ProcessorPlan helpGetPlan(String sql, QueryMetadataInterface metadata,
String[] bindings) {
if(DEBUG) System.out.println("\n####################################\n"
+ sql); //$NON-NLS-1$
Command command = helpParse(sql);
@@ -128,18 +129,18 @@
return process;
}
- static ProcessorPlan helpGetPlan(Command command, FakeMetadataFacade metadata) {
+ static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata) {
return helpGetPlan(command, metadata, new DefaultCapabilitiesFinder());
}
- static ProcessorPlan helpGetPlan(Command command, FakeMetadataFacade metadata,
CapabilitiesFinder capFinder) {
+ static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata,
CapabilitiesFinder capFinder) {
CommandContext context = new CommandContext();
context.setProcessorBatchSize(2000);
context.setConnectorBatchSize(2000);
return helpGetPlan(command, metadata, capFinder, context);
}
- static ProcessorPlan helpGetPlan(Command command, FakeMetadataFacade metadata,
CapabilitiesFinder capFinder, CommandContext context) {
+ static ProcessorPlan helpGetPlan(Command command, QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, CommandContext context) {
if(DEBUG) System.out.println("\n####################################\n" +
command); //$NON-NLS-1$
// resolve
Added: trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
(rev 0)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -0,0 +1,88 @@
+/*
+ * 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 com.metamatrix.query.processor;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.common.buffer.BufferManagerFactory;
+import com.metamatrix.query.metadata.TempMetadataAdapter;
+import com.metamatrix.query.tempdata.TempTableStoreImpl;
+import com.metamatrix.query.unittest.FakeMetadataFactory;
+
+public class TestTempTables {
+
+ private TempMetadataAdapter metadata;
+ private TempTableDataManager dataManager;
+
+ private void execute(String sql, List[] expectedResults) throws Exception {
+ TestProcessor.doProcess(TestProcessor.helpGetPlan(sql, metadata), dataManager,
expectedResults, TestProcessor.createCommandContext());
+ }
+
+ @Before public void setUp() throws MetaMatrixComponentException {
+ TempTableStoreImpl tempStore = new
TempTableStoreImpl(BufferManagerFactory.getStandaloneBufferManager(), "1",
null); //$NON-NLS-1$
+ metadata = new TempMetadataAdapter(FakeMetadataFactory.example1Cached(),
tempStore.getMetadataStore());
+ FakeDataManager fdm = new FakeDataManager();
+ TestProcessor.sampleData1(fdm);
+ dataManager = new TempTableDataManager(fdm, tempStore);
+ }
+
+ @Ignore("need to correct select into query formation")
+ @Test public void testInsertWithQueryExpression() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[]
{Arrays.asList(0)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) select e2, e1 from pm1.g1", new List[]
{Arrays.asList(6)}); //$NON-NLS-1$
+ execute("update x set e1 = e2 where e2 > 1", new List[]
{Arrays.asList(6)}); //$NON-NLS-1$
+ }
+
+ @Test public void testOutofOrderInsert() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[]
{Arrays.asList(0)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (1, 'one')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("select e1, e2 from x", new List[] {Arrays.asList("one",
1)}); //$NON-NLS-1$
+ }
+
+ @Test public void testUpdate() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[]
{Arrays.asList(0)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (1, 'one')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)});
//$NON-NLS-1$
+ execute("update x set e1 = e2 where e2 > 1", new List[]
{Arrays.asList(2)}); //$NON-NLS-1$
+ execute("select e1 from x where e2 > 0 order by e1", new List[] {
//$NON-NLS-1$
+ Arrays.asList((String)null),
+ Arrays.asList("2"), //$NON-NLS-1$
+ Arrays.asList("3"), //$NON-NLS-1$
+ Arrays.asList("c"), //$NON-NLS-1$
+ Arrays.asList("one")}); //$NON-NLS-1$
+ }
+
+ @Test public void testDelete() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer)", new List[]
{Arrays.asList(0)}); //$NON-NLS-1$
+ execute("select e1, e2 into x from pm1.g1", new List[] {Arrays.asList(6)});
//$NON-NLS-1$
+ execute("delete from x where ascii(e1) > e2", new List[]
{Arrays.asList(5)}); //$NON-NLS-1$
+ execute("select e1 from x order by e1", new List[]
{Arrays.asList((String)null)}); //$NON-NLS-1$
+ }
+
+}
Property changes on:
trunk/engine/src/test/java/com/metamatrix/query/processor/TestTempTables.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/proc/TestProcedureProcessor.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -27,7 +27,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -38,9 +37,6 @@
import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.MetaMatrixException;
import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.api.exception.query.QueryParserException;
-import com.metamatrix.api.exception.query.QueryPlannerException;
-import com.metamatrix.api.exception.query.QueryResolverException;
import com.metamatrix.api.exception.query.QueryValidatorException;
import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.BufferManagerFactory;
@@ -53,7 +49,6 @@
import com.metamatrix.dqp.message.ParameterInfo;
import com.metamatrix.query.analysis.AnalysisRecord;
import com.metamatrix.query.mapping.relational.QueryNode;
-import com.metamatrix.query.metadata.TempMetadataID;
import com.metamatrix.query.optimizer.QueryOptimizer;
import com.metamatrix.query.optimizer.TestOptimizer;
import com.metamatrix.query.optimizer.capabilities.CapabilitiesFinder;
@@ -822,9 +817,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -840,9 +833,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
FakeMetadataObject groupID = (FakeMetadataObject)
metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
List elementIDs = metadata.getElementIDsInGroupID(groupID);
@@ -872,9 +863,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
FakeMetadataObject groupID = (FakeMetadataObject)
metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
List elementIDs = metadata.getElementIDsInGroupID(groupID);
@@ -902,9 +891,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -912,47 +899,6 @@
helpTestProcess(plan, expected, dataMgr);
}
- private ProcessorPlan helpTestTempTable(String userUpdateStr,
- FakeMetadataFacade metadata,
- FakeDataManager dataMgr, List[] tempdata)
throws QueryParserException,
-
QueryResolverException,
-
MetaMatrixComponentException,
-
QueryValidatorException,
-
QueryPlannerException,
-
QueryMetadataException {
- QueryParser parser = new QueryParser();
- Command userCommand = parser.parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
- ValidatorReport report = Validator.validate(userCommand, metadata);
- // Get invalid objects from report
- Collection actualObjs = new ArrayList();
- report.collectInvalidObjects(actualObjs);
- if(actualObjs.size() > 0) {
- fail("Expected no failures but got some: " +
report.getFailureMessage()); //$NON-NLS-1$
- }
- QueryRewriter.rewrite(userCommand, null, metadata, null);
-
- ProcessorPlan plan = null;
- AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
- try {
- plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, new
DefaultCapabilitiesFinder(), analysisRecord, null);
- } finally {
- if(DEBUG) {
- System.out.println(analysisRecord.getDebugLog());
- }
- }
-
- Object tempGroup = new TempMetadataID("#temptable",
Collections.EMPTY_LIST); //$NON-NLS-1$
- List tempSymbols = new ArrayList(1);
- ElementSymbol element = new ElementSymbol("Count"); //$NON-NLS-1$
- tempSymbols.add(element);
-
- dataMgr.registerTuples(
- tempGroup,
- tempSymbols, tempdata);
- return plan;
- }
-
@Test public void testVirtualProcedure15() throws Exception {
String userUpdateStr = "EXEC pm1.vsp19()"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
@@ -960,9 +906,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -981,9 +925,7 @@
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
Arrays.asList(new Object[] { "First"}), //$NON-NLS-1$
@@ -999,9 +941,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -1018,9 +958,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -1035,9 +973,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
@@ -1051,9 +987,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {
Arrays.asList(new Object[] { "Second", new Integer(15)})};
//$NON-NLS-1$
@@ -1067,9 +1001,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
// Create expected results
List[] expected = new List[] {};
@@ -1269,9 +1201,7 @@
//Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
- ProcessorPlan plan = helpTestTempTable(userUpdateStr, metadata, dataMgr, new
List[] {
- Arrays.asList( new Object[] { new Integer(1) } )
- } );
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
FakeMetadataObject groupID = (FakeMetadataObject)
metadata.getGroupID("pm1.g2"); //$NON-NLS-1$
List elementIDs = metadata.getElementIDsInGroupID(groupID);
@@ -1298,22 +1228,8 @@
String userUpdateStr = "EXEC pm1.vsp46()"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Command userCommand = null;
- QueryParser parser = new QueryParser();
- userCommand = parser.parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
- QueryRewriter.rewrite(userCommand, null, metadata, null);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- ProcessorPlan plan = null;
- AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
- try {
- plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, new
DefaultCapabilitiesFinder(), analysisRecord, null);
- } finally {
- if(DEBUG) {
- System.out.println(analysisRecord.getDebugLog());
- }
- }
-
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
@@ -2573,22 +2489,8 @@
String userUpdateStr = "select a.e1 from (EXEC pm1.vsp46()) as a, pm1.g1
where a.e1=pm1.g1.e1"; //$NON-NLS-1$
FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();
- Command userCommand = null;
- QueryParser parser = new QueryParser();
- userCommand = parser.parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
- QueryRewriter.rewrite(userCommand, null, metadata, null);
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
- ProcessorPlan plan = null;
- AnalysisRecord analysisRecord = new AnalysisRecord(false, false, DEBUG);
- try {
- plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, new
DefaultCapabilitiesFinder(), analysisRecord, null);
- } finally {
- if(DEBUG) {
- System.out.println(analysisRecord.getDebugLog());
- }
- }
-
// Set up data
FakeDataManager dataMgr = exampleDataManager(metadata);
@@ -2786,5 +2688,25 @@
helpTestProcess(plan, expected, dataMgr);
}
+ @Test public void testTempSubqueryInput() throws Exception {
+ String proc = "CREATE VIRTUAL PROCEDURE " + //$NON-NLS-1$
+ "BEGIN " + //$NON-NLS-1$
+ " select e1, e2, e3, e4 into #t1 from pm1.g1;\n" +
//$NON-NLS-1$
+ " update #t1 set e1 = 1 where e4 < 2;\n" + //$NON-NLS-1$
+ " delete from #t1 where e4 > 2;\n" + //$NON-NLS-1$
+ " select e1 from #t1;\n" + //$NON-NLS-1$
+ "END"; //$NON-NLS-1$
+
+ FakeMetadataFacade metadata = createProcedureMetadata(proc);
+ String userQuery = "SELECT * FROM (EXEC pm1.sq1()) as proc";
//$NON-NLS-1$
+ FakeDataManager dataMgr = exampleDataManager2(metadata);
+ ProcessorPlan plan = getProcedurePlan(userQuery, metadata,
TestOptimizer.getGenericFinder());
+
+ List[] expected = new List[] {
+ Arrays.asList( new Object[] { String.valueOf(1) } ),
+ };
+ helpTestProcess(plan, expected, dataMgr);
+ }
+
private static final boolean DEBUG = false;
}
Modified:
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/relational/TestProjectIntoNode.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -29,6 +29,7 @@
import junit.framework.TestCase;
import com.metamatrix.api.exception.MetaMatrixComponentException;
+import com.metamatrix.api.exception.query.ExpressionEvaluationException;
import com.metamatrix.common.buffer.BlockedException;
import com.metamatrix.common.buffer.BufferManager;
import com.metamatrix.common.buffer.TupleBatch;
@@ -146,7 +147,7 @@
this.exceptionOnClose = exceptionOnClose;
}
public Object lookupCodeValue(CommandContext context,String codeTableName,String
returnElementName,String keyElementName,Object keyValue) throws
BlockedException,MetaMatrixComponentException {return null;}
- public TupleSource registerRequest(Object processorID,Command command,String
modelName,String connectorBindingId, int nodeID) throws MetaMatrixComponentException {
+ public TupleSource registerRequest(Object processorID,Command command,String
modelName,String connectorBindingId, int nodeID) throws MetaMatrixComponentException,
ExpressionEvaluationException {
callCount++;
int batchSize = 1;
@@ -155,7 +156,7 @@
if (command instanceof Insert) {
Insert insert = (Insert)command;
if (insert.isBulk()) {
- List batch = TempTableStoreImpl.getBulkRows(insert);
+ List batch = TempTableStoreImpl.getBulkRows(insert,
insert.getVariables());
batchSize = batch.size();
assertEquals("Unexpected batch on call " + callCount,
expectedBatchSize, batchSize); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-09-20
16:31:50 UTC (rev 1427)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-09-21
17:29:59 UTC (rev 1428)
@@ -1928,23 +1928,6 @@
helpValidate("SELECT * FROM vm1.doc1 where context(1, a2)='x'",
new String[] {"context(1, a2)"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
}
- public void testValidTempUpdateDelete() {
- FakeMetadataFacade fakeMetadata = exampleMetadata();
-
- TempMetadataStore store = new TempMetadataStore(new HashMap());
-
- ElementSymbol e1 = new ElementSymbol("#temp.e1");//$NON-NLS-1$
- e1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
-
- store.addTempGroup("#temp", Arrays.asList(e1), false, true);
//$NON-NLS-1$
-
- QueryMetadataInterface metadata = new TempMetadataAdapter(fakeMetadata, store);
-
- helpValidate("delete from #temp", new String[] {"#temp"},
metadata); //$NON-NLS-1$ //$NON-NLS-2$
-
- helpValidate("update #temp set e1 = 1", new String[]
{"#temp"}, metadata); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public void testInsertIntoVirtualWithQuery() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
Command command = helpResolve("insert into vm1.g1 select 1, 2, true,
3", metadata); //$NON-NLS-1$