Author: shawkins
Date: 2010-08-03 00:32:09 -0400 (Tue, 03 Aug 2010)
New Revision: 2400
Added:
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
Removed:
trunk/engine/src/main/java/org/teiid/query/processor/TempTableDataManager.java
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java
trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
Log:
TEIID-168 added support for implicit materialized view creation. still need to add
refersh logic
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -73,6 +73,7 @@
import org.teiid.logging.MessageLevel;
import org.teiid.logging.CommandLogMessage.Event;
import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.tempdata.TempTableDataManager;
import org.teiid.query.tempdata.TempTableStore;
@@ -236,7 +237,7 @@
public ClientState getClientState(String key, boolean create) {
ClientState state = clientState.get(key);
if (state == null && create) {
- state = new ClientState(new TempTableStore(bufferManager, key));
+ state = new ClientState(new TempTableStore(key));
clientState.put(key, state);
}
return state;
@@ -612,10 +613,6 @@
return this.dataTierMgr;
}
- public void setDataTierManager(ProcessorDataManager dataTierMgr) {
- this.dataTierMgr = dataTierMgr;
- }
-
public BufferManager getBufferManager() {
return bufferManager;
}
@@ -662,12 +659,12 @@
this.processWorkerPool = new
ThreadReuseExecutor(DQPConfiguration.PROCESS_PLAN_QUEUE_NAME, config.getMaxThreads());
- dataTierMgr = new DataTierManagerImpl(this,
+ dataTierMgr = new TempTableDataManager(new DataTierManagerImpl(this,
this.connectorManagerRepository,
this.bufferService,
this.maxCodeTables,
this.maxCodeRecords,
- this.maxCodeTableRecords);
+ this.maxCodeTableRecords),
this.bufferManager);
}
public void setBufferService(BufferService service) {
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -70,7 +70,6 @@
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.QueryProcessor;
-import org.teiid.query.processor.TempTableDataManager;
import org.teiid.query.processor.xml.XMLPlan;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.rewriter.QueryRewriter;
@@ -177,15 +176,6 @@
VDBMetaData vdbMetadata = workContext.getVDB();
metadata = vdbMetadata.getAttachment(QueryMetadataInterface.class);
globalTables = vdbMetadata.getAttachment(TempTableStore.class);
- if (globalTables == null) {
- synchronized (vdbMetadata) {
- globalTables = vdbMetadata.getAttachment(TempTableStore.class);
- if (globalTables == null) {
- globalTables = new TempTableStore(bufferManager, "SYSTEM");
//$NON-NLS-1$
- vdbMetadata.addAttchment(TempTableStore.class, globalTables);
- }
- }
- }
if (metadata == null) {
throw new
TeiidComponentException(DQPPlugin.Util.getString("DQPCore.Unable_to_load_metadata_for_VDB_name__{0},_version__{1}",
this.vdbName, this.vdbVersion)); //$NON-NLS-1$
@@ -362,7 +352,7 @@
}
this.transactionContext = tc;
- this.processor = new QueryProcessor(processPlan, context, bufferManager, new
TempTableDataManager(processorDataManager));
+ this.processor = new QueryProcessor(processPlan, context, bufferManager,
processorDataManager);
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadata.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -505,8 +505,8 @@
}
@Override
- public boolean isPrimaryKey(Object metadataID) {
- return false;
+ public Object getPrimaryKey(Object metadataID) {
+ return null;
}
}
Modified:
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/BasicQueryMetadataWrapper.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -370,8 +370,8 @@
}
@Override
- public boolean isPrimaryKey(Object metadataID) {
- return actualMetadata.isPrimaryKey(metadataID);
+ public Object getPrimaryKey(Object metadataID) {
+ return actualMetadata.getPrimaryKey(metadataID);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/QueryMetadataInterface.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -679,5 +679,5 @@
FunctionLibrary getFunctionLibrary();
- boolean isPrimaryKey(Object metadataID);
+ Object getPrimaryKey(Object metadataID);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -526,11 +526,7 @@
public int getPosition(Object elementID) throws TeiidComponentException,
QueryMetadataException {
if (elementID instanceof TempMetadataID) {
- String elementName = ((TempMetadataID)elementID).getID();
- String groupName = elementName.substring(0,
elementName.lastIndexOf(SEPARATOR));
- TempMetadataID groupID = this.tempStore.getTempGroupID(groupName);
- List elements = groupID.getElements();
- return elements.indexOf(elementID);
+ return ((TempMetadataID)elementID).getPosition();
}
return actualMetadata.getPosition(elementID);
}
@@ -694,15 +690,11 @@
}
@Override
- public boolean isPrimaryKey(Object metadataID) {
+ public Object getPrimaryKey(Object metadataID) {
if (metadataID instanceof TempMetadataID) {
- TempMetadataID tid = (TempMetadataID)metadataID;
- if (tid.getPrimaryKey() != null) {
- return true;
- }
- return false;
+ return metadataID;
}
- return this.actualMetadata.isPrimaryKey(metadataID);
+ return this.actualMetadata.getPrimaryKey(metadataID);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -41,7 +41,8 @@
private static final int LOCAL_CACHE_SIZE = 8;
private String ID; // never null, upper cased fully-qualified string
- private int position = -1; //used for order by symbol resolving. refers to the
position in the select clause
+ private int selectPosition = -1; //used for order by symbol resolving. refers to the
position in the select clause
+ private int position;
private Class<?> type; // type of this element, only for element
private List<TempMetadataID> elements; // of TempMetadataID, only for group
private Object originalMetadataID;
@@ -71,6 +72,10 @@
public TempMetadataID(String ID, List<TempMetadataID> elements, boolean
isVirtual, boolean isTempTable) {
this.ID = ID;
this.elements = elements;
+ int pos = 1;
+ for (TempMetadataID tempMetadataID : elements) {
+ tempMetadataID.setPosition(pos++);
+ }
this.isVirtual = isVirtual;
this.isTempTable = isTempTable;
}
@@ -128,6 +133,7 @@
protected void addElement(TempMetadataID elem) {
if (this.elements != null) {
this.elements.add(elem);
+ elem.setPosition(this.elements.size());
}
if (this.localCache != null) {
this.localCache.clear();
@@ -217,12 +223,12 @@
this.isTempTable = isTempTable;
}
- public int getPosition() {
- return this.position;
+ public int getSelectPosition() {
+ return this.selectPosition;
}
- public void setPosition(int position) {
- this.position = position;
+ public void setSelectPosition(int position) {
+ this.selectPosition = position;
}
Object getProperty(Object key) {
@@ -254,5 +260,13 @@
public void setPrimaryKey(List<TempMetadataID> primaryKey) {
this.primaryKey = primaryKey;
}
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -1069,9 +1069,9 @@
}
@Override
- public boolean isPrimaryKey(Object metadataID) {
- ArgCheck.isInstanceOf(KeyRecord.class, metadataID);
- KeyRecord key = (KeyRecord)metadataID;
- return key.getType() == org.teiid.metadata.KeyRecord.Type.Primary;
+ public Object getPrimaryKey(Object metadataID) {
+ ArgCheck.isInstanceOf(Table.class, metadataID);
+ Table table = (Table)metadataID;
+ return table.getPrimaryKey();
}
}
\ No newline at end of file
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -115,6 +115,8 @@
*/
public class RelationalPlanner {
+ public static final String MAT_PREFIX = "#MAT_"; //$NON-NLS-1$
+
private AnalysisRecord analysisRecord;
private Command parentCommand;
private IDGenerator idGenerator;
@@ -946,7 +948,7 @@
private Command handleCacheHint(GroupSymbol virtualGroup, String name, boolean noCache,
Command result)
throws TeiidComponentException, QueryMetadataException, QueryResolverException,
QueryValidatorException {
TempMetadataStore store = context.getGlobalTableStore().getMetadataStore();
- String matTableName = "#MAT_" + name; //$NON-NLS-1$
+ String matTableName = MAT_PREFIX + name;
TempMetadataID id = store.getTempGroupID(matTableName);
//define the table preserving the primary key
if (id == null) {
@@ -956,19 +958,16 @@
//TODO: this could be done with a generated create
id = store.addTempGroup(matTableName, result.getProjectedSymbols(), false, true);
+ Object pk = metadata.getPrimaryKey(virtualGroup.getMetadataID());
//primary key
- Collection keys = metadata.getUniqueKeysInGroup(virtualGroup.getMetadataID());
- for (Object object : keys) {
- if (metadata.isPrimaryKey(object)) {
- List cols = metadata.getElementIDsInKey(object);
- ArrayList<TempMetadataID> primaryKey = new
ArrayList<TempMetadataID>(cols.size());
- for (Object coldId : cols) {
- int pos = metadata.getPosition(coldId) - 1;
- primaryKey.add(id.getElements().get(pos));
- }
- id.setPrimaryKey(primaryKey);
- break;
+ if (pk != null) {
+ List cols = metadata.getElementIDsInKey(pk);
+ ArrayList<TempMetadataID> primaryKey = new
ArrayList<TempMetadataID>(cols.size());
+ for (Object coldId : cols) {
+ int pos = metadata.getPosition(coldId) - 1;
+ primaryKey.add(id.getElements().get(pos));
}
+ id.setPrimaryKey(primaryKey);
}
//version column?
Modified: trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/processor/BatchCollector.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -24,9 +24,11 @@
import java.util.List;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleBuffer;
+import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -51,6 +53,52 @@
List getOutputElements();
}
+ public static class BatchProducerTupleSource implements TupleSource {
+ private final BatchProducer sourceNode;
+ private TupleBatch sourceBatch; // Current batch loaded from the source, if
blocked
+ private int sourceRow = 1;
+
+ public BatchProducerTupleSource(BatchProducer sourceNode) {
+ this.sourceNode = sourceNode;
+ }
+
+ @Override
+ public List<?> nextTuple() throws TeiidComponentException,
+ TeiidProcessingException {
+ while (true) {
+ if(sourceBatch == null) {
+ // Read next batch
+ sourceBatch = sourceNode.nextBatch();
+ }
+
+ if(sourceBatch.getRowCount() > 0 && sourceRow <=
sourceBatch.getEndRow()) {
+ // Evaluate expressions needed for grouping
+ List tuple = sourceBatch.getTuple(sourceRow);
+ tuple = updateTuple(tuple);
+ sourceRow++;
+ return tuple;
+ }
+
+ // Check for termination condition
+ if(sourceBatch.getTerminationFlag()) {
+ sourceBatch = null;
+ return null;
+ }
+ sourceBatch = null;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ protected List updateTuple(List tuple) throws ExpressionEvaluationException,
BlockedException, TeiidComponentException {
+ return tuple;
+ }
+
+ @Override
+ public void closeSource() {
+
+ }
+ }
+
private BatchProducer sourceNode;
private boolean done = false;
Deleted: trunk/engine/src/main/java/org/teiid/query/processor/TempTableDataManager.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/TempTableDataManager.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/processor/TempTableDataManager.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -1,84 +0,0 @@
-/*
- * 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;
-
-import org.teiid.common.buffer.BlockedException;
-import org.teiid.common.buffer.TupleSource;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.tempdata.TempTableStore;
-import org.teiid.query.util.CommandContext;
-
-
-/**
- * This proxy ProcessorDataManager is used to handle temporary tables.
- */
-public class TempTableDataManager implements ProcessorDataManager {
-
- private ProcessorDataManager processorDataManager;
-
- /**
- * Constructor takes the "real" ProcessorDataManager that this object will
be a proxy to,
- * and will pass most calls through to transparently. Only when a request is
registered for
- * a temp group will this proxy do it's thing.
- * @param processorDataManager the real ProcessorDataManager that this object is a
proxy to
- */
- public TempTableDataManager(ProcessorDataManager processorDataManager){
- this.processorDataManager = processorDataManager;
- }
-
- public TupleSource registerRequest(
- CommandContext context,
- Command command,
- String modelName,
- String connectorBindingId, int nodeID)
- throws TeiidComponentException, TeiidProcessingException {
-
- TempTableStore tempTableStore = context.getTempTableStore();
- if(tempTableStore != null) {
- TupleSource result = tempTableStore.registerRequest(context, command);
- if (result != null) {
- return result;
- }
- }
- return this.processorDataManager.registerRequest(context, command, modelName,
connectorBindingId, nodeID);
- }
-
- public Object lookupCodeValue(
- CommandContext context,
- String codeTableName,
- String returnElementName,
- String keyElementName,
- Object keyValue)
- throws BlockedException, TeiidComponentException, TeiidProcessingException {
-
- return this.processorDataManager.lookupCodeValue(context, codeTableName,
returnElementName, keyElementName, keyValue);
- }
-
- @Override
- public void clearCodeTables() {
- this.processorDataManager.clearCodeTables();
- }
-
-}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/processor/proc/ProcedurePlan.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -201,7 +201,7 @@
context.setValue(entry.getKey(), value);
}
}
- tempTableStore = new TempTableStore(bufferMgr, getContext().getConnectionID());
+ tempTableStore = new TempTableStore(getContext().getConnectionID());
getContext().setTempTableStore(tempTableStore);
}
this.evaluatedParams = true;
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -31,6 +31,7 @@
import java.util.ListIterator;
import java.util.Map;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.client.plan.PlanNode;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
@@ -50,6 +51,7 @@
import org.teiid.query.function.aggregate.StatsFunction;
import org.teiid.query.function.aggregate.Sum;
import org.teiid.query.function.aggregate.XMLAgg;
+import org.teiid.query.processor.BatchCollector;
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.sql.lang.OrderBy;
@@ -267,49 +269,22 @@
final RelationalNode sourceNode = this.getChildren()[0];
- return new TupleSource() {
- private TupleBatch sourceBatch; // Current batch loaded from the source,
if blocked
- private int sourceRow = 1;
-
- @Override
- public List<?> nextTuple() throws TeiidComponentException,
- TeiidProcessingException {
- while (true) {
- if(sourceBatch == null) {
- // Read next batch
- sourceBatch = sourceNode.nextBatch();
- }
-
- if(sourceBatch.getRowCount() > 0 && sourceRow <=
sourceBatch.getEndRow()) {
- // Evaluate expressions needed for grouping
- List tuple = sourceBatch.getTuple(sourceRow);
-
- int columns = collectedExpressions.size();
- List exprTuple = new ArrayList(columns);
- for(int col = 0; col<columns; col++) {
- // The following call may throw BlockedException, but all state to
this point
- // is saved in class variables so we can start over on building
this tuple
- Object value = new Evaluator(elementMap, getDataManager(),
getContext()).evaluate((Expression)collectedExpressions.get(col), tuple);
- exprTuple.add(value);
- }
- sourceRow++;
- return exprTuple;
- }
-
- // Check for termination condition
- if(sourceBatch.getTerminationFlag()) {
- sourceBatch = null;
- return null;
- }
- sourceBatch = null;
- }
- }
+ return new BatchCollector.BatchProducerTupleSource(sourceNode) {
+ Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext());
+
@Override
- public void closeSource() {
-
+ protected List updateTuple(List tuple) throws ExpressionEvaluationException,
BlockedException, TeiidComponentException {
+ int columns = collectedExpressions.size();
+ List exprTuple = new ArrayList(columns);
+ for(int col = 0; col<columns; col++) {
+ // The following call may throw BlockedException, but all state to this
point
+ // is saved in class variables so we can start over on building this
tuple
+ Object value = eval.evaluate(collectedExpressions.get(col), tuple);
+ exprTuple.add(value);
+ }
+ return exprTuple;
}
-
};
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLPlan.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -57,7 +57,6 @@
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.TempTableDataManager;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.tempdata.TempTableStore;
@@ -112,7 +111,7 @@
public void initialize(CommandContext context, ProcessorDataManager dataMgr,
BufferManager bufferMgr) {
context = context.clone();
setContext(context);
- TempTableStore tempTableStore = new TempTableStore(bufferMgr,
context.getConnectionID());
+ TempTableStore tempTableStore = new TempTableStore(context.getConnectionID());
tempTableStore.setParentTempTableStore(context.getTempTableStore());
context.setTempTableStore(tempTableStore);
this.dataMgr = dataMgr;
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -141,7 +141,7 @@
public static boolean orderByContainsVariable(OrderBy orderBy, SingleElementSymbol
ses, int position) {
for (final Iterator iterator = orderBy.getSortKeys().iterator();
iterator.hasNext();) {
final ElementSymbol element = (ElementSymbol)iterator.next();
- if (position == ((TempMetadataID)element.getMetadataID()).getPosition()) {
+ if (position ==
((TempMetadataID)element.getMetadataID()).getSelectPosition()) {
return true;
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -427,7 +427,7 @@
if (matchedSymbol != null) {
TempMetadataID tempMetadataID = new TempMetadataID(symbol.getName(),
matchedSymbol.getType());
int position = knownElements.indexOf(matchedSymbol);
- tempMetadataID.setPosition(position);
+ tempMetadataID.setSelectPosition(position);
symbol.setMetadataID(tempMetadataID);
symbol.setType(matchedSymbol.getType());
return position;
Added: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -0,0 +1,243 @@
+/*
+ * 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.tempdata;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryProcessingException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleSource;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.eval.Evaluator;
+import org.teiid.query.execution.QueryExecPlugin;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
+import org.teiid.query.processor.BatchCollector;
+import org.teiid.query.processor.CollectionTupleSource;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Create;
+import org.teiid.query.sql.lang.Criteria;
+import org.teiid.query.sql.lang.Delete;
+import org.teiid.query.sql.lang.Drop;
+import org.teiid.query.sql.lang.Insert;
+import org.teiid.query.sql.lang.ProcedureContainer;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.navigator.PostOrderNavigator;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
+import org.teiid.query.tempdata.TempTableStore.MatState;
+import org.teiid.query.tempdata.TempTableStore.MatTableInfo;
+import org.teiid.query.util.CommandContext;
+
+
+/**
+ * This proxy ProcessorDataManager is used to handle temporary tables.
+ */
+public class TempTableDataManager implements ProcessorDataManager {
+
+
+
+ private ProcessorDataManager processorDataManager;
+ private BufferManager bufferManager;
+
+ /**
+ * Constructor takes the "real" ProcessorDataManager that this object will
be a proxy to,
+ * and will pass most calls through to transparently. Only when a request is
registered for
+ * a temp group will this proxy do it's thing.
+ * @param processorDataManager the real ProcessorDataManager that this object is a
proxy to
+ */
+ public TempTableDataManager(ProcessorDataManager processorDataManager, BufferManager
bufferManager){
+ this.processorDataManager = processorDataManager;
+ this.bufferManager = bufferManager;
+ }
+
+ public TupleSource registerRequest(
+ CommandContext context,
+ Command command,
+ String modelName,
+ String connectorBindingId, int nodeID)
+ throws TeiidComponentException, TeiidProcessingException {
+
+ TempTableStore tempTableStore = context.getTempTableStore();
+ if(tempTableStore != null) {
+ TupleSource result = registerRequest(context, command);
+ if (result != null) {
+ return result;
+ }
+ }
+ return this.processorDataManager.registerRequest(context, command, modelName,
connectorBindingId, nodeID);
+ }
+
+ public TupleSource registerRequest(CommandContext context, Command command) throws
TeiidComponentException, TeiidProcessingException {
+ TempTableStore contextStore = context.getTempTableStore();
+ if (command instanceof Query) {
+ Query query = (Query)command;
+ return registerQuery(context, command, contextStore, query);
+ }
+ if (command instanceof ProcedureContainer) {
+ GroupSymbol group = ((ProcedureContainer)command).getGroup();
+ if (!group.isTempGroupSymbol()) {
+ return null;
+ }
+ final String groupKey = group.getNonCorrelationName().toUpperCase();
+ final TempTable table = contextStore.getOrCreateTempTable(groupKey, command,
bufferManager, false);
+ if (command instanceof Insert) {
+ Insert insert = (Insert)command;
+ TupleSource ts = insert.getTupleSource();
+ if (ts == null) {
+ List<Object> values = new
ArrayList<Object>(insert.getValues().size());
+ for (Expression expr : (List<Expression>)insert.getValues()) {
+ values.add(Evaluator.evaluate(expr));
+ }
+ ts = new CollectionTupleSource(Arrays.asList(values).iterator());
+ }
+ return table.insert(ts, insert.getVariables());
+ }
+ if (command instanceof Update) {
+ final Update update = (Update)command;
+ final Criteria crit = update.getCriteria();
+ return table.update(crit, update.getChangeList());
+ }
+ if (command instanceof Delete) {
+ final Delete delete = (Delete)command;
+ final Criteria crit = delete.getCriteria();
+ if (crit == null) {
+ //because we are non-transactional, just use a truncate
+ int rows = table.truncate();
+ return CollectionTupleSource.createUpdateCountTupleSource(rows);
+ }
+ return table.delete(crit);
+ }
+ }
+ if (command instanceof Create) {
+ Create create = (Create)command;
+ String tempTableName = create.getTable().getCanonicalName();
+ if (contextStore.hasTempTable(tempTableName)) {
+ throw new
QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_exist_error",
tempTableName));//$NON-NLS-1$
+ }
+ contextStore.addTempTable(tempTableName, create, bufferManager);
+ return CollectionTupleSource.createUpdateCountTupleSource(0);
+ }
+ if (command instanceof Drop) {
+ String tempTableName = ((Drop)command).getTable().getCanonicalName();
+ contextStore.removeTempTableByName(tempTableName);
+ return CollectionTupleSource.createUpdateCountTupleSource(0);
+ }
+ return null;
+ }
+
+ private TupleSource registerQuery(CommandContext context, Command command,
+ TempTableStore contextStore, Query query)
+ throws TeiidComponentException, QueryMetadataException,
+ TeiidProcessingException, ExpressionEvaluationException,
+ QueryProcessingException {
+ GroupSymbol group = query.getFrom().getGroups().get(0);
+ if (!group.isTempGroupSymbol()) {
+ return null;
+ }
+ final String tableName = group.getNonCorrelationName().toUpperCase();
+ TempTable table = null;
+ if (group.isGlobalTable()) {
+ TempTableStore tts = context.getGlobalTableStore();
+ MatTableInfo info = tts.getMatTableInfo(tableName);
+ boolean load = info.shouldLoad();
+ if (load) {
+ QueryMetadataInterface metadata = context.getMetadata();
+ Create create = new Create();
+ create.setTable(group);
+ create.setColumns(ResolverUtil.resolveElementsInGroup(group, metadata));
+ Object pk = metadata.getPrimaryKey(group.getMetadataID());
+ if (pk != null) {
+ for (Object col : metadata.getElementIDsInKey(pk)) {
+ create.getPrimaryKey().add(create.getColumns().get(metadata.getPosition(col)-1));
+ }
+ }
+ table = tts.addTempTable(tableName, create, bufferManager);
+ boolean success = false;
+ try {
+ String actualViewName = tableName.substring(RelationalPlanner.MAT_PREFIX.length());
+ Object id = metadata.getGroupID(actualViewName);
+ String transformation = metadata.getVirtualPlan(id).getQuery();
+ QueryProcessor qp =
context.getQueryProcessorFactory().createQueryProcessor(transformation, actualViewName,
context);
+ qp.setNonBlocking(true);
+ TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
+ //TODO: if this insert fails, it's unnecessary to do the undo processing
+ table.insert(ts, table.getColumns());
+ success = true;
+ } finally {
+ if (!success) {
+ table.remove();
+ tts.removeTempTableByName(tableName);
+ }
+ info.setState(success?MatState.LOADED:MatState.FAILED_LOAD);
+ }
+ } else {
+ table = tts.getOrCreateTempTable(tableName, command, bufferManager, false);
+ }
+ } else {
+ table = contextStore.getOrCreateTempTable(tableName, command, bufferManager, true);
+ }
+ //convert to the actual table symbols (this is typically handled by the
languagebridgefactory
+ ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
+ @Override
+ public Expression replaceExpression(Expression element) {
+ if (element instanceof ElementSymbol) {
+ ElementSymbol es = (ElementSymbol)element;
+ ((ElementSymbol) element).setName(tableName + ElementSymbol.SEPARATOR +
es.getShortName());
+ }
+ return element;
+ }
+ };
+ PostOrderNavigator.doVisit(query, emv);
+ return table.createTupleSource(command.getProjectedSymbols(), query.getCriteria(),
query.getOrderBy());
+ }
+
+ public Object lookupCodeValue(
+ CommandContext context,
+ String codeTableName,
+ String returnElementName,
+ String keyElementName,
+ Object keyValue)
+ throws BlockedException, TeiidComponentException, TeiidProcessingException {
+
+ return this.processorDataManager.lookupCodeValue(context, codeTableName,
returnElementName, keyElementName, keyValue);
+ }
+
+ @Override
+ public void clearCodeTables() {
+ this.processorDataManager.clearCodeTables();
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -23,7 +23,6 @@
package org.teiid.query.tempdata;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -32,52 +31,92 @@
import org.teiid.api.exception.query.QueryProcessingException;
import org.teiid.common.buffer.BufferManager;
-import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.query.eval.Evaluator;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.metadata.TempMetadataStore;
-import org.teiid.query.processor.CollectionTupleSource;
import org.teiid.query.resolver.command.TempTableResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Create;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.Drop;
import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.navigator.PostOrderNavigator;
import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
-import org.teiid.query.util.CommandContext;
-/**
- * @since 5.5
- */
public class TempTableStore {
-
- private BufferManager buffer;
+
+ public enum MatState {
+ NOT_LOADED,
+ LOADING,
+ FAILED_LOAD,
+ LOADED
+ }
+
+ public static class MatTableInfo {
+ private long updateTime = -1;
+ private MatState state = MatState.NOT_LOADED;
+
+ synchronized boolean shouldLoad() throws TeiidComponentException {
+ for (;;) {
+ switch (state) {
+ case NOT_LOADED:
+ updateTime = System.currentTimeMillis();
+ case FAILED_LOAD:
+ state = MatState.LOADING;
+ return true;
+ case LOADING:
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new TeiidComponentException(e);
+ }
+ continue;
+ case LOADED:
+ return false;
+ }
+ }
+ }
+
+ public synchronized void setState(MatState state) {
+ this.state = state;
+ this.updateTime = System.currentTimeMillis();
+ notifyAll();
+ }
+
+ public long getUpdateTime() {
+ return updateTime;
+ }
+
+ }
+
+ private ConcurrentHashMap<String, MatTableInfo> matTables = new
ConcurrentHashMap<String, MatTableInfo>();
+
private TempMetadataStore tempMetadataStore = new TempMetadataStore(new
ConcurrentHashMap<String, TempMetadataID>());
private Map<String, TempTable> groupToTupleSourceID = new
ConcurrentHashMap<String, TempTable>();
private String sessionID;
private TempTableStore parentTempTableStore;
- public TempTableStore(BufferManager buffer, String sessionID) {
- this.buffer = buffer;
+ public TempTableStore(String sessionID) {
this.sessionID = sessionID;
}
+ public MatTableInfo getMatTableInfo(final String tableName) {
+ MatTableInfo newInfo = new MatTableInfo();
+ MatTableInfo info = matTables.putIfAbsent(tableName, newInfo);
+ if (info == null) {
+ info = newInfo;
+ }
+ return info;
+ }
+
public void setParentTempTableStore(TempTableStore parentTempTableStore) {
this.parentTempTableStore = parentTempTableStore;
}
+
+ public boolean hasTempTable(String tempTableName) {
+ return groupToTupleSourceID.containsKey(tempTableName);
+ }
- void addTempTable(String tempTableName, Create create) {
+ TempTable addTempTable(String tempTableName, Create create, BufferManager buffer) {
List<ElementSymbol> columns = create.getColumns();
//add metadata
@@ -92,6 +131,7 @@
}
TempTable tempTable = new TempTable(id, buffer, columns,
create.getPrimaryKey().size(), sessionID);
groupToTupleSourceID.put(tempTableName, tempTable);
+ return tempTable;
}
public void removeTempTableByName(String tempTableName) {
@@ -105,89 +145,14 @@
public TempMetadataStore getMetadataStore() {
return tempMetadataStore;
}
-
- public TupleSource registerRequest(CommandContext context, Command command) throws
TeiidComponentException, TeiidProcessingException{
- if (command instanceof Query) {
- Query query = (Query)command;
- GroupSymbol group = query.getFrom().getGroups().get(0);
- if (!group.isTempGroupSymbol()) {
- return null;
- }
- final String tableName = group.getNonCorrelationName().toUpperCase();
- TempTable table = getOrCreateTempTable(tableName, command, true);
- //convert to the actual table symbols (this is typically handled by the
languagebridgefactory
- ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
- @Override
- public Expression replaceExpression(Expression element) {
- if (element instanceof ElementSymbol) {
- ElementSymbol es = (ElementSymbol)element;
- ((ElementSymbol) element).setName(tableName + ElementSymbol.SEPARATOR +
es.getShortName());
- }
- return element;
- }
- };
- PostOrderNavigator.doVisit(query, emv);
- return table.createTupleSource(command.getProjectedSymbols(),
query.getCriteria(), query.getOrderBy());
- }
- if (command instanceof ProcedureContainer) {
- GroupSymbol group = ((ProcedureContainer)command).getGroup();
- if (!group.isTempGroupSymbol()) {
- return null;
- }
- final String groupKey = group.getNonCorrelationName().toUpperCase();
- final TempTable table = getOrCreateTempTable(groupKey, command, false);
- if (command instanceof Insert) {
- Insert insert = (Insert)command;
- TupleSource ts = insert.getTupleSource();
- if (ts == null) {
- List<Object> values = new
ArrayList<Object>(insert.getValues().size());
- for (Expression expr : (List<Expression>)insert.getValues()) {
- values.add(Evaluator.evaluate(expr));
- }
- ts = new CollectionTupleSource(Arrays.asList(values).iterator());
- }
- return table.insert(ts, insert.getVariables());
- }
- if (command instanceof Update) {
- final Update update = (Update)command;
- final Criteria crit = update.getCriteria();
- return table.update(crit, update.getChangeList());
- }
- if (command instanceof Delete) {
- final Delete delete = (Delete)command;
- final Criteria crit = delete.getCriteria();
- if (crit == null) {
- //because we are non-transactional, just use a truncate
- int rows = table.truncate();
- return CollectionTupleSource.createUpdateCountTupleSource(rows);
- }
- return table.delete(crit);
- }
- }
- if (command instanceof Create) {
- Create create = (Create)command;
- String tempTableName = create.getTable().getCanonicalName();
- if(tempMetadataStore.getTempGroupID(tempTableName) != null) {
- throw new
QueryProcessingException(QueryExecPlugin.Util.getString("TempTableStore.table_exist_error",
tempTableName));//$NON-NLS-1$
- }
- addTempTable(tempTableName, create);
- return CollectionTupleSource.createUpdateCountTupleSource(0);
- }
- if (command instanceof Drop) {
- String tempTableName = ((Drop)command).getTable().getCanonicalName();
- removeTempTableByName(tempTableName);
- return CollectionTupleSource.createUpdateCountTupleSource(0);
- }
- return null;
- }
-
+
public void removeTempTables() {
for (String name : groupToTupleSourceID.keySet()) {
removeTempTableByName(name);
}
}
- private TempTable getOrCreateTempTable(String tempTableID, Command command, boolean
delegate) throws QueryProcessingException{
+ TempTable getOrCreateTempTable(String tempTableID, Command command, BufferManager
buffer, boolean delegate) throws QueryProcessingException{
TempTable tsID = groupToTupleSourceID.get(tempTableID);
if(tsID != null) {
return tsID;
@@ -213,8 +178,7 @@
Create create = new Create();
create.setTable(new GroupSymbol(tempTableID));
create.setColumns(columns);
- addTempTable(tempTableID, create);
- return groupToTupleSourceID.get(tempTableID);
+ return addTempTable(tempTableID, create, buffer);
}
public Set<String> getAllTempTables() {
Modified:
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -30,7 +30,6 @@
import org.junit.Ignore;
import org.junit.Test;
import org.teiid.client.plan.Annotation;
-import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.TestOptimizer;
@@ -39,7 +38,7 @@
import org.teiid.query.processor.relational.RelationalPlan;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.tempdata.TempTableStore;
-import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.query.util.CommandContext;
@SuppressWarnings("nls")
@@ -48,7 +47,7 @@
@Test public void testMaterializedTransformation() throws Exception {
String userSql = "SELECT MATVIEW.E1 FROM MATVIEW"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -65,7 +64,7 @@
@Test public void testMaterializedTransformationLoading() throws Exception {
String userSql = "SELECT MATVIEW.E1 INTO MatTable.MatStage FROM
MATVIEW"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -81,7 +80,7 @@
@Test public void testMaterializedTransformationNoCache() throws Exception {
String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE
MatView.MatView"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -98,7 +97,7 @@
@Test public void testMaterializedTransformationNoCache2() throws Exception {
String userSql = "SELECT MATVIEW.E1 FROM MATVIEW OPTION NOCACHE";
//$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -114,7 +113,7 @@
@Test public void testNoCacheInTransformation() throws Exception {
String userSql = "SELECT VGROUP.E1 FROM VGROUP"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -125,7 +124,7 @@
@Test public void testTableNoCacheDoesntCascade() throws Exception {
String userSql = "SELECT MATVIEW1.E1 FROM MATVIEW1 option nocache
matview.matview1"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -136,7 +135,7 @@
@Test public void testNoCacheCascade() throws Exception {
String userSql = "SELECT MATVIEW1.E1 FROM MATVIEW1 option nocache";
//$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
@@ -147,12 +146,12 @@
@Test public void testCacheHint() throws Exception {
String userSql = "SELECT * from vgroup2"; //$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
CommandContext cc = new CommandContext();
- cc.setGlobalTableStore(new
TempTableStore(BufferManagerFactory.getStandaloneBufferManager(), "SYSTEM"));
+ cc.setGlobalTableStore(new TempTableStore("SYSTEM"));
ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(),
analysis, true, cc);
TestOptimizer.checkAtomicQueries(new String[] {"SELECT
#MAT_MatView.VGroup2.X FROM #MAT_MatView.VGroup2"}, plan);
Collection<Annotation> annotations = analysis.getAnnotations();
@@ -164,12 +163,12 @@
@Test public void testCacheHintWithPk() throws Exception {
String userSql = "SELECT * from vgroup3 where x = 'foo'";
//$NON-NLS-1$
- QueryMetadataInterface metadata = FakeMetadataFactory.exampleMaterializedView();
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
Command command = helpGetCommand(userSql, metadata, null);
CommandContext cc = new CommandContext();
- cc.setGlobalTableStore(new
TempTableStore(BufferManagerFactory.getStandaloneBufferManager(), "SYSTEM"));
+ cc.setGlobalTableStore(new TempTableStore("SYSTEM"));
RelationalPlan plan = (RelationalPlan)TestOptimizer.getPlan(command, metadata,
getGenericFinder(), analysis, true, cc);
assertEquals(1f, plan.getRootNode().getEstimateNodeCardinality());
TestOptimizer.checkAtomicQueries(new String[] {"SELECT
#MAT_MatView.VGroup3.X, #MAT_MatView.VGroup3.y FROM #MAT_MatView.VGroup3 WHERE
#MAT_MatView.VGroup3.X = 'foo'"}, plan);
Modified: trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/test/java/org/teiid/query/processor/HardcodedDataManager.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -55,7 +55,7 @@
private boolean blockOnce;
// Collect all commands run against this class
- private Collection commandHistory = new ArrayList(); // Commands
+ private List commandHistory = new ArrayList(); // Commands
public HardcodedDataManager() {
this(true);
@@ -92,7 +92,7 @@
* @return
* @since 4.2
*/
- public Collection getCommandHistory() {
+ public List getCommandHistory() {
return this.commandHistory;
}
Added: trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
(rev 0)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (C) 2009 Red Hat, Inc.
+ * Licensed to Red Hat, Inc. under one or more contributor
+ * license agreements. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * 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;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.dqp.internal.process.SimpleQueryProcessorFactory;
+import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
+import org.teiid.query.tempdata.TempTableDataManager;
+import org.teiid.query.tempdata.TempTableStore;
+import org.teiid.query.unittest.RealMetadataFactory;
+import org.teiid.query.util.CommandContext;
+
+@SuppressWarnings("nls")
+public class TestMaterialization {
+
+ private TempMetadataAdapter metadata;
+ private TempTableDataManager dataManager;
+ private TempTableStore tempStore;
+ private TempTableStore globalStore;
+ private ProcessorPlan previousPlan;
+ private HardcodedDataManager hdm;
+
+ @Before public void setUp() {
+ tempStore = new TempTableStore("1"); //$NON-NLS-1$
+ globalStore = new TempTableStore("SYSTEM");
+ metadata = new TempMetadataAdapter(RealMetadataFactory.exampleMaterializedView(),
tempStore.getMetadataStore());
+ hdm = new HardcodedDataManager();
+ hdm.addData("SELECT matsrc.x FROM matsrc", new List[]
{Arrays.asList((String)null), Arrays.asList("one"),
Arrays.asList("two"), Arrays.asList("three")});
+ dataManager = new TempTableDataManager(hdm,
BufferManagerFactory.getStandaloneBufferManager());
+ }
+
+ private void execute(String sql, List[] expectedResults) throws Exception {
+ CommandContext cc = TestProcessor.createCommandContext();
+ cc.setTempTableStore(tempStore);
+ cc.setGlobalTableStore(globalStore);
+ cc.setMetadata(metadata);
+ CapabilitiesFinder finder = new DefaultCapabilitiesFinder();
+ previousPlan = TestProcessor.helpGetPlan(TestProcessor.helpParse(sql), metadata,
finder, cc);
+ cc.setQueryProcessorFactory(new
SimpleQueryProcessorFactory(BufferManagerFactory.getStandaloneBufferManager(),
dataManager, finder, null, metadata));
+ TestProcessor.doProcess(previousPlan, dataManager, expectedResults, cc);
+ }
+
+ @Test public void testPopulate() throws Exception {
+ execute("SELECT * from vgroup3 where x = 'one'", new List[]
{Arrays.asList("one", "zne")});
+ assertEquals(1, hdm.getCommandHistory().size());
+ execute("SELECT * from vgroup3 where x is null", new List[]
{Arrays.asList(null, null)});
+ assertEquals(1, hdm.getCommandHistory().size());
+ }
+
+}
Property changes on:
trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -85,6 +85,7 @@
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.util.VariableContext;
import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
+import org.teiid.query.tempdata.TempTableDataManager;
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.unittest.FakeMetadataFacade;
import org.teiid.query.unittest.FakeMetadataFactory;
@@ -228,10 +229,10 @@
bufferMgr.setConnectorBatchSize(context.getProcessorBatchSize());
context.getNextRand(0);
if (context.getTempTableStore() == null) {
- context.setTempTableStore(new TempTableStore(bufferMgr,
context.getConnectionID()));
+ context.setTempTableStore(new TempTableStore(context.getConnectionID()));
}
if (!(dataManager instanceof TempTableDataManager)) {
- dataManager = new TempTableDataManager(dataManager);
+ dataManager = new TempTableDataManager(dataManager, bufferMgr);
}
TupleBuffer id = null;
try {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -33,6 +33,7 @@
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.metadata.TempMetadataAdapter;
+import org.teiid.query.tempdata.TempTableDataManager;
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.unittest.FakeMetadataFactory;
import org.teiid.query.util.CommandContext;
@@ -55,11 +56,11 @@
}
@Before public void setUp() {
- tempStore = new TempTableStore(BufferManagerFactory.getStandaloneBufferManager(),
"1"); //$NON-NLS-1$
+ tempStore = new TempTableStore("1"); //$NON-NLS-1$
metadata = new TempMetadataAdapter(FakeMetadataFactory.example1Cached(),
tempStore.getMetadataStore());
FakeDataManager fdm = new FakeDataManager();
TestProcessor.sampleData1(fdm);
- dataManager = new TempTableDataManager(fdm);
+ dataManager = new TempTableDataManager(fdm,
BufferManagerFactory.getStandaloneBufferManager());
}
@Test public void testInsertWithQueryExpression() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java 2010-08-03
02:06:18 UTC (rev 2399)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFacade.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -776,9 +776,11 @@
}
@Override
- public boolean isPrimaryKey(Object metadataID) {
- ArgCheck.isInstanceOf(FakeMetadataObject.class, metadataID);
- FakeMetadataObject object = (FakeMetadataObject) metadataID;
- return object.getProperty(FakeMetadataObject.Props.KEY_TYPE) ==
FakeMetadataObject.TYPE_PRIMARY_KEY;
+ public Object getPrimaryKey(Object metadataID) {
+ Collection keys = getTypeOfKeysInGroup(metadataID,
FakeMetadataObject.TYPE_PRIMARY_KEY);
+ if (!keys.isEmpty()) {
+ return keys.iterator().next();
+ }
+ return null;
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -2066,110 +2066,7 @@
// Create the facade from the store
return new FakeMetadataFacade(store);
}
-
- /**
- * Metadata for Materialized Views
- * @return
- * @since 4.2
- */
- public static QueryMetadataInterface exampleMaterializedView() {
- FakeMetadataObject virtModel = createVirtualModel("MatView");
//$NON-NLS-1$
- FakeMetadataObject physModel = createPhysicalModel("MatTable");
//$NON-NLS-1$
- FakeMetadataObject physModel_virtSrc = createPhysicalModel("MatSrc");
//$NON-NLS-1$
-
- FakeMetadataObject physGroup = createPhysicalGroup("MatTable.MatTable",
physModel); //$NON-NLS-1$
- List physElements = createElements(physGroup,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- FakeMetadataObject physGroupStage =
createPhysicalGroup("MatTable.MatStage", physModel); //$NON-NLS-1$
- List physStageElements = createElements(physGroupStage,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- FakeMetadataObject physGroup1 =
createPhysicalGroup("MatTable.MatTable1", physModel); //$NON-NLS-1$
- List physElements1 = createElements(physGroup,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- FakeMetadataObject physGroupStage1 =
createPhysicalGroup("MatTable.MatStage1", physModel); //$NON-NLS-1$
- List physStageElements1 = createElements(physGroupStage,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- FakeMetadataObject physGroup_virtSrc =
createPhysicalGroup("MatSrc.MatSrc", physModel_virtSrc); //$NON-NLS-1$
- List physElements_virtSrc = createElements(physGroup_virtSrc,
- new String[] { "X" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- QueryNode virtTrans = new QueryNode("MatView.MatView", "SELECT x
as e1 FROM MatSrc.MatSrc"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject virtGroup = createVirtualGroup("MatView.MatView",
virtModel, virtTrans); //$NON-NLS-1$
- List virtElements = createElements(virtGroup,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- virtGroup.putProperty(FakeMetadataObject.Props.MAT_GROUP, physGroup);
- virtGroup.putProperty(FakeMetadataObject.Props.MAT_STAGE, physGroupStage);
-
- //add one virtual group that uses the materialized group in transformation with
NOCACHE option
- QueryNode vTrans = new QueryNode("MatView.VGroup", "SELECT e1 FROM
MatView.MatView option NOCACHE"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vGroup = createVirtualGroup("MatView.VGroup",
virtModel, vTrans); //$NON-NLS-1$
- List vElements = createElements(vGroup,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- QueryNode virtTrans1 = new QueryNode("MatView.MatView1", "SELECT
e1 FROM MatView.MatView where e1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject virtGroup1 = createVirtualGroup("MatView.MatView1",
virtModel, virtTrans1); //$NON-NLS-1$
- List virtElements1 = createElements(virtGroup1,
- new String[] { "e1" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- virtGroup1.putProperty(FakeMetadataObject.Props.MAT_GROUP, physGroup1);
- virtGroup1.putProperty(FakeMetadataObject.Props.MAT_STAGE, physGroupStage1);
-
- QueryNode vTrans2 = new QueryNode("MatView.VGroup2", "/* cache */
SELECT x FROM matsrc"); //$NON-NLS-1$ //$NON-NLS-2$
- FakeMetadataObject vGroup2 = createVirtualGroup("MatView.VGroup2",
virtModel, vTrans2); //$NON-NLS-1$
- List vElements2 = createElements(vGroup2,
- new String[] { "x" }, //$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING});
-
- QueryNode vTrans3 = new QueryNode("MatView.VGroup3", "/* cache */
SELECT x, 'z' || substring(x, 2) as y FROM matsrc"); //$NON-NLS-1$
//$NON-NLS-2$
- FakeMetadataObject vGroup3 = createVirtualGroup("MatView.VGroup3",
virtModel, vTrans3); //$NON-NLS-1$
- List vElements3 = createElements(vGroup3,
- new String[] { "x", "y" },
//$NON-NLS-1$
- new String[] {
DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING});
- FakeMetadataObject vGroup3pk = createKey("pk", vGroup3,
vElements3.subList(0, 1));
-
-
- FakeMetadataStore store = new FakeMetadataStore();
- store.addObject(virtModel);
- store.addObject(physModel);
- store.addObject(physModel_virtSrc);
- store.addObject(physGroup);
- store.addObjects(physElements);
- store.addObject(physGroupStage);
- store.addObjects(physStageElements);
- store.addObject(physGroup1);
- store.addObjects(physElements1);
- store.addObject(physGroupStage1);
- store.addObjects(physStageElements1);
- store.addObject(physGroup_virtSrc);
- store.addObjects(physElements_virtSrc);
- store.addObject(virtGroup);
- store.addObjects(virtElements);
- store.addObject(vGroup);
- store.addObjects(vElements);
- store.addObject(virtGroup1);
- store.addObjects(virtElements1);
- store.addObject(vGroup2);
- store.addObjects(vElements2);
- store.addObject(vGroup3);
- store.addObjects(vElements3);
- store.addObject(vGroup3pk);
- return new FakeMetadataFacade(store);
- }
-
public static VDBMetaData examplePrivatePhysicalModelVDB() {
VDBMetaData vdb = new VDBMetaData();
vdb.setName("example1");
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-03
02:06:18 UTC (rev 2399)
+++
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-03
04:32:09 UTC (rev 2400)
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import org.teiid.adminapi.impl.VDBMetaData;
@@ -32,6 +31,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.Column;
import org.teiid.metadata.ColumnSet;
+import org.teiid.metadata.KeyRecord;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
@@ -42,10 +42,11 @@
import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.sql.lang.SPParameter;
-
+@SuppressWarnings("nls")
public class RealMetadataFactory {
private static TransformationMetadata CACHED_BQT = exampleBQT();
@@ -157,111 +158,213 @@
List<Column> bqt1SmallAe = createElements(bqt1SmallA, elemNames,
elemTypes);
bqt1SmallAe.get(1).setNativeType("char"); //$NON-NLS-1$
- List bqt1SmallBe = createElements(bqt1SmallB, elemNames, elemTypes);
- List bqt1MediumAe = createElements(bqt1MediumA, elemNames, elemTypes);
- List bqt1MediumBe = createElements(bqt1MediumB, elemNames, elemTypes);
- List bqt2SmallAe = createElements(bqt2SmallA, elemNames, elemTypes);
- List bqt2SmallBe = createElements(bqt2SmallB, elemNames, elemTypes);
- List bqt2MediumAe = createElements(bqt2MediumA, elemNames, elemTypes);
- List bqt2MediumBe = createElements(bqt2MediumB, elemNames, elemTypes);
- List bqt3SmallAe = createElements(bqt3SmallA, elemNames, elemTypes);
- List bqt3SmallBe = createElements(bqt3SmallB, elemNames, elemTypes);
- List bqt3MediumAe = createElements(bqt3MediumA, elemNames, elemTypes);
- List bqt3MediumBe = createElements(bqt3MediumB, elemNames, elemTypes);
- List lobTable_elem = createElements(lobTable, new String[]
{"ClobValue"}, new String[] {DataTypeManager.DefaultDataTypes.CLOB});
//$NON-NLS-1$
+ createElements(bqt1SmallB, elemNames, elemTypes);
+ createElements(bqt1MediumA, elemNames, elemTypes);
+ createElements(bqt1MediumB, elemNames, elemTypes);
+ createElements(bqt2SmallA, elemNames, elemTypes);
+ createElements(bqt2SmallB, elemNames, elemTypes);
+ createElements(bqt2MediumA, elemNames, elemTypes);
+ createElements(bqt2MediumB, elemNames, elemTypes);
+ createElements(bqt3SmallA, elemNames, elemTypes);
+ createElements(bqt3SmallB, elemNames, elemTypes);
+ createElements(bqt3MediumA, elemNames, elemTypes);
+ createElements(bqt3MediumB, elemNames, elemTypes);
+ createElements(lobTable, new String[] {"ClobValue"}, new String[]
{DataTypeManager.DefaultDataTypes.CLOB}); //$NON-NLS-1$
// Create virtual elements
- List vqtg1e = createElements(vqtg1, elemNames, elemTypes);
- List vqtg2e = createElements(vqtg2, new String[] {"a12345"}, new
String[] {DataTypeManager.DefaultDataTypes.STRING}); //$NON-NLS-1$
- List vqtg15355e = createElements(vqtg15355, new String[] {"StringKey",
"BigIntegerValue"}, new String[] {DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
- List vqtg15355ae = createElements(vqtg15355a, new String[]
{"StringKey", "StringNum", "BigIntegerValue"}, new String[]
{DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
- List vqtg15355be = createElements(vqtg15355b, new String[] {"IntKey",
"BigIntegerValue"}, new String[] {DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
- List vqtg2589e = createElements(vqtg2589, elemNames, elemTypes);
- List vqtg2589ae = createElements(vqtg2589a, elemNames, elemTypes);
- List vqtg2589be = createElements(vqtg2589b, elemNames, elemTypes);
- List vqtg2589ce = createElements(vqtg2589c, elemNames, elemTypes);
- List vqtg2589de = createElements(vqtg2589d, elemNames, elemTypes);
- List vqtg2589fe = createElements(vqtg2589f, elemNames, elemTypes);
- List vqtg2589ge = createElements(vqtg2589g, elemNames, elemTypes);
- List vqtg2589he = createElements(vqtg2589h, elemNames, elemTypes);
- List vqtg2589ie = createElements(vqtg2589i, elemNames, elemTypes);
- List bvqtg1e = createElements(bvqtg1, elemNames, elemTypes);
- List bvqt2g1e = createElements(bvqt2g1, elemNames, elemTypes);
+ createElements(vqtg1, elemNames, elemTypes);
+ createElements(vqtg2, new String[] {"a12345"}, new String[]
{DataTypeManager.DefaultDataTypes.STRING}); //$NON-NLS-1$
+ createElements(vqtg15355, new String[] {"StringKey",
"BigIntegerValue"}, new String[] {DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
+ createElements(vqtg15355a, new String[] {"StringKey",
"StringNum", "BigIntegerValue"}, new String[]
{DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ createElements(vqtg15355b, new String[] {"IntKey",
"BigIntegerValue"}, new String[] {DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.BIG_INTEGER}); //$NON-NLS-1$ //$NON-NLS-2$
+ createElements(vqtg2589, elemNames, elemTypes);
+ createElements(vqtg2589a, elemNames, elemTypes);
+ createElements(vqtg2589b, elemNames, elemTypes);
+ createElements(vqtg2589c, elemNames, elemTypes);
+ createElements(vqtg2589d, elemNames, elemTypes);
+ createElements(vqtg2589f, elemNames, elemTypes);
+ createElements(vqtg2589g, elemNames, elemTypes);
+ createElements(vqtg2589h, elemNames, elemTypes);
+ createElements(vqtg2589i, elemNames, elemTypes);
+ createElements(bvqtg1, elemNames, elemTypes);
+ createElements(bvqt2g1, elemNames, elemTypes);
// Add stored procedure
Schema pm1 = createPhysicalModel("pm1", metadataStore); //$NON-NLS-1$
- ProcedureParameter rs1p1 = createParameter("intkey", 2,
ParameterInfo.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
- ColumnSet<Procedure> rs1 = createResultSet("rs1", pm1, new
String[] { "IntKey", "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcedureParameter rs1p1 = createParameter("intkey", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ ColumnSet<Procedure> rs1 = createResultSet("rs1", new String[] {
"IntKey", "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Procedure spTest5 = createStoredProcedure("spTest5", pm1,
Arrays.asList(rs1p1), "spTest5"); //$NON-NLS-1$ //$NON-NLS-2$
spTest5.setResultSet(rs1);
Schema pm2 = createPhysicalModel("pm2", metadataStore); //$NON-NLS-1$
- ProcedureParameter rs2p1 = createParameter("inkey", 2,
ParameterInfo.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
- ProcedureParameter rs2p2 = createParameter("outkey", 3,
ParameterInfo.OUT, DataTypeManager.DefaultDataTypes.INTEGER, null);
//$NON-NLS-1$
- ColumnSet<Procedure> rs2 = createResultSet("rs2", pm2, new
String[] { "IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcedureParameter rs2p1 = createParameter("inkey", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ ProcedureParameter rs2p2 = createParameter("outkey", ParameterInfo.OUT,
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ ColumnSet<Procedure> rs2 = createResultSet("rs2", new String[] {
"IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Procedure spTest8 = createStoredProcedure("spTest8", pm2,
Arrays.asList(rs2p1, rs2p2), "spTest8"); //$NON-NLS-1$ //$NON-NLS-2$
spTest8.setResultSet(rs2);
- ProcedureParameter rs2p2a = createParameter("outkey", 3,
ParameterInfo.OUT, DataTypeManager.DefaultDataTypes.INTEGER, null);
//$NON-NLS-1$
- ColumnSet<Procedure> rs2a = createResultSet("rs2", pm2, new
String[] { "IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcedureParameter rs2p2a = createParameter("outkey",
ParameterInfo.OUT, DataTypeManager.DefaultDataTypes.INTEGER);
//$NON-NLS-1$
+ ColumnSet<Procedure> rs2a = createResultSet("rs2", new String[] {
"IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Procedure spTest8a = createStoredProcedure("spTest8a", pm2,
Arrays.asList(rs2p2a), "spTest8a"); //$NON-NLS-1$ //$NON-NLS-2$
spTest8a.setResultSet(rs2a);
Schema pm4 = createPhysicalModel("pm4", metadataStore); //$NON-NLS-1$
- ProcedureParameter rs4p1 = createParameter("inkey", 2,
ParameterInfo.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
- ProcedureParameter rs4p2 = createParameter("ret", 1,
ParameterInfo.RETURN_VALUE, DataTypeManager.DefaultDataTypes.INTEGER, null);
//$NON-NLS-1$
- Procedure spTest9 = createStoredProcedure("spTest9", pm4,
Arrays.asList(rs4p1, rs4p2), "spTest9"); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcedureParameter rs4p1 = createParameter("inkey", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ ProcedureParameter rs4p2 = createParameter("ret",
ParameterInfo.RETURN_VALUE, DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ createStoredProcedure("spTest9", pm4, Arrays.asList(rs4p1, rs4p2),
"spTest9"); //$NON-NLS-1$ //$NON-NLS-2$
Schema pm3 = createPhysicalModel("pm3", metadataStore); //$NON-NLS-1$
- ProcedureParameter rs3p1 = createParameter("inkey", 2,
ParameterInfo.IN, DataTypeManager.DefaultDataTypes.INTEGER, null); //$NON-NLS-1$
- ProcedureParameter rs3p2 = createParameter("outkey", 3,
ParameterInfo.INOUT, DataTypeManager.DefaultDataTypes.INTEGER, null);
//$NON-NLS-1$
- ColumnSet<Procedure> rs3 = createResultSet("rs3", pm3, new
String[] { "IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ProcedureParameter rs3p1 = createParameter("inkey", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.INTEGER); //$NON-NLS-1$
+ ProcedureParameter rs3p2 = createParameter("outkey",
ParameterInfo.INOUT, DataTypeManager.DefaultDataTypes.INTEGER);
//$NON-NLS-1$
+ ColumnSet<Procedure> rs3 = createResultSet("rs3", new String[] {
"IntKey", "StringKey"}, new String[] {
DataTypeManager.DefaultDataTypes.INTEGER , DataTypeManager.DefaultDataTypes.STRING });
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Procedure spTest11 = createStoredProcedure("spTest11", pm3,
Arrays.asList(rs3p1, rs3p2), "spTest11"); //$NON-NLS-1$ //$NON-NLS-2$
spTest11.setResultSet(rs3);
//add virtual stored procedures
Schema mmspTest1 = createVirtualModel("mmspTest1", metadataStore);
//$NON-NLS-1$
- ColumnSet<Procedure> vsprs1 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ColumnSet<Procedure> vsprs1 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
QueryNode vspqn1 = new QueryNode("vsp1", "CREATE VIRTUAL PROCEDURE
BEGIN DECLARE integer x; LOOP ON (SELECT intkey FROM bqt1.smallA) AS intKeyCursor BEGIN x=
intKeyCursor.intkey - 1; END SELECT stringkey FROM bqt1.smalla where intkey=x; END");
//$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp1 = createVirtualProcedure("MMSP1", mmspTest1, null,
vspqn1); //$NON-NLS-1$
vsp1.setResultSet(vsprs1);
- ColumnSet<Procedure> vsprs2 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ColumnSet<Procedure> vsprs2 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
QueryNode vspqn2 = new QueryNode("vsp2", "CREATE VIRTUAL PROCEDURE
BEGIN DECLARE integer x; LOOP ON (SELECT intkey FROM bqt1.smallA) AS intKeyCursor1 BEGIN
LOOP ON (SELECT intkey FROM bqt1.smallB) AS intKeyCursor2 BEGIN x= intKeyCursor1.intkey -
intKeyCursor2.intkey; END END SELECT stringkey FROM bqt1.smalla where intkey=x;
END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp2 = createVirtualProcedure("MMSP2", mmspTest1, null,
vspqn2); //$NON-NLS-1$
vsp2.setResultSet(vsprs2);
- ColumnSet<Procedure> vsprs3 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ColumnSet<Procedure> vsprs3 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
QueryNode vspqn3 = new QueryNode("vsp3", "CREATE VIRTUAL PROCEDURE
BEGIN DECLARE integer x; LOOP ON (SELECT intkey FROM bqt1.smallA) AS intKeyCursor BEGIN x=
intKeyCursor.intkey - 1; if(x = 25) BEGIN BREAK; END ELSE BEGIN CONTINUE; END END SELECT
stringkey FROM bqt1.smalla where intkey=x; END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp3 = createVirtualProcedure("MMSP3", mmspTest1, null,
vspqn3); //$NON-NLS-1$
vsp3.setResultSet(vsprs3);
- ColumnSet<Procedure> vsprs4 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ColumnSet<Procedure> vsprs4 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
QueryNode vspqn4 = new QueryNode("vsp4", "CREATE VIRTUAL PROCEDURE
BEGIN DECLARE integer x; x=0; WHILE(x < 50) BEGIN x= x + 1; if(x = 25) BEGIN BREAK; END
ELSE BEGIN CONTINUE; END END SELECT stringkey FROM bqt1.smalla where intkey=x; END");
//$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp4 = createVirtualProcedure("MMSP4", mmspTest1, null,
vspqn4); //$NON-NLS-1$
vsp4.setResultSet(vsprs4);
- ColumnSet<Procedure> vsprs5 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
- ProcedureParameter vsp5p1 = createParameter("param1", 2,
ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING, null); //$NON-NLS-1$
+ ColumnSet<Procedure> vsprs5 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcedureParameter vsp5p1 = createParameter("param1", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$
QueryNode vspqn5 = new QueryNode("vsp5", "CREATE VIRTUAL PROCEDURE
BEGIN SELECT 0; END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp5 = createVirtualProcedure("MMSP5", mmspTest1,
Arrays.asList(vsp5p1), vspqn5); //$NON-NLS-1$
vsp5.setResultSet(vsprs5);
- ColumnSet<Procedure> vsprs6 = createResultSet("mmspTest1.vsprs1",
mmspTest1, new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
- ProcedureParameter vsp6p1 = createParameter("p1", 2, ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.STRING, null); //$NON-NLS-1$
+ ColumnSet<Procedure> vsprs6 = createResultSet("mmspTest1.vsprs1",
new String[] { "StringKey" }, new String[] {
DataTypeManager.DefaultDataTypes.STRING }); //$NON-NLS-1$ //$NON-NLS-2$
+ ProcedureParameter vsp6p1 = createParameter("p1", ParameterInfo.IN,
DataTypeManager.DefaultDataTypes.STRING); //$NON-NLS-1$
QueryNode vspqn6 = new QueryNode("vsp6", "CREATE VIRTUAL PROCEDURE
BEGIN SELECT 1; END"); //$NON-NLS-1$ //$NON-NLS-2$
Procedure vsp6 = createVirtualProcedure("MMSP6", mmspTest1,
Arrays.asList(vsp6p1), vspqn6); //$NON-NLS-1$
vsp6.setResultSet(vsprs6);
- CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
+ return createTransformationMetadata(metadataStore, "bqt");
+ }
+
+ private static TransformationMetadata createTransformationMetadata(
+ MetadataStore metadataStore, String vdbName) {
+ CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
VDBMetaData vdbMetaData = new VDBMetaData();
- vdbMetaData.setName("bqt"); //$NON-NLS-1$
+ vdbMetaData.setName(vdbName); //$NON-NLS-1$
vdbMetaData.setVersion(1);
for (Schema schema : metadataStore.getSchemas().values()) {
vdbMetaData.addModel(FakeMetadataFactory.createModel(schema.getName(),
schema.isPhysical()));
}
- return new TransformationMetadata(vdbMetaData, store, null, null);
+ return new TransformationMetadata(vdbMetaData, store, null, null);
+ }
+
+ /**
+ * Metadata for Materialized Views
+ * @return
+ * @since 4.2
+ */
+ public static QueryMetadataInterface exampleMaterializedView() {
+ MetadataStore metadataStore = new MetadataStore();
+ Schema virtModel = createVirtualModel("MatView", metadataStore);
//$NON-NLS-1$
+ Schema physModel = createPhysicalModel("MatTable", metadataStore);
//$NON-NLS-1$
+ Schema physModel_virtSrc = createPhysicalModel("MatSrc",
metadataStore); //$NON-NLS-1$
+
+ Table physGroup = createPhysicalGroup("MatTable", physModel);
//$NON-NLS-1$
+ createElements(physGroup,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ Table physGroupStage = createPhysicalGroup("MatStage", physModel);
//$NON-NLS-1$
+ createElements(physGroupStage,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ Table physGroup1 = createPhysicalGroup("MatTable1", physModel);
//$NON-NLS-1$
+ createElements(physGroup1,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ Table physGroupStage1 = createPhysicalGroup("MatStage1", physModel);
//$NON-NLS-1$
+ createElements(physGroupStage,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ Table physGroup_virtSrc = createPhysicalGroup("MatSrc",
physModel_virtSrc); //$NON-NLS-1$
+ createElements(physGroup_virtSrc,
+ new String[] { "X" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ QueryNode virtTrans = new QueryNode("MatView", "SELECT x as e1
FROM MatSrc.MatSrc"); //$NON-NLS-1$ //$NON-NLS-2$
+ Table virtGroup = createVirtualGroup("MatView", virtModel, virtTrans);
//$NON-NLS-1$
+ createElements(virtGroup,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ virtGroup.setMaterialized(true);
+ virtGroup.setMaterializedTable(physGroup);
+ virtGroup.setMaterializedStageTable(physGroupStage);
+
+ //add one virtual group that uses the materialized group in transformation with
NOCACHE option
+ QueryNode vTrans = new QueryNode("VGroup", "SELECT e1 FROM
MatView.MatView option NOCACHE"); //$NON-NLS-1$ //$NON-NLS-2$
+ Table vGroup = createVirtualGroup("VGroup", virtModel, vTrans);
//$NON-NLS-1$
+ createElements(vGroup,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ QueryNode virtTrans1 = new QueryNode("MatView1", "SELECT e1 FROM
MatView.MatView where e1 = 1"); //$NON-NLS-1$ //$NON-NLS-2$
+ Table virtGroup1 = createVirtualGroup("MatView1", virtModel,
virtTrans1); //$NON-NLS-1$
+ createElements(virtGroup1,
+ new String[] { "e1" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ virtGroup1.setMaterializedTable(physGroup1);
+ virtGroup1.setMaterializedStageTable(physGroupStage1);
+
+ QueryNode vTrans2 = new QueryNode("VGroup2", "/* cache */ SELECT x
FROM matsrc"); //$NON-NLS-1$ //$NON-NLS-2$
+ Table vGroup2 = createVirtualGroup("VGroup2", virtModel, vTrans2);
//$NON-NLS-1$
+ createElements(vGroup2,
+ new String[] { "x" }, //$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING});
+
+ QueryNode vTrans3 = new QueryNode("VGroup3", "/* cache */ SELECT
x, 'z' || substring(x, 2) as y FROM matsrc"); //$NON-NLS-1$
//$NON-NLS-2$
+ Table vGroup3 = createVirtualGroup("VGroup3", virtModel, vTrans3);
//$NON-NLS-1$
+ List<Column> vElements3 = createElements(vGroup3,
+ new String[] { "x", "y" },
//$NON-NLS-1$
+ new String[] {
DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING});
+
+ createKey("pk", vGroup3, vElements3.subList(0, 1));
+
+ return createTransformationMetadata(metadataStore, "");
}
+
+ /**
+ * Create primary key. The name will be used as the Object metadataID.
+ * @param name String name of key
+ * @param group the group for the key
+ * @param elements the elements of the key (will be used as if they were
+ * metadata IDs)
+ * @return key metadata object
+ */
+ public static KeyRecord createKey(String name, Table group, List<Column> elements)
{
+ KeyRecord key = new KeyRecord(org.teiid.metadata.KeyRecord.Type.Primary);
+ key.setName(name);
+ for (Column column : elements) {
+ key.addColumn(column);
+ }
+ group.setPrimaryKey(key);
+ return key;
+ }
/**
* Create a physical model with default settings.
@@ -316,23 +419,6 @@
}
/**
- * Create a temp group with default settings.
- * @param name Name of virtual group, must match model name
- * @param model Associated model
- * @param plan Appropriate query plan definition object for the temp group
- * @return FakeMetadataObject Metadata object for group
- */
- public static FakeMetadataObject createTempGroup(String name, FakeMetadataObject
model, Object plan) {
- FakeMetadataObject obj = new FakeMetadataObject(name, FakeMetadataObject.GROUP);
- obj.putProperty(FakeMetadataObject.Props.MODEL, model);
- obj.putProperty(FakeMetadataObject.Props.IS_VIRTUAL, Boolean.FALSE);
- obj.putProperty(FakeMetadataObject.Props.PLAN, plan);
- obj.putProperty(FakeMetadataObject.Props.UPDATE, Boolean.FALSE);
- obj.putProperty(FakeMetadataObject.Props.TEMP, Boolean.TRUE);
- return obj;
- }
-
- /**
* Create a virtual group that allows updates with default settings.
*/
public static Table createUpdatableVirtualGroup(String name, Schema model, QueryNode
plan) {
@@ -389,96 +475,9 @@
}
/**
- * Create index. The name will be used as the Object metadataID.
- * @param name String name of index
- * @param group the group for the index
- * @param elements the elements of the index (will be used as if they were
- * metadata IDs)
- * @return key metadata object
- */
- public static FakeMetadataObject createIndex(String name, FakeMetadataObject group,
List elements) {
- FakeMetadataObject obj = new FakeMetadataObject(name, FakeMetadataObject.KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_TYPE,
FakeMetadataObject.TYPE_INDEX);
- obj.putProperty(FakeMetadataObject.Props.KEY_ELEMENTS, elements);
- Collection keys = (Collection)group.getProperty(FakeMetadataObject.Props.KEYS);
- if (keys == null){
- keys = new ArrayList();
- group.putProperty(FakeMetadataObject.Props.KEYS, keys);
- }
- keys.add(obj);
- return obj;
- }
-
- /**
- * Create primary key. The name will be used as the Object metadataID.
- * @param name String name of key
- * @param group the group for the key
- * @param elements the elements of the key (will be used as if they were
- * metadata IDs)
- * @return key metadata object
- */
- public static FakeMetadataObject createKey(String name, FakeMetadataObject group, List
elements) {
- FakeMetadataObject obj = new FakeMetadataObject(name, FakeMetadataObject.KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_TYPE,
FakeMetadataObject.TYPE_PRIMARY_KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_ELEMENTS, elements);
- Collection keys = (Collection)group.getProperty(FakeMetadataObject.Props.KEYS);
- if (keys == null){
- keys = new ArrayList();
- group.putProperty(FakeMetadataObject.Props.KEYS, keys);
- }
- keys.add(obj);
- return obj;
- }
-
- /**
- * Create foreign key. The name will be used as the Object metadataID.
- * @param name String name of key
- * @param group the group for the key
- * @param elements the elements of the key (will be used as if they were
- * @param primaryKey referenced by this foreign key
- * metadata IDs)
- * @return key metadata object
- */
- public static FakeMetadataObject createForeignKey(String name, FakeMetadataObject
group, List elements, FakeMetadataObject primaryKey) {
- FakeMetadataObject obj = new FakeMetadataObject(name, FakeMetadataObject.KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_TYPE,
FakeMetadataObject.TYPE_FOREIGN_KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_ELEMENTS, elements);
- obj.putProperty(FakeMetadataObject.Props.REFERENCED_KEY, primaryKey);
- Collection keys = (Collection)group.getProperty(FakeMetadataObject.Props.KEYS);
- if (keys == null){
- keys = new ArrayList();
- group.putProperty(FakeMetadataObject.Props.KEYS, keys);
- }
- keys.add(obj);
- return obj;
- }
-
- /**
- * Create access pattern (currently an access pattern is implemented as a type of
key). The name will
- * be used as the Object metadataID.
- * @param name String name of key
- * @param group the group for the access pattern
- * @param elements the elements of the access pattern (will be used as if they were
- * metadata IDs)
- * @return Access pattern metadata object
- */
- public static FakeMetadataObject createAccessPattern(String name, FakeMetadataObject
group, List elements) {
- FakeMetadataObject obj = new FakeMetadataObject(name, FakeMetadataObject.KEY);
- obj.putProperty(FakeMetadataObject.Props.KEY_TYPE,
FakeMetadataObject.TYPE_ACCESS_PATTERN);
- obj.putProperty(FakeMetadataObject.Props.KEY_ELEMENTS, elements);
- Collection keys = (Collection)group.getProperty(FakeMetadataObject.Props.KEYS);
- if (keys == null){
- keys = new ArrayList();
- group.putProperty(FakeMetadataObject.Props.KEYS, keys);
- }
- keys.add(obj);
- return obj;
- }
-
- /**
* Create stored procedure parameter.
*/
- public static ProcedureParameter createParameter(String name, int index, int
direction, String type, Object rs) {
+ public static ProcedureParameter createParameter(String name, int direction, String
type) {
ProcedureParameter param = new ProcedureParameter();
param.setName(name);
switch (direction) {
@@ -542,7 +541,7 @@
/**
* Create a result set.
*/
- public static ColumnSet<Procedure> createResultSet(String name, Object model,
String[] colNames, String[] colTypes) {
+ public static ColumnSet<Procedure> createResultSet(String name, String[]
colNames, String[] colTypes) {
ColumnSet<Procedure> rs = new ColumnSet<Procedure>();
rs.setName(name);
for(Column column : createElements(rs, colNames, colTypes)) {
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2010-08-03 02:06:18
UTC (rev 2399)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2010-08-03 04:32:09
UTC (rev 2400)
@@ -35,6 +35,7 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.metadata.TransformationMetadata.Resource;
+import org.teiid.query.tempdata.TempTableStore;
import org.teiid.vdb.runtime.VDBKey;
@@ -78,7 +79,9 @@
private void update(VDBMetaData vdbMetadata) {
TransformationMetadata metadata = buildTransformationMetaData(vdbMetadata,
getVisibilityMap(), getMetadataStores(), getUDF());
vdbMetadata.addAttchment(QueryMetadataInterface.class, metadata);
- vdbMetadata.addAttchment(TransformationMetadata.class, metadata);
+ vdbMetadata.addAttchment(TransformationMetadata.class, metadata);
+ TempTableStore globalTables = new TempTableStore("SYSTEM"); //$NON-NLS-1$
+ vdbMetadata.addAttchment(TempTableStore.class, globalTables);
}
private TransformationMetadata buildTransformationMetaData(VDBMetaData vdb,
LinkedHashMap<String, Resource> visibilityMap, MetadataStoreGroup stores,
UDFMetaData udf) {