Author: shawkins
Date: 2012-02-13 10:46:55 -0500 (Mon, 13 Feb 2012)
New Revision: 3867
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java
branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties
Log:
TEIID-1874 adding validation for translator metadata
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java 2012-02-13
15:18:20 UTC (rev 3866)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java 2012-02-13
15:46:55 UTC (rev 3867)
@@ -49,10 +49,15 @@
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.Table;
import org.teiid.query.QueryPlugin;
+import org.teiid.query.function.metadata.FunctionMetadataValidator;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.SourceCapabilities;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Scope;
+import org.teiid.query.report.ActivityReport;
+import org.teiid.query.report.ReportItem;
import org.teiid.query.sql.lang.Command;
import org.teiid.resource.spi.WrappedConnection;
import org.teiid.translator.ExecutionContext;
@@ -129,10 +134,32 @@
} finally {
executionFactory.closeConnection(connection, connectionFactory);
}
+ validateMetadata(factory.getMetadataStore(), modelName);
return factory.getMetadataStore();
}
- public List<FunctionMethod> getPushDownFunctions(){
+ private void validateMetadata(MetadataStore metadataStore, String schemaName) throws
TranslatorException {
+ if (metadataStore.getSchemas().size() != 1) {
+ throw new
TranslatorException(QueryPlugin.Util.getString("invalid_schema", schemaName));
//$NON-NLS-1$
+ }
+ Map.Entry<String, Schema> schemaEntry =
metadataStore.getSchemas().entrySet().iterator().next();
+ if (!schemaName.equalsIgnoreCase(schemaEntry.getKey())) {
+ throw new
TranslatorException(QueryPlugin.Util.getString("invalid_schema", schemaName));
//$NON-NLS-1$
+ }
+ Schema s = schemaEntry.getValue();
+ for (Table t : s.getTables().values()) {
+ if (t.getColumns() == null || t.getColumns().size() == 0) {
+ throw new TranslatorException(QueryPlugin.Util.getString("invalid_table",
t.getFullName())); //$NON-NLS-1$
+ }
+ }
+ ActivityReport<ReportItem> report = new
ActivityReport<ReportItem>("Translator metadata load " + schemaName);
//$NON-NLS-1$
+ FunctionMetadataValidator.validateFunctionMethods(s.getFunctions().values(),report);
+ if(report.hasItems()) {
+ throw new
TranslatorException(QueryPlugin.Util.getString("ERR.015.001.0005", report));
//$NON-NLS-1$
+ }
+ }
+
+ public List<FunctionMethod> getPushDownFunctions(){
return getExecutionFactory().getPushDownFunctions();
}
Modified: branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties 2012-02-13
15:18:20 UTC (rev 3866)
+++ branches/7.7.x/engine/src/main/resources/org/teiid/query/i18n.properties 2012-02-13
15:46:55 UTC (rev 3867)
@@ -947,4 +947,7 @@
RuleAssignOutputElements.couldnt_push_expression=Expression(s) {0} cannot be pushed to
source.
RuleAssignOutputElements.cannot_introduce_expressions=Cannot introduce new expressions
{1} in duplicate removal.
-DependentCriteriaProcessor.dep_join_backoff=Not performing dependent join using source
{0}, since the number of distinct rows for expression {1} exceeds {2}. You should ensure
that your source statistics, including column distinct value counts, accurately reflect
the source or use a MAKE_DEP hint to force the join.
\ No newline at end of file
+DependentCriteriaProcessor.dep_join_backoff=Not performing dependent join using source
{0}, since the number of distinct rows for expression {1} exceeds {2}. You should ensure
that your source statistics, including column distinct value counts, accurately reflect
the source or use a MAKE_DEP hint to force the join.
+
+invalid_schema=Invalid schema from translator metadata expected {0}, but the returned
MetadataStore contained no such schema or more than 1 schema.
+invalid_table=Invalid table {0}. A table must have 1 or more columns.
\ No newline at end of file