Author: shawkins
Date: 2010-07-26 10:17:53 -0400 (Mon, 26 Jul 2010)
New Revision: 2373
Added:
trunk/engine/src/main/java/org/teiid/query/metadata/CompositeMetadataStore.java
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
trunk/engine/src/test/java/org/teiid/query/metadata/
trunk/metadata/src/main/java/org/teiid/metadata/VdbConstants.java
Removed:
trunk/engine/src/main/java/org/teiid/metadata/
trunk/engine/src/test/java/org/teiid/metadata/
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/RuntimeMetadataImpl.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.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/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.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/metadata/TestTransformationMetadata.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
trunk/metadata/src/test/java/org/teiid/metadata/index/TestMultipleModelIndexes.java
trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java
Log:
TEIID-1167 adding primary key metadata TEIID-1166 fixing assertion error
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -36,12 +36,12 @@
import org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl;
import org.teiid.language.Command;
import org.teiid.metadata.Column;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.FakeMetadataFactory;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.TranslatorException;
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -30,12 +30,12 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.Command;
import org.teiid.metadata.Column;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.jdbc.TranslationHelper;
Modified:
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java
===================================================================
---
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/connectors/translator-ldap/src/test/java/org/teiid/translator/ldap/TestIQueryToLdapSearchParser.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -39,14 +39,14 @@
import org.teiid.language.Command;
import org.teiid.language.Select;
import org.teiid.metadata.Column;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.metadata.Column.SearchType;
+import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.ldap.IQueryToLdapSearchParser;
Modified:
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
===================================================================
---
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -31,13 +31,13 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.Select;
import org.teiid.metadata.Column;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.metadata.Column.SearchType;
+import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.salesforce.execution.visitors.JoinQueryVisitor;
import org.teiid.translator.salesforce.execution.visitors.SelectVisitor;
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/RuntimeMetadataImpl.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/RuntimeMetadataImpl.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/RuntimeMetadataImpl.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -27,9 +27,12 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.ArgCheck;
-import org.teiid.metadata.*;
-import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.metadata.StoredProcedureInfo;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.query.metadata.*;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.translator.TranslatorException;
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -60,7 +60,6 @@
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.Datatype;
import org.teiid.metadata.ForeignKey;
import org.teiid.metadata.KeyRecord;
@@ -68,7 +67,8 @@
import org.teiid.metadata.ProcedureParameter;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.processor.CollectionTupleSource;
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.QueryProcessor;
Copied: trunk/engine/src/main/java/org/teiid/query/metadata/CompositeMetadataStore.java
(from rev 2371,
trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java)
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/CompositeMetadataStore.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/CompositeMetadataStore.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -0,0 +1,145 @@
+/*
+ * 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.metadata;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.Table.Type;
+
+
+/**
+ * Aggregates the metadata from multiple stores.
+ * IMPORTANT: All strings queries should be in lower case.
+ */
+public class CompositeMetadataStore extends MetadataStore {
+
+
+ public CompositeMetadataStore(MetadataStore metadataStore) {
+ addMetadataStore(metadataStore);
+ }
+
+ public CompositeMetadataStore(List<MetadataStore> metadataStores) {
+ for (MetadataStore metadataStore : metadataStores) {
+ addMetadataStore(metadataStore);
+ }
+ }
+
+ public void addMetadataStore(MetadataStore metadataStore) {
+ this.schemas.putAll(metadataStore.getSchemas());
+ this.datatypes.addAll(metadataStore.getDatatypes());
+ }
+
+ public Schema getSchema(String fullName)
+ throws QueryMetadataException {
+ Schema result = getSchemas().get(fullName);
+ if (result == null) {
+ throw new
QueryMetadataException(fullName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ return result;
+ }
+
+ public Table findGroup(String fullName)
+ throws QueryMetadataException {
+ int index = fullName.indexOf(TransformationMetadata.DELIMITER_STRING);
+ if (index == -1) {
+ throw new
QueryMetadataException(fullName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ String schema = fullName.substring(0, index);
+ Table result = getSchema(schema).getTables().get(fullName.substring(index + 1));
+ if (result == null) {
+ throw new
QueryMetadataException(fullName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ return result;
+ }
+
+ /**
+ * TODO: this resolving mode allows partial matches of a full group name containing .
+ * @param partialGroupName
+ * @return
+ */
+ public Collection<Table> getGroupsForPartialName(String partialGroupName) {
+ List<Table> result = new LinkedList<Table>();
+ for (Schema schema : getSchemas().values()) {
+ for (Table t : schema.getTables().values()) {
+ String fullName = t.getFullName();
+ if (fullName.regionMatches(true, fullName.length() - partialGroupName.length(),
partialGroupName, 0, partialGroupName.length())) {
+ result.add(t);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Collection<Procedure> getStoredProcedure(String name)
+ throws TeiidComponentException, QueryMetadataException {
+ List<Procedure> result = new LinkedList<Procedure>();
+ int index = name.indexOf(TransformationMetadata.DELIMITER_STRING);
+ if (index > -1) {
+ String schema = name.substring(0, index);
+ Procedure proc = getSchema(schema).getProcedures().get(name.substring(index + 1));
+ if (proc != null) {
+ result.add(proc);
+ return result;
+ }
+ }
+ //assume it's a partial name
+ name = TransformationMetadata.DELIMITER_STRING + name;
+ for (Schema schema : getSchemas().values()) {
+ for (Procedure p : schema.getProcedures().values()) {
+ String fullName = p.getFullName();
+ if (fullName.regionMatches(true, fullName.length() - name.length(), name, 0,
name.length())) {
+ result.add(p);
+ }
+ }
+ }
+ if (result.isEmpty()) {
+ throw new
QueryMetadataException(name.substring(1)+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ return result;
+ }
+
+ /*
+ * The next method is a hold over from XML/UUID resolving and will perform poorly
+ */
+
+ public Collection<Table> getXMLTempGroups(Table tableRecord) {
+ ArrayList<Table> results = new ArrayList<Table>();
+ String namePrefix = tableRecord.getFullName() +
TransformationMetadata.DELIMITER_STRING;
+ for (Table table : tableRecord.getParent().getTables().values()) {
+ if (table.getTableType() == Type.XmlStagingTable &&
table.getName().startsWith(namePrefix)) {
+ results.add(table);
+ }
+ }
+ return results;
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/metadata/CompositeMetadataStore.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -23,6 +23,7 @@
package org.teiid.query.metadata;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -371,7 +372,11 @@
throws TeiidComponentException, QueryMetadataException {
if(groupID instanceof TempMetadataID) {
- return Collections.EMPTY_LIST;
+ TempMetadataID id = (TempMetadataID)groupID;
+ if (id.getPrimaryKey() == null) {
+ return Collections.emptyList();
+ }
+ return Arrays.asList(groupID);
}
return this.actualMetadata.getUniqueKeysInGroup(groupID);
}
@@ -396,6 +401,10 @@
public List getElementIDsInKey(Object keyID)
throws TeiidComponentException, QueryMetadataException {
+ if (keyID instanceof TempMetadataID) {
+ return ((TempMetadataID)keyID).getPrimaryKey();
+ }
+
return this.actualMetadata.getElementIDsInKey(keyID);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-07-24
03:25:41 UTC (rev 2372)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -51,6 +51,7 @@
private int cardinality = QueryMetadataInterface.UNKNOWN_CARDINALITY;
private LRUCache localCache;
private boolean scalarGroup;
+ private List<TempMetadataID> primaryKey;
/**
* Constructor for group form of metadata ID.
@@ -58,8 +59,7 @@
* @param elements List of TempMetadataID representing elements
*/
public TempMetadataID(String ID, List<TempMetadataID> elements) {
- this.ID = ID;
- this.elements = elements;
+ this(ID, elements, true, false);
}
/**
@@ -246,5 +246,13 @@
public void setScalarGroup(boolean scalarGroup) {
this.scalarGroup = scalarGroup;
}
+
+ public List<TempMetadataID> getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public void setPrimaryKey(List<TempMetadataID> primaryKey) {
+ this.primaryKey = primaryKey;
+ }
}
Copied: trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
(from rev 2371,
trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java)
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -0,0 +1,1070 @@
+/*
+ * 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.metadata;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.virtual.VirtualFile;
+import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.BlobImpl;
+import org.teiid.core.types.ClobImpl;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.InputStreamFactory;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.util.ArgCheck;
+import org.teiid.core.util.LRUCache;
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.core.util.StringUtil;
+import org.teiid.dqp.DQPPlugin;
+import org.teiid.metadata.AbstractMetadataRecord;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnSet;
+import org.teiid.metadata.Datatype;
+import org.teiid.metadata.ForeignKey;
+import org.teiid.metadata.KeyRecord;
+import org.teiid.metadata.Procedure;
+import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.Column.SearchType;
+import org.teiid.metadata.ProcedureParameter.Type;
+import org.teiid.query.QueryPlugin;
+import org.teiid.query.function.FunctionLibrary;
+import org.teiid.query.function.FunctionTree;
+import org.teiid.query.function.SystemFunctionManager;
+import org.teiid.query.function.UDFSource;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.mapping.xml.MappingDocument;
+import org.teiid.query.mapping.xml.MappingLoader;
+import org.teiid.query.mapping.xml.MappingNode;
+import org.teiid.query.sql.lang.SPParameter;
+
+
+/**
+ * Teiid's implementation of the QueryMetadataInterface that reads columns, groups,
models etc.
+ * from the metadata object model.
+ */
+public class TransformationMetadata extends BasicQueryMetadata implements Serializable {
+
+ private final class VirtualFileInputStreamFactory extends
+ InputStreamFactory {
+ private final VirtualFile f;
+
+ private VirtualFileInputStreamFactory(VirtualFile f) {
+ this.f = f;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return f.openStream();
+ }
+
+ @Override
+ public long getLength() {
+ try {
+ return f.getSize();
+ } catch (IOException e) {
+ }
+ return super.getLength();
+ }
+
+ @Override
+ public void free() throws IOException {
+ f.close();
+ }
+ }
+
+ public static class Resource {
+ public Resource(VirtualFile file, boolean visible) {
+ this.file = file;
+ this.visible = visible;
+ }
+ VirtualFile file;
+ boolean visible;
+ }
+
+ private static final long serialVersionUID = 1058627332954475287L;
+
+ /** Delimiter character used when specifying fully qualified entity names */
+ public static final char DELIMITER_CHAR = StringUtil.Constants.DOT_CHAR;
+ public static final String DELIMITER_STRING = String.valueOf(DELIMITER_CHAR);
+
+ // error message cached to avoid i18n lookup each time
+ public static String NOT_EXISTS_MESSAGE =
StringUtil.Constants.SPACE+DQPPlugin.Util.getString("TransformationMetadata.does_not_exist._1");
//$NON-NLS-1$
+
+ private static Properties EMPTY_PROPS = new Properties();
+
+ private final CompositeMetadataStore store;
+ private Map<String, Resource> vdbEntries;
+ private FunctionLibrary functionLibrary;
+ private VDBMetaData vdbMetaData;
+
+ /*
+ * TODO: move caching to jboss cache structure
+ */
+ private final Map<String, Object> metadataCache =
Collections.synchronizedMap(new LRUCache<String, Object>(250));
+ private final Map<String, Object> groupInfoCache =
Collections.synchronizedMap(new LRUCache<String, Object>(250));
+ private final Map<String, Collection<Table>> partialNameToFullNameCache =
Collections.synchronizedMap(new LRUCache<String, Collection<Table>>(1000));
+ private final Map<String, Collection<StoredProcedureInfo>> procedureCache
= Collections.synchronizedMap(new LRUCache<String,
Collection<StoredProcedureInfo>>(200));
+ /**
+ * TransformationMetadata constructor
+ * @param context Object containing the info needed to lookup metadta.
+ */
+ public TransformationMetadata(VDBMetaData vdbMetadata, final CompositeMetadataStore
store, Map<String, Resource> vdbEntries, Collection <FunctionMethod>
udfMethods) {
+ ArgCheck.isNotNull(store);
+ this.vdbMetaData = vdbMetadata;
+ this.store = store;
+ if (vdbEntries == null) {
+ this.vdbEntries = Collections.emptyMap();
+ } else {
+ this.vdbEntries = vdbEntries;
+ }
+ if (udfMethods == null) {
+ udfMethods = Collections.emptyList();
+ }
+ this.functionLibrary = new
FunctionLibrary(SystemFunctionManager.getSystemFunctions(), new FunctionTree(new
UDFSource(udfMethods)));
+ }
+
+ //==================================================================================
+ // I N T E R F A C E M E T H O D S
+ //==================================================================================
+
+ public Object getElementID(final String elementName) throws TeiidComponentException,
QueryMetadataException {
+ int columnIndex = elementName.lastIndexOf(TransformationMetadata.DELIMITER_STRING);
+ if (columnIndex == -1) {
+ throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ Table table = this.store.findGroup(elementName.substring(0, columnIndex));
+ String shortElementName = elementName.substring(columnIndex + 1);
+ for (Column column : (List<Column>)getElementIDsInGroupID(table)) {
+ if (column.getName().equalsIgnoreCase(shortElementName)) {
+ return column;
+ }
+ }
+ throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+
+ public Object getGroupID(final String groupName) throws TeiidComponentException,
QueryMetadataException {
+ return getMetadataStore().findGroup(groupName.toLowerCase());
+ }
+
+ public Collection getGroupsForPartialName(final String partialGroupName)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(partialGroupName);
+
+ Collection<Table> matches =
this.partialNameToFullNameCache.get(partialGroupName);
+
+ if (matches == null) {
+ String partialName = DELIMITER_CHAR + partialGroupName.toLowerCase();
+
+ matches = getMetadataStore().getGroupsForPartialName(partialName);
+
+ this.partialNameToFullNameCache.put(partialGroupName, matches);
+ }
+
+ if (matches.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ Collection<String> filteredResult = new ArrayList<String>(matches.size());
+ for (Table table : matches) {
+ if (vdbMetaData == null ||
vdbMetaData.getModel(table.getParent().getName()).isVisible()) {
+ filteredResult.add(table.getFullName());
+ }
+ }
+ return filteredResult;
+ }
+
+ public Object getModelID(final Object groupOrElementID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, groupOrElementID);
+ AbstractMetadataRecord metadataRecord = (AbstractMetadataRecord)
groupOrElementID;
+ AbstractMetadataRecord parent = metadataRecord.getParent();
+ if (parent instanceof Schema) {
+ return parent;
+ }
+ if (parent == null) {
+ throw createInvalidRecordTypeException(groupOrElementID);
+ }
+ parent = metadataRecord.getParent();
+ if (parent instanceof Schema) {
+ return parent;
+ }
+ throw createInvalidRecordTypeException(groupOrElementID);
+ }
+
+ public String getFullName(final Object metadataID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, metadataID);
+ AbstractMetadataRecord metadataRecord = (AbstractMetadataRecord) metadataID;
+ return metadataRecord.getFullName();
+ }
+
+ public String getFullElementName(final String fullGroupName, final String
shortElementName)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(fullGroupName);
+ ArgCheck.isNotEmpty(shortElementName);
+
+ return fullGroupName + DELIMITER_CHAR + shortElementName;
+ }
+
+ public String getShortElementName(final String fullElementName) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(fullElementName);
+ int index = fullElementName.lastIndexOf(DELIMITER_CHAR);
+ if(index >= 0) {
+ return fullElementName.substring(index+1);
+ }
+ return fullElementName;
+ }
+
+ /**
+ * Return the text portion of the fullElementName representing a group.
+ * That means that this should only return text that is part of the
+ * fullElementName and not look up new IDs or do much of anything fancy.
+ * This method is used by the resolver to decide which portion of a fully-
+ * qualified element name is the group name. It will compare whatever comes
+ * back with the actual group names and aliases in the query, which is
+ * why it is important not to introduce new metadata here. Also, returning
+ * null indicates that no portion of the fullElementName is a
+ * group name - that is ok as it will be resolved as an ambiguous element.
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getGroupName(java.lang.String)
+ */
+ public String getGroupName(final String fullElementName) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(fullElementName);
+
+ int index = fullElementName.lastIndexOf(DELIMITER_CHAR);
+ if(index >= 0) {
+ return fullElementName.substring(0, index);
+ }
+ return null;
+ }
+
+ public List getElementIDsInGroupID(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table)groupID).getColumns();
+ }
+
+ public Object getGroupIDForElementID(final Object elementID) throws
TeiidComponentException, QueryMetadataException {
+ if(elementID instanceof Column) {
+ Column columnRecord = (Column) elementID;
+ return this.getGroupID(getGroupName(columnRecord.getFullName()));
+ } else if(elementID instanceof ProcedureParameter){
+ ProcedureParameter columnRecord = (ProcedureParameter) elementID;
+ return this.getGroupID(getGroupName(columnRecord.getFullName()));
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public StoredProcedureInfo getStoredProcedureInfoForProcedure(final String
fullyQualifiedProcedureName)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isNotEmpty(fullyQualifiedProcedureName);
+ String lowerGroupName = fullyQualifiedProcedureName.toLowerCase();
+ Collection<StoredProcedureInfo> results =
this.procedureCache.get(lowerGroupName);
+
+ if (results == null) {
+ Collection<Procedure> procRecords =
getMetadataStore().getStoredProcedure(lowerGroupName);
+ results = new ArrayList<StoredProcedureInfo>(procRecords.size());
+ for (Procedure procRecord : procRecords) {
+ String procedureFullName = procRecord.getFullName();
+
+ // create the storedProcedure info object that would hold procedure's
metadata
+ StoredProcedureInfo procInfo = new StoredProcedureInfo();
+ procInfo.setProcedureCallableName(procedureFullName);
+ procInfo.setProcedureID(procRecord);
+
+ // modelID for the procedure
+ procInfo.setModelID(procRecord.getParent());
+
+ // get the parameter metadata info
+ for (ProcedureParameter paramRecord : procRecord.getParameters()) {
+ String runtimeType = paramRecord.getRuntimeType();
+ int direction =
this.convertParamRecordTypeToStoredProcedureType(paramRecord.getType());
+ // create a parameter and add it to the procedure object
+ SPParameter spParam = new SPParameter(paramRecord.getPosition(),
direction, paramRecord.getFullName());
+ spParam.setMetadataID(paramRecord);
+ spParam.setClassType(DataTypeManager.getDataTypeClass(runtimeType));
+ procInfo.addParameter(spParam);
+ }
+
+ // if the procedure returns a resultSet, obtain resultSet metadata
+ if(procRecord.getResultSet() != null) {
+ ColumnSet<Procedure> resultRecord = procRecord.getResultSet();
+ // resultSet is the last parameter in the procedure
+ int lastParamIndex = procInfo.getParameters().size() + 1;
+ SPParameter param = new SPParameter(lastParamIndex,
SPParameter.RESULT_SET, resultRecord.getFullName());
+ param.setClassType(java.sql.ResultSet.class);
+ param.setMetadataID(resultRecord);
+
+ for (Column columnRecord : resultRecord.getColumns()) {
+ String colType = columnRecord.getRuntimeType();
+ param.addResultSetColumn(columnRecord.getFullName(),
DataTypeManager.getDataTypeClass(colType), columnRecord);
+ }
+
+ procInfo.addParameter(param);
+ }
+
+ // if this is a virtual procedure get the procedure plan
+ if(procRecord.isVirtual()) {
+ QueryNode queryNode = new QueryNode(procedureFullName,
procRecord.getQueryPlan());
+ procInfo.setQueryPlan(queryNode);
+ }
+
+ //subtract 1, to match up with the server
+ procInfo.setUpdateCount(procRecord.getUpdateCount() -1);
+ results.add(procInfo);
+ }
+ this.procedureCache.put(lowerGroupName, results);
+ }
+
+ StoredProcedureInfo result = null;
+
+ for (StoredProcedureInfo storedProcedureInfo : results) {
+ Schema schema = (Schema)storedProcedureInfo.getModelID();
+ if(vdbMetaData == null || vdbMetaData.getModel(schema.getName()).isVisible()){
+ if (result != null) {
+ throw new
QueryMetadataException(QueryPlugin.Util.getString("ambiguous_procedure",
fullyQualifiedProcedureName)); //$NON-NLS-1$
+ }
+ result = storedProcedureInfo;
+ }
+ }
+
+ if (result == null) {
+ throw new QueryMetadataException(fullyQualifiedProcedureName+NOT_EXISTS_MESSAGE);
+ }
+
+ return result;
+ }
+
+ /**
+ * Method to convert the parameter type returned from a ProcedureParameterRecord
+ * to the parameter type expected by StoredProcedureInfo
+ * @param parameterType
+ * @return
+ */
+ private int convertParamRecordTypeToStoredProcedureType(final ProcedureParameter.Type
parameterType) {
+ switch (parameterType) {
+ case In : return SPParameter.IN;
+ case Out : return SPParameter.OUT;
+ case InOut : return SPParameter.INOUT;
+ case ReturnValue : return SPParameter.RETURN_VALUE;
+ default :
+ return -1;
+ }
+ }
+
+ public String getElementType(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getRuntimeType();
+ } else if(elementID instanceof ProcedureParameter){
+ return ((ProcedureParameter) elementID).getRuntimeType();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public Object getDefaultValue(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getDefaultValue();
+ } else if(elementID instanceof ProcedureParameter){
+ return ((ProcedureParameter) elementID).getDefaultValue();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public Object getMinimumValue(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getMinimumValue();
+ } else if(elementID instanceof ProcedureParameter){
+ return null;
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public Object getMaximumValue(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getMaximumValue();
+ } else if(elementID instanceof ProcedureParameter){
+ return null;
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public boolean isVirtualGroup(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table) groupID).isVirtual();
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#isProcedureInputElement(java.lang.Object)
+ * @since 4.2
+ */
+ public boolean isProcedure(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ if(groupID instanceof Procedure) {
+ return true;
+ }
+ if(groupID instanceof Table){
+ return false;
+ }
+ throw createInvalidRecordTypeException(groupID);
+ }
+
+ public boolean isVirtualModel(final Object modelID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Schema.class, modelID);
+ Schema modelRecord = (Schema) modelID;
+ return !modelRecord.isPhysical();
+ }
+
+ public QueryNode getVirtualPlan(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+
+ Table tableRecord = (Table) groupID;
+ if (!tableRecord.isVirtual()) {
+ throw new
QueryMetadataException(DQPPlugin.Util.getString("TransformationMetadata.QueryPlan_could_not_be_found_for_physical_group__6")+tableRecord.getFullName());
//$NON-NLS-1$
+ }
+ String transQuery = tableRecord.getSelectTransformation();
+ QueryNode queryNode = new QueryNode(tableRecord.getFullName(), transQuery);
+
+ // get any bindings and add them onto the query node
+ List bindings = tableRecord.getBindings();
+ if(bindings != null) {
+ for(Iterator bindIter = bindings.iterator();bindIter.hasNext();) {
+ queryNode.addBinding((String)bindIter.next());
+ }
+ }
+
+ return queryNode;
+ }
+
+ public String getInsertPlan(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecordImpl = (Table)groupID;
+ if (!tableRecordImpl.isVirtual()) {
+ throw new
QueryMetadataException(DQPPlugin.Util.getString("TransformationMetadata.InsertPlan_could_not_be_found_for_physical_group__8")+tableRecordImpl.getFullName());
//$NON-NLS-1$
+ }
+ return ((Table)groupID).getInsertPlan();
+ }
+
+ public String getUpdatePlan(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecordImpl = (Table)groupID;
+ if (!tableRecordImpl.isVirtual()) {
+ throw new
QueryMetadataException(DQPPlugin.Util.getString("TransformationMetadata.InsertPlan_could_not_be_found_for_physical_group__10")+tableRecordImpl.getFullName());
//$NON-NLS-1$
+ }
+ return ((Table)groupID).getUpdatePlan();
+ }
+
+ public String getDeletePlan(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecordImpl = (Table)groupID;
+ if (!tableRecordImpl.isVirtual()) {
+ throw new
QueryMetadataException(DQPPlugin.Util.getString("TransformationMetadata.DeletePlan_could_not_be_found_for_physical_group__12")+tableRecordImpl.getFullName());
//$NON-NLS-1$
+ }
+ return ((Table)groupID).getDeletePlan();
+ }
+
+ public boolean modelSupports(final Object modelID, final int modelConstant)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Schema.class, modelID);
+
+ switch(modelConstant) {
+ default:
+ throw new
UnsupportedOperationException(DQPPlugin.Util.getString("TransformationMetadata.Unknown_support_constant___12")
+ modelConstant); //$NON-NLS-1$
+ }
+ }
+
+ public boolean groupSupports(final Object groupID, final int groupConstant)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+
+ switch(groupConstant) {
+ case SupportConstants.Group.UPDATE:
+ return tableRecord.supportsUpdate();
+ default:
+ throw new
UnsupportedOperationException(DQPPlugin.Util.getString("TransformationMetadata.Unknown_support_constant___12")
+ groupConstant); //$NON-NLS-1$
+ }
+ }
+
+ public boolean elementSupports(final Object elementID, final int elementConstant)
+ throws TeiidComponentException, QueryMetadataException {
+
+ if(elementID instanceof Column) {
+ Column columnRecord = (Column) elementID;
+ switch(elementConstant) {
+ case SupportConstants.Element.NULL:
+ return columnRecord.getNullType() == NullType.Nullable;
+ case SupportConstants.Element.NULL_UNKNOWN:
+ return columnRecord.getNullType() == NullType.Unknown;
+ case SupportConstants.Element.SEARCHABLE_COMPARE:
+ return (columnRecord.getSearchType() == SearchType.Searchable ||
columnRecord.getSearchType() == SearchType.All_Except_Like);
+ case SupportConstants.Element.SEARCHABLE_LIKE:
+ return (columnRecord.getSearchType() == SearchType.Searchable ||
columnRecord.getSearchType() == SearchType.Like_Only);
+ case SupportConstants.Element.SELECT:
+ return columnRecord.isSelectable();
+ case SupportConstants.Element.UPDATE:
+ return columnRecord.isUpdatable();
+ case SupportConstants.Element.DEFAULT_VALUE:
+ Object defaultValue = columnRecord.getDefaultValue();
+ if(defaultValue == null) {
+ return false;
+ }
+ return true;
+ case SupportConstants.Element.AUTO_INCREMENT:
+ return columnRecord.isAutoIncremented();
+ case SupportConstants.Element.CASE_SENSITIVE:
+ return columnRecord.isCaseSensitive();
+ case SupportConstants.Element.SIGNED:
+ return columnRecord.isSigned();
+ default:
+ throw new
UnsupportedOperationException(DQPPlugin.Util.getString("TransformationMetadata.Unknown_support_constant___12")
+ elementConstant); //$NON-NLS-1$
+ }
+ } else if(elementID instanceof ProcedureParameter) {
+ ProcedureParameter columnRecord = (ProcedureParameter) elementID;
+ switch(elementConstant) {
+ case SupportConstants.Element.NULL:
+ return columnRecord.getNullType() == NullType.Nullable;
+ case SupportConstants.Element.NULL_UNKNOWN:
+ return columnRecord.getNullType() == NullType.Unknown;
+ case SupportConstants.Element.SEARCHABLE_COMPARE:
+ case SupportConstants.Element.SEARCHABLE_LIKE:
+ return false;
+ case SupportConstants.Element.SELECT:
+ return columnRecord.getType() != Type.In;
+ case SupportConstants.Element.UPDATE:
+ return false;
+ case SupportConstants.Element.DEFAULT_VALUE:
+ Object defaultValue = columnRecord.getDefaultValue();
+ if(defaultValue == null) {
+ return false;
+ }
+ return true;
+ case SupportConstants.Element.AUTO_INCREMENT:
+ return false;
+ case SupportConstants.Element.CASE_SENSITIVE:
+ return false;
+ case SupportConstants.Element.SIGNED:
+ return true;
+ default:
+ throw new
UnsupportedOperationException(DQPPlugin.Util.getString("TransformationMetadata.Unknown_support_constant___12")
+ elementConstant); //$NON-NLS-1$
+ }
+
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ private IllegalArgumentException createInvalidRecordTypeException(Object elementID)
{
+ return new
IllegalArgumentException(DQPPlugin.Util.getString("TransformationMetadata.Invalid_type",
elementID.getClass().getName())); //$NON-NLS-1$
+ }
+
+ public int getMaxSetSize(final Object modelID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Schema.class, modelID);
+ return 0;
+ }
+
+ public Collection getIndexesInGroup(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table)groupID).getIndexes();
+ }
+
+ public Collection getUniqueKeysInGroup(final Object groupID)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecordImpl = (Table)groupID;
+ ArrayList<ColumnSet> result = new
ArrayList<ColumnSet>(tableRecordImpl.getUniqueKeys());
+ if (tableRecordImpl.getPrimaryKey() != null) {
+ result.add(tableRecordImpl.getPrimaryKey());
+ }
+ for (KeyRecord key : tableRecordImpl.getIndexes()) {
+ if (key.getType() == KeyRecord.Type.Index) {
+ result.add(key);
+ }
+ }
+ return result;
+ }
+
+ public Collection getForeignKeysInGroup(final Object groupID)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table)groupID).getForeignKeys();
+ }
+
+ public Object getPrimaryKeyIDForForeignKeyID(final Object foreignKeyID)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(ForeignKey.class, foreignKeyID);
+ ForeignKey fkRecord = (ForeignKey) foreignKeyID;
+ return fkRecord.getPrimaryKey();
+ }
+
+ public Collection getAccessPatternsInGroup(final Object groupID)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table)groupID).getAccessPatterns();
+ }
+
+ public List getElementIDsInIndex(final Object index) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(ColumnSet.class, index);
+ return ((ColumnSet)index).getColumns();
+ }
+
+ public List getElementIDsInKey(final Object key) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(ColumnSet.class, key);
+ return ((ColumnSet)key).getColumns();
+ }
+
+ public List getElementIDsInAccessPattern(final Object accessPattern)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(ColumnSet.class, accessPattern);
+ return ((ColumnSet)accessPattern).getColumns();
+ }
+
+ public boolean isXMLGroup(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+
+ Table tableRecord = (Table) groupID;
+ return tableRecord.getTableType() == Table.Type.Document;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#hasMaterialization(java.lang.Object)
+ * @since 4.2
+ */
+ public boolean hasMaterialization(final Object groupID) throws
TeiidComponentException,
+ QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+ return tableRecord.isMaterialized();
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getMaterialization(java.lang.Object)
+ * @since 4.2
+ */
+ public Object getMaterialization(final Object groupID) throws
TeiidComponentException,
+ QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+ if(tableRecord.isMaterialized()) {
+ return tableRecord.getMaterializedTable();
+ }
+ return null;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getMaterializationStage(java.lang.Object)
+ * @since 4.2
+ */
+ public Object getMaterializationStage(final Object groupID) throws
TeiidComponentException,
+ QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+ if(tableRecord.isMaterialized()) {
+ return tableRecord.getMaterializedStageTable();
+ }
+ return null;
+ }
+
+ public MappingNode getMappingNode(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+
+ Table tableRecord = (Table) groupID;
+ final String groupName = tableRecord.getFullName();
+ if(tableRecord.isVirtual()) {
+ // get mappin transform
+ String document = tableRecord.getSelectTransformation();
+ InputStream inputStream = new ByteArrayInputStream(document.getBytes());
+ MappingLoader reader = new MappingLoader();
+ MappingDocument mappingDoc = null;
+ try{
+ mappingDoc = reader.loadDocument(inputStream);
+ mappingDoc.setName(groupName);
+ } catch (Exception e){
+ throw new TeiidComponentException(e,
DQPPlugin.Util.getString("TransformationMetadata.Error_trying_to_read_virtual_document_{0},_with_body__n{1}_1",
groupName, mappingDoc)); //$NON-NLS-1$
+ } finally {
+ try {
+ inputStream.close();
+ } catch(Exception e) {}
+ }
+ return (MappingDocument)mappingDoc.clone();
+ }
+
+ return null;
+ }
+
+ /**
+ * @see org.teiid.query.metadata.QueryMetadataInterface#getVirtualDatabaseName()
+ */
+ public String getVirtualDatabaseName() throws TeiidComponentException,
QueryMetadataException {
+ if (vdbMetaData == null) {
+ return null;
+ }
+ return vdbMetaData.getName();
+ }
+
+ public int getVirtualDatabaseVersion() {
+ if (vdbMetaData == null) {
+ return 0;
+ }
+ return vdbMetaData.getVersion();
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getXMLTempGroups(java.lang.Object)
+ */
+ public Collection getXMLTempGroups(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+
+ if(tableRecord.getTableType() == Table.Type.Document) {
+ return this.store.getXMLTempGroups(tableRecord);
+ }
+ return Collections.EMPTY_SET;
+ }
+
+ public int getCardinality(final Object groupID) throws TeiidComponentException,
QueryMetadataException {
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ return ((Table) groupID).getCardinality();
+ }
+
+ public List<SQLXMLImpl> getXMLSchemas(final Object groupID) throws
TeiidComponentException, QueryMetadataException {
+
+ ArgCheck.isInstanceOf(Table.class, groupID);
+ Table tableRecord = (Table) groupID;
+
+ // lookup transformation record for the group
+ String groupName = tableRecord.getFullName();
+
+ // get the schema Paths
+ List<String> schemaPaths = tableRecord.getSchemaPaths();
+
+ List<SQLXMLImpl> schemas = new LinkedList<SQLXMLImpl>();
+ if (schemaPaths == null) {
+ return schemas;
+ }
+ File f = new File(tableRecord.getResourcePath());
+ String path = f.getParent();
+ if (File.separatorChar != '/') {
+ path = path.replace(File.separatorChar, '/');
+ }
+ for (String string : schemaPaths) {
+ SQLXMLImpl schema = getVDBResourceAsSQLXML(string);
+
+ if (schema == null) {
+ schema = getVDBResourceAsSQLXML(path + '/' + string);
+ }
+
+ if (schema == null) {
+ throw new
TeiidComponentException(DQPPlugin.Util.getString("TransformationMetadata.Error_trying_to_read_schemas_for_the_document/table____1")+groupName);
//$NON-NLS-1$
+ }
+ schemas.add(schema);
+ }
+
+ return schemas;
+ }
+
+ public String getNameInSource(final Object metadataID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, metadataID);
+ return ((AbstractMetadataRecord) metadataID).getNameInSource();
+ }
+
+ public int getElementLength(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getLength();
+ } else if(elementID instanceof ProcedureParameter){
+ return ((ProcedureParameter) elementID).getLength();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public int getPosition(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getPosition();
+ } else if(elementID instanceof ProcedureParameter) {
+ return ((ProcedureParameter) elementID).getPosition();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public int getPrecision(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getPrecision();
+ } else if(elementID instanceof ProcedureParameter) {
+ return ((ProcedureParameter) elementID).getPrecision();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public int getRadix(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getRadix();
+ } else if(elementID instanceof ProcedureParameter) {
+ return ((ProcedureParameter) elementID).getRadix();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public String getFormat(Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getFormat();
+ }
+ throw createInvalidRecordTypeException(elementID);
+ }
+
+ public int getScale(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getScale();
+ } else if(elementID instanceof ProcedureParameter) {
+ return ((ProcedureParameter) elementID).getScale();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public int getDistinctValues(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getDistinctValues();
+ } else if(elementID instanceof ProcedureParameter) {
+ return -1;
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public int getNullValues(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getNullValues();
+ } else if(elementID instanceof ProcedureParameter) {
+ return -1;
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public String getNativeType(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ if(elementID instanceof Column) {
+ return ((Column) elementID).getNativeType();
+ } else if(elementID instanceof ProcedureParameter) {
+ return null;
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ public Properties getExtensionProperties(final Object metadataID) throws
TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, metadataID);
+ AbstractMetadataRecord metadataRecord = (AbstractMetadataRecord) metadataID;
+ Map<String, String> result = metadataRecord.getProperties();
+ if (result == null) {
+ return EMPTY_PROPS;
+ }
+ Properties p = new Properties();
+ p.putAll(result);
+ return p;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.BasicQueryMetadata#getBinaryVDBResource(java.lang.String)
+ * @since 4.3
+ */
+ public byte[] getBinaryVDBResource(String resourcePath) throws
TeiidComponentException, QueryMetadataException {
+ final VirtualFile f = getFile(resourcePath);
+ if (f == null) {
+ return null;
+ }
+ try {
+ return ObjectConverterUtil.convertToByteArray(f.openStream());
+ } catch (IOException e) {
+ throw new TeiidComponentException(e);
+ }
+ }
+
+ public ClobImpl getVDBResourceAsClob(String resourcePath) {
+ final VirtualFile f = getFile(resourcePath);
+ if (f == null) {
+ return null;
+ }
+ return new ClobImpl(new VirtualFileInputStreamFactory(f), -1);
+ }
+
+ public SQLXMLImpl getVDBResourceAsSQLXML(String resourcePath) {
+ final VirtualFile f = getFile(resourcePath);
+ if (f == null) {
+ return null;
+ }
+ return new SQLXMLImpl(new VirtualFileInputStreamFactory(f));
+ }
+
+ public BlobImpl getVDBResourceAsBlob(String resourcePath) {
+ final VirtualFile f = getFile(resourcePath);
+ if (f == null) {
+ return null;
+ }
+ return new BlobImpl(new VirtualFileInputStreamFactory(f));
+ }
+
+ private VirtualFile getFile(String resourcePath) {
+ if (resourcePath == null) {
+ return null;
+ }
+ Resource r = this.vdbEntries.get(resourcePath);
+ if (r != null && r.visible) {
+ return r.file;
+ }
+ return null;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.BasicQueryMetadata#getCharacterVDBResource(java.lang.String)
+ * @since 4.3
+ */
+ public String getCharacterVDBResource(String resourcePath) throws
TeiidComponentException, QueryMetadataException {
+ try {
+ byte[] bytes = getBinaryVDBResource(resourcePath);
+ if (bytes == null) {
+ return null;
+ }
+ return ObjectConverterUtil.convertToString(new ByteArrayInputStream(bytes));
+ } catch (IOException e) {
+ throw new TeiidComponentException(e);
+ }
+ }
+
+ public CompositeMetadataStore getMetadataStore() {
+ return this.store;
+ }
+
+ /**
+ * @see org.teiid.query.metadata.BasicQueryMetadata#getVDBResourcePaths()
+ * @since 4.3
+ */
+ public String[] getVDBResourcePaths() throws TeiidComponentException,
QueryMetadataException {
+ LinkedList<String> paths = new LinkedList<String>();
+ for (Map.Entry<String, Resource> entry : this.vdbEntries.entrySet()) {
+ if (entry.getValue().visible) {
+ paths.add(entry.getKey());
+ }
+ }
+ return paths.toArray(new String[paths.size()]);
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getModeledType(java.lang.Object)
+ * @since 5.0
+ */
+ public String getModeledType(final Object elementID) throws TeiidComponentException,
QueryMetadataException {
+ Datatype record = getDatatypeRecord(elementID);
+ if (record != null) {
+ return record.getDatatypeID();
+ }
+ return null;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getModeledBaseType(java.lang.Object)
+ * @since 5.0
+ */
+ public String getModeledBaseType(final Object elementID) throws
TeiidComponentException, QueryMetadataException {
+ Datatype record = getDatatypeRecord(elementID);
+ if (record != null) {
+ return record.getBasetypeID();
+ }
+ return null;
+ }
+
+ /**
+ * @see
org.teiid.query.metadata.QueryMetadataInterface#getModeledPrimitiveType(java.lang.Object)
+ * @since 5.0
+ */
+ public String getModeledPrimitiveType(final Object elementID) throws
TeiidComponentException, QueryMetadataException {
+ Datatype record = getDatatypeRecord(elementID);
+ if (record != null) {
+ return record.getPrimitiveTypeID();
+ }
+ return null;
+ }
+
+ private Datatype getDatatypeRecord(final Object elementID) {
+ if (elementID instanceof Column) {
+ return ((Column)elementID).getDatatype();
+ } else if (elementID instanceof ProcedureParameter) {
+ return ((ProcedureParameter)elementID).getDatatype();
+ } else {
+ throw createInvalidRecordTypeException(elementID);
+ }
+ }
+
+ @Override
+ public Object addToMetadataCache(Object metadataID, String key, Object value)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, metadataID);
+ boolean groupInfo = key.startsWith(GroupInfo.CACHE_PREFIX);
+ key = getCacheKey(key, (AbstractMetadataRecord)metadataID);
+ if (groupInfo) {
+ return this.groupInfoCache.put(key, value);
+ }
+ return this.metadataCache.put(key, value);
+ }
+
+ @Override
+ public Object getFromMetadataCache(Object metadataID, String key)
+ throws TeiidComponentException, QueryMetadataException {
+ ArgCheck.isInstanceOf(AbstractMetadataRecord.class, metadataID);
+ boolean groupInfo = key.startsWith(GroupInfo.CACHE_PREFIX);
+ key = getCacheKey(key, (AbstractMetadataRecord)metadataID);
+ if (groupInfo) {
+ return this.groupInfoCache.get(key);
+ }
+ return this.metadataCache.get(key);
+ }
+
+ private String getCacheKey(String key, AbstractMetadataRecord record) {
+ return record.getUUID() + "/" + key; //$NON-NLS-1$
+ }
+
+ @Override
+ public FunctionLibrary getFunctionLibrary() {
+ return this.functionLibrary;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -36,6 +36,7 @@
import org.teiid.core.id.IntegerID;
import org.teiid.core.id.IntegerIDFactory;
import org.teiid.core.util.Assertion;
+import org.teiid.language.TableReference;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -83,6 +84,7 @@
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.TableFunctionReference;
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.SetQuery.Operation;
@@ -90,6 +92,7 @@
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.symbol.SingleElementSymbol;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.sql.visitor.GroupCollectorVisitor;
@@ -377,6 +380,7 @@
XMLTableNode xtn = new XMLTableNode(getID());
//we handle the projection filtering once here rather than repeating the
//path analysis on a per plan basis
+ updateGroupName(node, xt);
Map elementMap = RelationalNode.createLookupMap(xt.getProjectedSymbols());
List cols = (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS);
int[] projectionIndexes = RelationalNode.getProjectionIndexes(elementMap, cols);
@@ -392,7 +396,9 @@
}
if (source instanceof TextTable) {
TextTableNode ttn = new TextTableNode(getID());
- ttn.setTable((TextTable)source);
+ TextTable tt = (TextTable)source;
+ updateGroupName(node, tt);
+ ttn.setTable(tt);
processNode = ttn;
break;
}
@@ -447,6 +453,14 @@
return processNode;
}
+ private void updateGroupName(PlanNode node, TableFunctionReference tt) {
+ String groupName = node.getGroups().iterator().next().getName();
+ tt.getGroupSymbol().setName(groupName);
+ for (ElementSymbol symbol : tt.getProjectedSymbols()) {
+ symbol.setName(groupName + SingleElementSymbol.SEPARATOR + symbol.getShortName());
+ }
+ }
+
private RelationalNode correctProjectionInternalTables(PlanNode node,
AccessNode aNode, Query
query) throws QueryMetadataException,
TeiidComponentException {
Modified:
trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/main/java/org/teiid/query/resolver/command/TempTableResolver.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -22,6 +22,7 @@
package org.teiid.query.resolver.command;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -77,15 +78,25 @@
//if we get here then either the group does not exist or has already been
defined as a temp table
//if it has been defined as a temp table, that's ok we'll use this as
the new definition and throw an
//exception at runtime if the user has not dropped the previous table yet
- ResolverUtil.addTempTable(metadata, group, create.getColumns());
-
- ResolverUtil.resolveGroup(((Create)command).getTable(), metadata);
+ TempMetadataID tempTable = ResolverUtil.addTempTable(metadata, group,
create.getColumns());
+ ResolverUtil.resolveGroup(create.getTable(), metadata);
Set<GroupSymbol> groups = new HashSet<GroupSymbol>();
- groups.add(((Create)command).getTable());
+ groups.add(create.getTable());
ResolverVisitor.resolveLanguageObject(command, groups, metadata);
+ addPrimaryKey(create, tempTable);
} else if(command.getType() == Command.TYPE_DROP) {
ResolverUtil.resolveGroup(((Drop)command).getTable(), metadata);
}
}
+ public static void addPrimaryKey(Create create, TempMetadataID tempTable) {
+ if (!create.getPrimaryKey().isEmpty()) {
+ ArrayList<TempMetadataID> primaryKey = new
ArrayList<TempMetadataID>(create.getPrimaryKey().size());
+ for (ElementSymbol symbol : create.getPrimaryKey()) {
+ primaryKey.add((TempMetadataID) symbol.getMetadataID());
+ }
+ tempTable.setPrimaryKey(primaryKey);
+ }
+ }
+
}
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-07-24
03:25:41 UTC (rev 2372)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -631,10 +631,10 @@
return store.addTempGroup(symbol.getName(), symbols, !tempTable, tempTable);
}
- public static void addTempTable(TempMetadataAdapter metadata,
+ public static TempMetadataID addTempTable(TempMetadataAdapter metadata,
GroupSymbol symbol,
List symbols) throws QueryResolverException {
- addTempGroup(metadata, symbol, symbols, true);
+ return addTempGroup(metadata, symbol, symbols, true);
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-07-24
03:25:41 UTC (rev 2372)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -38,8 +38,10 @@
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;
@@ -91,7 +93,8 @@
columns.addAll(0, primaryKey);
}
//add metadata
- tempMetadataStore.addTempGroup(tempTableName, columns, false, true);
+ TempMetadataID id = tempMetadataStore.addTempGroup(tempTableName, columns, false,
true);
+ TempTableResolver.addPrimaryKey(create, id);
TempTable tempTable = new TempTable(buffer, columns,
create.getPrimaryKey().size(), sessionID);
groupToTupleSourceID.put(tempTableName, tempTable);
}
Copied: trunk/engine/src/test/java/org/teiid/query/metadata (from rev 2371,
trunk/engine/src/test/java/org/teiid/metadata)
Modified:
trunk/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/metadata/TestTransformationMetadata.java 2010-07-23
21:44:19 UTC (rev 2371)
+++
trunk/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package org.teiid.metadata;
+package org.teiid.query.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -39,6 +39,8 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataFactory;
+import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.unittest.FakeMetadataFactory;
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -29,8 +29,8 @@
import junit.framework.TestCase;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -358,7 +358,17 @@
process(sql, expected);
}
+
+ @Test public void testXmlTableSubquery() throws Exception {
+ String sql = "select * from xmltable('/a/b' passing
convert('<a><b>first</b><b
x=\"attr\">c</b></a>', xml) columns x string path
'@x', val string path '/.') as x where val = (select max(e1) from pm1.g1
as x)";
+
+ List[] expected = new List[] {
+ Arrays.asList("attr", "c"),
+ };
+ process(sql, expected);
+ }
+
private static FakeDataManager dataManager = new FakeDataManager();
@BeforeClass public static void oneTimeSetUp() {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-07-24
03:25:41 UTC (rev 2372)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -22,7 +22,10 @@
package org.teiid.query.processor;
+import static org.junit.Assert.*;
+
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import org.junit.Before;
@@ -33,15 +36,19 @@
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.query.unittest.FakeMetadataFactory;
-
+@SuppressWarnings("nls")
public class TestTempTables {
private TempMetadataAdapter metadata;
private TempTableDataManager dataManager;
private void execute(String sql, List[] expectedResults) throws Exception {
- TestProcessor.doProcess(TestProcessor.helpGetPlan(sql, metadata), dataManager,
expectedResults, TestProcessor.createCommandContext());
+ execute(expectedResults, TestProcessor.helpGetPlan(sql, metadata));
}
+
+ private void execute(List[] expectedResults, ProcessorPlan processorPlan) throws
Exception {
+ TestProcessor.doProcess(processorPlan, dataManager, expectedResults,
TestProcessor.createCommandContext());
+ }
@Before public void setUp() {
TempTableStore tempStore = new
TempTableStore(BufferManagerFactory.getStandaloneBufferManager(), "1", null);
//$NON-NLS-1$
@@ -122,4 +129,11 @@
execute("select count(*) from x", new List[] {Arrays.asList(2)});
//$NON-NLS-1$
}
+ @Test public void testPrimaryKeyMetadata() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer, primary key
(e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ Collection c = metadata.getUniqueKeysInGroup(metadata.getGroupID("x"));
+ assertEquals(1, c.size());
+ assertEquals(1, (metadata.getElementIDsInKey(c.iterator().next()).size()));
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-07-24
03:25:41 UTC (rev 2372)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -185,7 +185,19 @@
process(sql, expected);
}
+
+ @Test public void testTextTableSubquery() throws Exception {
+ String sql = "select x.* from pm1.g1, texttable(e1 || ',' || e2 COLUMNS x
string, y integer) x where y < (select avg(e2) from pm1.g1 as x)";
+
+ List[] expected = new List[] {
+ Arrays.asList("a", 0),
+ Arrays.asList("c", 1),
+ Arrays.asList("a", 0),
+ };
+ process(sql, expected);
+ }
+
public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/test/java/org/teiid/query/unittest/FakeMetadataFactory.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -39,16 +39,16 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.dqp.internal.process.DQPWorkContext;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.mapping.xml.MappingAttribute;
import org.teiid.query.mapping.xml.MappingDocument;
import org.teiid.query.mapping.xml.MappingElement;
import org.teiid.query.mapping.xml.MappingSequenceNode;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.sql.symbol.ElementSymbol;
-
+@SuppressWarnings("nls")
public class FakeMetadataFactory {
private static FakeMetadataFacade CACHED_EXAMPLE1 = 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-07-24
03:25:41 UTC (rev 2372)
+++
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -32,17 +32,17 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.Column;
import org.teiid.metadata.ColumnSet;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
import org.teiid.metadata.ProcedureParameter;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.ProcedureParameter.Type;
import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.sql.lang.SPParameter;
Copied: trunk/metadata/src/main/java/org/teiid/metadata/VdbConstants.java (from rev 2371,
trunk/engine/src/main/java/org/teiid/metadata/VdbConstants.java)
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/VdbConstants.java
(rev 0)
+++ trunk/metadata/src/main/java/org/teiid/metadata/VdbConstants.java 2010-07-26 14:17:53
UTC (rev 2373)
@@ -0,0 +1,37 @@
+/*
+ * 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.metadata;
+
+
+
+/**
+ * Constants used for VDB processing.
+ */
+public interface VdbConstants {
+
+ public static final String DEPLOYMENT_FILE = "vdb.xml"; // !!! DO NOT
CHANGE VALUE as this would cause problems with existing VDBs having DEF files !!!
//$NON-NLS-1$
+ public static final String VDB_ARCHIVE_EXTENSION = ".vdb"; //$NON-NLS-1$
+ public final static String INDEX_EXT = ".INDEX"; //$NON-NLS-1$
+ public final static String SEARCH_INDEX_EXT = ".SEARCH_INDEX";
//$NON-NLS-1$
+ public final static String MODEL_EXT = ".xmi"; //$NON-NLS-1$
+}
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
===================================================================
---
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -62,9 +62,9 @@
import org.teiid.metadata.ProcedureParameter;
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.metadata.VdbConstants;
-import org.teiid.metadata.TransformationMetadata.Resource;
+import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
/**
Modified:
trunk/metadata/src/test/java/org/teiid/metadata/index/TestMultipleModelIndexes.java
===================================================================
---
trunk/metadata/src/test/java/org/teiid/metadata/index/TestMultipleModelIndexes.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/metadata/src/test/java/org/teiid/metadata/index/TestMultipleModelIndexes.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -29,7 +29,7 @@
import org.junit.Test;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.metadata.Table;
-import org.teiid.metadata.TransformationMetadata;
+import org.teiid.query.metadata.TransformationMetadata;
@SuppressWarnings("nls")
public class TestMultipleModelIndexes {
Modified: trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java
===================================================================
---
trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/metadata/src/test/java/org/teiid/metadata/index/VDBMetadataFactory.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -38,11 +38,11 @@
import org.teiid.core.util.FileUtils;
import org.teiid.core.util.LRUCache;
import org.teiid.core.util.UnitTestUtil;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.query.function.metadata.FunctionMetadataReader;
import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.metadata.CompositeMetadataStore;
+import org.teiid.query.metadata.TransformationMetadata;
@SuppressWarnings("nls")
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2010-07-24 03:25:41
UTC (rev 2372)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2010-07-26 14:17:53
UTC (rev 2373)
@@ -29,12 +29,12 @@
import org.teiid.adminapi.impl.DataPolicyMetadata;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.metadata.CompositeMetadataStore;
import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.TransformationMetadata;
-import org.teiid.metadata.TransformationMetadata.Resource;
import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.vdb.runtime.VDBKey;
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-07-24 03:25:41
UTC (rev 2372)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-07-26 14:17:53
UTC (rev 2373)
@@ -47,8 +47,8 @@
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.TransformationMetadata.Resource;
import org.teiid.metadata.index.IndexMetadataFactory;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.TranslatorException;
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2010-07-24 03:25:41
UTC (rev 2372)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2010-07-26 14:17:53
UTC (rev 2373)
@@ -45,7 +45,7 @@
import org.teiid.metadata.Datatype;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.TransformationMetadata.Resource;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.translator.TranslatorException;
import org.teiid.vdb.runtime.VDBKey;
Modified:
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/BaseQueryTest.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -26,10 +26,10 @@
import junit.framework.TestCase;
import org.teiid.dqp.message.RequestID;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.metadata.index.VDBMetadataFactory;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.QueryOptimizer;
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
Modified:
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java 2010-07-24
03:25:41 UTC (rev 2372)
+++
trunk/test-integration/common/src/test/java/org/teiid/dqp/internal/process/TestXMLTypeTranslations.java 2010-07-26
14:17:53 UTC (rev 2373)
@@ -35,8 +35,8 @@
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.dqp.message.RequestID;
-import org.teiid.metadata.TransformationMetadata;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;