Author: shawkins
Date: 2012-03-03 10:03:10 -0500 (Sat, 03 Mar 2012)
New Revision: 3911
Modified:
branches/7.7.x/api/src/main/java/org/teiid/translator/ExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java
Log:
TEIID-499 adding pushdown support for SQL Server date formats, updating the teiid
translator and reverting the cachedfinder change.
Modified: branches/7.7.x/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- branches/7.7.x/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-03-03
11:48:18 UTC (rev 3910)
+++ branches/7.7.x/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -935,5 +935,28 @@
public boolean supportsLikeRegex() {
return false;
}
+
+ public enum Format {
+ NUMBER,
+ DATE
+ }
+
+ /**
+ * See also {@link #supportsFormatLiteral(String, Format)}
+ * @return true if only literal formats are supports.
+ */
+ public boolean supportsOnlyFormatLiterals() {
+ return false;
+ }
+
+ /**
+ *
+ * @param literal
+ * @param format
+ * @return true if the given Java format string is supported
+ */
+ public boolean supportsFormatLiteral(String literal, Format format) {
+ return false;
+ }
}
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -20,46 +20,103 @@
* 02110-1301 USA.
*/
-/*
- */
-package org.teiid.translator.jdbc.sqlserver;
-
+/*
+ */
+package org.teiid.translator.jdbc.sqlserver;
+
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import org.teiid.language.AggregateFunction;
import org.teiid.language.ColumnReference;
import org.teiid.language.Function;
import org.teiid.language.LanguageObject;
+import org.teiid.language.Literal;
import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
+import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.sybase.SybaseExecutionFactory;
/**
* Updated to assume the use of the DataDirect, 2005 driver, or later.
*/
-@Translator(name="sqlserver", description="A translator for Microsoft SQL
Server Database")
-public class SQLServerExecutionFactory extends SybaseExecutionFactory {
+@Translator(name="sqlserver", description="A translator for Microsoft SQL
Server Database")
+public class SQLServerExecutionFactory extends SybaseExecutionFactory {
+ private class ParseFormatFunctionModifier extends FunctionModifier {
+ @Override
+ public List<?> translate(Function function) {
+ return Arrays.asList("CONVERT(" + getTarget() + ", ",
function.getParameters().get(0), ", ",
formatMap.get(((Literal)function.getParameters().get(1)).getValue()), ")" );
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ String getTarget() {
+ return "DATETIME"; //$NON-NLS-1$
+ }
+ }
+
public static final String V_2005 = "2005"; //$NON-NLS-1$
public static final String V_2008 = "2008"; //$NON-NLS-1$
+ private Map<String, Integer> formatMap = new HashMap<String, Integer>();
+
//TEIID-31 remove mod modifier for SQL Server 2008
public SQLServerExecutionFactory() {
setDatabaseVersion(V_2005);
setMaxInCriteriaSize(JDBCExecutionFactory.DEFAULT_MAX_IN_CRITERIA);
setMaxDependentInPredicates(JDBCExecutionFactory.DEFAULT_MAX_DEPENDENT_PREDICATES);
+ formatMap.put("MM/dd/yy", 1); //$NON-NLS-1$
+ formatMap.put("yy.MM.dd", 2); //$NON-NLS-1$
+ formatMap.put("dd/MM/yy", 3); //$NON-NLS-1$
+ formatMap.put("dd-MM-yy", 4); //$NON-NLS-1$
+ formatMap.put("dd-MM-yy", 5); //$NON-NLS-1$
+ formatMap.put("dd MMM yy", 6); //$NON-NLS-1$
+ formatMap.put("MMM dd, yy", 7); //$NON-NLS-1$
+ formatMap.put("hh:mm:ss", 8); //$NON-NLS-1$
+ formatMap.put("MM-dd-yy", 10); //$NON-NLS-1$
+ formatMap.put("yy/MM/dd", 11); //$NON-NLS-1$
+ formatMap.put("yyMMdd", 12); //$NON-NLS-1$
+ formatMap.put("kk:MM:ss:SSS", 14); //$NON-NLS-1$
+ for (Map.Entry<String, Integer> entry : new HashSet<Map.Entry<String,
Integer>>(formatMap.entrySet())) {
+ formatMap.put(entry.getKey().replace("yy", "yyyy"),
entry.getValue() + 100); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ formatMap.put("MMM dd yyyy hh:mma", 100); //$NON-NLS-1$
+ formatMap.put("MMM dd yyyy hh:mm:ss:SSSa", 109); //$NON-NLS-1$
+ formatMap.put("dd MMM yyyy kk:mm:ss:SSS", 113); //$NON-NLS-1$
+ formatMap.put("yyyy-MM-dd kk:mm:ss", 120); //$NON-NLS-1$
+ formatMap.put("yyyy-MM-dd kk:mm:ss.SSS", 121); //$NON-NLS-1$
+ formatMap.put("yyyy-MM-ddTkk:mm:ss.SSS", 126); //$NON-NLS-1$
+ formatMap.put("yyyy-MM-ddTkk:mm:ss.SSST", 127); //$NON-NLS-1$
+ formatMap.put("dd MMM yyyy hh:mm:ss:SSSa", 130); //$NON-NLS-1$
+ formatMap.put("dd/mm/yyyy hh:mm:ss:SSSa", 131); //$NON-NLS-1$
}
@Override
+ public void start() throws TranslatorException {
+ super.start();
+ registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new
ParseFormatFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new
ParseFormatFunctionModifier() {
+ @Override
+ String getTarget() {
+ return "VARCHAR"; //$NON-NLS-1$
+ }
+ });
+ }
+
+ @Override
protected List<Object> convertDateToString(Function function) {
return Arrays.asList("replace(convert(varchar, ",
function.getParameters().get(0), ", 102), '.', '-')");
//$NON-NLS-1$ //$NON-NLS-2$
- }
+ }
@Override
protected List<?> convertTimestampToString(Function function) {
@@ -157,7 +214,8 @@
supportedFunctions.add("CONVERT"); //$NON-NLS-1$
supportedFunctions.add("IFNULL"); //$NON-NLS-1$
supportedFunctions.add("NVL"); //$NON-NLS-1$
-
+ supportedFunctions.add(SourceSystemFunctions.FORMATTIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
return supportedFunctions;
}
@@ -241,5 +299,19 @@
public boolean supportsWindowOrderByWithAggregates() {
return false;
}
-
-}
+
+ @Override
+ public boolean supportsFormatLiteral(String literal,
+ org.teiid.translator.ExecutionFactory.Format format) {
+ if (format == Format.NUMBER) {
+ return false; //TODO: add support
+ }
+ return formatMap.containsKey(literal);
+ }
+
+ @Override
+ public boolean supportsOnlyLiteralFormat() {
+ return true;
+ }
+
+}
Modified:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
===================================================================
---
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -43,6 +43,7 @@
public static final String SEVEN_3 = "7.3"; //$NON-NLS-1$
public static final String SEVEN_4 = "7.4"; //$NON-NLS-1$
public static final String SEVEN_5 = "7.5"; //$NON-NLS-1$
+ public static final String SEVEN_6 = "7.6"; //$NON-NLS-1$
public TeiidExecutionFactory() {
setDatabaseVersion(SEVEN_0);
@@ -231,4 +232,15 @@
public boolean supportsSimilarTo() {
return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
}
+
+ @Override
+ public boolean supportsWindowDistinctAggregates() {
+ return getDatabaseVersion().compareTo(SEVEN_6) >= 0;
+ }
+
+ @Override
+ public boolean supportsWindowOrderByWithAggregates() {
+ return getDatabaseVersion().compareTo(SEVEN_5) >= 0;
+ }
+
}
Modified:
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java
===================================================================
---
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sqlserver/TestSqlServerConversionVisitor.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -209,5 +209,14 @@
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, trans, obj);
}
+
+ @Test public void testParseFormat() throws Exception {
+ String input = "select parsetimestamp(smalla.timestampvalue,
'yyyy.MM.dd'), formattimestamp(smalla.timestampvalue, 'yy.MM.dd') from
bqt1.smalla"; //$NON-NLS-1$
+ String output = "SELECT CONVERT(DATETIME, convert(varchar,
g_0.TimestampValue, 21), 102), CONVERT(VARCHAR, g_0.TimestampValue, 2) FROM SmallA
g_0"; //$NON-NLS-1$
+
+ CommandBuilder commandBuilder = new
CommandBuilder(RealMetadataFactory.exampleBQTCached());
+ Command obj = commandBuilder.getCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(output, trans, obj);
+ }
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -110,6 +110,7 @@
tgtCaps.setCapabilitySupport(Capability.CRITERIA_SIMILAR,
srcCaps.supportsSimilarTo());
tgtCaps.setCapabilitySupport(Capability.CRITERIA_LIKE_REGEX,
srcCaps.supportsLikeRegex());
setSupports(connectorID, tgtCaps, Capability.WINDOW_FUNCTION_DISTINCT_AGGREGATES,
srcCaps.supportsWindowDistinctAggregates(), Capability.ELEMENTARY_OLAP,
Capability.QUERY_AGGREGATES_DISTINCT);
+ tgtCaps.setCapabilitySupport(Capability.ONLY_FORMAT_LITERALS,
srcCaps.supportsOnlyFormatLiterals());
List<String> functions = srcCaps.getSupportedFunctions();
if(functions != null && functions.size() > 0) {
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -40,9 +40,6 @@
/**
- * This class is misnamed. Since connector managers are in process and cache their own
- * capabilities, there is no need to cache again here. Also we want to pick up any
- * changes if a source has it's translator modified.
*/
public class CachedFinder implements CapabilitiesFinder {
@@ -98,6 +95,7 @@
throw new TeiidRuntimeException("No sources were given for the model "
+ modelName); //$NON-NLS-1$
}
+ userCache.put(modelName, caps);
return caps;
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -23,8 +23,13 @@
package org.teiid.query.optimizer.capabilities;
import java.io.Serializable;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import org.teiid.translator.ExecutionFactory;
+import org.teiid.translator.ExecutionFactory.Format;
+
/**
*/
public class BasicSourceCapabilities implements SourceCapabilities, Serializable {
@@ -35,6 +40,7 @@
private Map<Capability, Boolean> capabilityMap = new HashMap<Capability,
Boolean>();
private Map<String, Boolean> functionMap = new TreeMap<String,
Boolean>(String.CASE_INSENSITIVE_ORDER);
private Map<Capability, Object> propertyMap = new HashMap<Capability,
Object>();
+ private ExecutionFactory<?, ?> translator;
/**
* Construct a basic capabilities object.
@@ -95,4 +101,15 @@
return this.propertyMap.get(propertyName);
}
+ public void setTranslator(ExecutionFactory<?, ?> translator) {
+ this.translator = translator;
+ }
+
+ public boolean supportsFormatLiteral(String literal, Format format) {
+ if (this.translator == null) {
+ return false;
+ }
+ return this.translator.supportsFormatLiteral(literal, format);
+ }
+
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -22,6 +22,8 @@
package org.teiid.query.optimizer.capabilities;
+import org.teiid.translator.ExecutionFactory.Format;
+
public interface SourceCapabilities {
public enum Capability {
@@ -329,7 +331,8 @@
CRITERIA_SIMILAR,
CRITERIA_LIKE_REGEX,
WINDOW_FUNCTION_DISTINCT_AGGREGATES("WindowDistinctAggregates"),
//$NON-NLS-1$
- QUERY_ONLY_SINGLE_TABLE_GROUP_BY;
+ QUERY_ONLY_SINGLE_TABLE_GROUP_BY,
+ ONLY_FORMAT_LITERALS;
private final String toString;
@@ -389,4 +392,6 @@
* @since 4.4
*/
public Object getSourceProperty(Capability propertyName);
+
+ public boolean supportsFormatLiteral(String literal, Format format);
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -419,7 +419,7 @@
return connectorID != null &&
connectorID.equals(caps1.getSourceProperty(Capability.CONNECTOR_ID));
}
- private static SourceCapabilities getCapabilities(Object modelID,
QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
+ static SourceCapabilities getCapabilities(Object modelID, QueryMetadataInterface
metadata, CapabilitiesFinder capFinder)
throws QueryMetadataException, TeiidComponentException {
// Find capabilities
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -23,9 +23,11 @@
package org.teiid.query.optimizer.relational.rules;
import java.util.Arrays;
+import java.util.HashSet;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
@@ -41,42 +43,14 @@
import org.teiid.query.processor.relational.RelationalPlan;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.AbstractCompareCriteria;
-import org.teiid.query.sql.lang.AbstractSetCriteria;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.DependentSetCriteria;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.navigator.PostOrderNavigator;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.CaseExpression;
-import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.QueryString;
-import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.TextLine;
-import org.teiid.query.sql.symbol.WindowFunction;
-import org.teiid.query.sql.symbol.XMLAttributes;
-import org.teiid.query.sql.symbol.XMLElement;
-import org.teiid.query.sql.symbol.XMLForest;
-import org.teiid.query.sql.symbol.XMLNamespaces;
-import org.teiid.query.sql.symbol.XMLParse;
-import org.teiid.query.sql.symbol.XMLQuery;
-import org.teiid.query.sql.symbol.XMLSerialize;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.sql.visitor.FunctionCollectorVisitor;
+import org.teiid.translator.SourceSystemFunctions;
+import org.teiid.translator.ExecutionFactory.Format;
/**
@@ -264,6 +238,15 @@
markInvalid(crit, "OR criteria not supported by source");
//$NON-NLS-1$
}
}
+
+ static HashSet<String> parseFormat = new HashSet<String>();
+
+ static {
+ parseFormat.add(SourceSystemFunctions.PARSEBIGDECIMAL);
+ parseFormat.add(SourceSystemFunctions.FORMATBIGDECIMAL);
+ parseFormat.add(SourceSystemFunctions.PARSETIMESTAMP);
+ parseFormat.add(SourceSystemFunctions.FORMATTIMESTAMP);
+ }
public void visit(Function obj) {
try {
@@ -277,7 +260,24 @@
}
if (! CapabilitiesUtil.supportsScalarFunction(modelID, obj, metadata,
capFinder)) {
markInvalid(obj, (obj.isImplicit()?"(implicit) ":"")
+ obj.getName() + " function not supported by source"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ return;
}
+ String name = obj.getFunctionDescriptor().getName();
+ if (CapabilitiesUtil.supports(Capability.ONLY_FORMAT_LITERALS, modelID,
metadata, capFinder) && parseFormat.contains(name)) {
+ if (!(obj.getArg(1) instanceof Constant)) {
+ markInvalid(obj, obj.getName() + " non-literal parse format function
not supported by source"); //$NON-NLS-1$
+ return;
+ }
+ Constant c = (Constant)obj.getArg(1);
+ if (c.isMultiValued()) {
+ markInvalid(obj, obj.getName() + " non-literal parse format function
not supported by source"); //$NON-NLS-1$
+ return;
+ }
+ if (!CapabilitiesUtil.getCapabilities(modelID, metadata,
capFinder).supportsFormatLiteral((String)c.getValue(),
name.endsWith(DataTypeManager.DefaultDataTypes.TIMESTAMP)?Format.DATE:Format.NUMBER)) {
+ markInvalid(obj, obj.getName() + " literal parse " + c + "
not supported by source"); //$NON-NLS-1$ //$NON-NLS-2$
+ return;
+ }
+ }
} catch(QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch(TeiidComponentException e) {
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestBatchedUpdatePlanner.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -26,17 +26,18 @@
import java.util.Collection;
import java.util.List;
+import junit.framework.TestCase;
+
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import org.teiid.query.optimizer.capabilities.SourceCapabilities;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.BatchedUpdatePlan;
import org.teiid.query.processor.ProcessorPlan;
@@ -53,10 +54,8 @@
import org.teiid.query.validator.Validator;
import org.teiid.query.validator.ValidatorReport;
-import junit.framework.TestCase;
-
/**
* @since 4.2
*/
@@ -210,19 +209,14 @@
helpTestPlanner(sql, expectedBatching, finder);
}
- private static final class FakeCapabilities implements SourceCapabilities {
+ private static final class FakeCapabilities extends BasicSourceCapabilities {
private boolean supportsBatching = false;
private FakeCapabilities(boolean supportsBatching) {
this.supportsBatching = supportsBatching;
}
- public Scope getScope() {return null;}
public boolean supportsCapability(Capability capability) {
return !capability.equals(Capability.BATCHED_UPDATES) || supportsBatching;
}
- public boolean supportsFunction(String functionName) {return false;}
- // since 4.4
- public Object getSourceProperty(Capability propertyName) {return null;}
-
}
private static final boolean DEBUG = false;
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -56,24 +56,7 @@
import org.teiid.query.optimizer.relational.rules.RuleChooseDependent;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.relational.AccessNode;
-import org.teiid.query.processor.relational.DependentAccessNode;
-import org.teiid.query.processor.relational.EnhancedSortMergeJoinStrategy;
-import org.teiid.query.processor.relational.GroupingNode;
-import org.teiid.query.processor.relational.JoinNode;
-import org.teiid.query.processor.relational.JoinStrategy;
-import org.teiid.query.processor.relational.MergeJoinStrategy;
-import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
-import org.teiid.query.processor.relational.NestedTableJoinStrategy;
-import org.teiid.query.processor.relational.NullNode;
-import org.teiid.query.processor.relational.PlanExecutionNode;
-import org.teiid.query.processor.relational.ProjectIntoNode;
-import org.teiid.query.processor.relational.ProjectNode;
-import org.teiid.query.processor.relational.RelationalNode;
-import org.teiid.query.processor.relational.RelationalPlan;
-import org.teiid.query.processor.relational.SelectNode;
-import org.teiid.query.processor.relational.SortNode;
-import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.processor.relational.*;
import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.TestResolver;
@@ -87,6 +70,7 @@
import org.teiid.query.util.CommandContext;
import org.teiid.query.validator.Validator;
import org.teiid.query.validator.ValidatorReport;
+import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.SourceSystemFunctions;
@SuppressWarnings({"nls", "unchecked"})
@@ -6566,6 +6550,41 @@
});
}
+ @Test public void testParseFormat() throws Exception {
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.ONLY_FORMAT_LITERALS, true);
+ caps.setFunctionSupport(SourceSystemFunctions.FORMATTIMESTAMP, true);
+ caps.setFunctionSupport(SourceSystemFunctions.PARSEBIGDECIMAL, true);
+ caps.setTranslator(new ExecutionFactory<Object, Object> () {
+ @Override
+ public boolean supportsFormatLiteral(String literal,
+ org.teiid.translator.ExecutionFactory.Format format) {
+ return (format == Format.DATE && literal.equals("yyyy")) ||
(format == Format.NUMBER && literal.equals("$"));
+ }
+ });
+ ProcessorPlan plan = TestOptimizer.helpPlan("SELECT stringkey from
bqt1.smalla where formattimestamp(timestampvalue, 'yyyy') = '1921' and
parsebigdecimal(stringkey, '$') = 1 and formattimestamp(timestampvalue,
'yy') = '19'", //$NON-NLS-1$
+ RealMetadataFactory.exampleBQTCached(), null, new
DefaultCapabilitiesFinder(caps),
+ new String[] {
+ "SELECT g_0.timestampvalue, g_0.stringkey
FROM bqt1.smalla AS g_0 WHERE (formattimestamp(g_0.timestampvalue, 'yyyy') =
'1921') AND (parsebigdecimal(g_0.stringkey, '$') = 1)"},
ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 1, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
public static final boolean DEBUG = false;
}
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java 2012-03-03
11:48:18 UTC (rev 3910)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/optimizer/capabilities/AllCapabilities.java 2012-03-03
15:03:10 UTC (rev 3911)
@@ -25,27 +25,9 @@
*/
package org.teiid.query.optimizer.capabilities;
-import org.teiid.query.optimizer.capabilities.SourceCapabilities;
-public class AllCapabilities implements SourceCapabilities {
+public class AllCapabilities extends BasicSourceCapabilities {
public boolean supportsCapability(Capability capability) {
return true;
}
-
- public boolean supportsFunction(String functionName) {
- return false;
- }
-
- /**
- * @see
org.teiid.query.optimizer.capabilities.SourceCapabilities#getSourceProperty(java.lang.String)
- * @since 4.4
- */
- public Object getSourceProperty(Capability propertyName) {
- return null;
- }
-
- public Scope getScope() {
- return Scope.SCOPE_GLOBAL;
- }
-
}
\ No newline at end of file