Author: shawkins
Date: 2012-03-09 15:18:08 -0500 (Fri, 09 Mar 2012)
New Revision: 3932
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
Log:
TEIID-3 making the behavior of supportsConvert consistent with supportsLiteralFormat
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-03-09 19:38:02
UTC (rev 3931)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2012-03-09 20:18:08
UTC (rev 3932)
@@ -46,6 +46,7 @@
import org.teiid.metadata.FunctionParameter;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.TypeFacility.RUNTIME_CODES;
@@ -928,18 +929,23 @@
}
/**
- * Used for fine grained control of convert/cast pushdown. If {@link
#getSupportedFunctions()} contains
- * {@link SourceSystemFunctions#CONVERT}, then all of the default Teiid pushdown
conversions are supported.
- * So typically this method will be implemented when {@link #getSupportedFunctions()}
does not contain
- * {@link SourceSystemFunctions#CONVERT}. The engine will does not care about an
unnecessary conversion
+ * Used for fine grained control of convert/cast pushdown. The {@link
#getSupportedFunctions()} should
+ * contain {@link SourceSystemFunctions#CONVERT}. This method can then return false to
indicate
+ * a lack of specific support. The engine will does not care about an unnecessary
conversion
* where fromType == toType.
+ *
+ * By default lob conversion is disabled.
+ *
* @param fromType @see RUNTIME_CODES
* @param toType @see RUNTIME_CODES
* @return true if the given conversion is supported.
* @since 8.0
*/
public boolean supportsConvert(int fromType, int toType) {
- return false;
+ if (fromType == RUNTIME_CODES.OBJECT || fromType == RUNTIME_CODES.CLOB || fromType ==
RUNTIME_CODES.XML || fromType == RUNTIME_CODES.BLOB || toType == RUNTIME_CODES.CLOB ||
toType == RUNTIME_CODES.XML || toType == RUNTIME_CODES.BLOB) {
+ return false;
+ }
+ return true;
}
/**
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-09
19:38:02 UTC (rev 3931)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-09
20:18:08 UTC (rev 3932)
@@ -25,7 +25,6 @@
import java.util.Iterator;
import java.util.List;
-import org.teiid.core.types.DataTypeManager;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.FunctionMethod;
@@ -115,15 +114,6 @@
tgtCaps.setCapabilitySupport(Capability.CRITERIA_ONLY_LITERAL_COMPARE,
srcCaps.supportsOnlyLiteralComparison());
tgtCaps.setCapabilitySupport(Capability.DEPENDENT_JOIN,
srcCaps.supportsDependentJoins());
- //TODO: as more types are added it may make more sense to just delegate calls to
the executionfactory
- for (int i = 0; i <= DataTypeManager.MAX_TYPE_CODE; i++) {
- for (int j = 0; j <= DataTypeManager.MAX_TYPE_CODE; j++) {
- if (i != j) {
- tgtCaps.setSupportsConvert(i, j, srcCaps.supportsConvert(i, j));
- }
- }
- }
-
List<String> functions = srcCaps.getSupportedFunctions();
if(functions != null && functions.size() > 0) {
Iterator<String> iter = functions.iterator();
@@ -132,6 +122,7 @@
tgtCaps.setFunctionSupport(func.toLowerCase(), true);
}
}
+
List<FunctionMethod> pushDowns = srcCaps.getPushDownFunctions();
if(pushDowns != null && pushDowns.size() > 0) {
for(FunctionMethod func:pushDowns) {
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java 2012-03-09
19:38:02 UTC (rev 3931)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/BasicSourceCapabilities.java 2012-03-09
20:18:08 UTC (rev 3932)
@@ -27,10 +27,7 @@
import java.util.Map;
import java.util.TreeMap;
-import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.types.DataTypeManager.DefaultTypeCodes;
import org.teiid.translator.ExecutionFactory;
-import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.ExecutionFactory.Format;
/**
@@ -42,7 +39,6 @@
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 boolean[][] converts = new boolean[DataTypeManager.MAX_TYPE_CODE +
1][DataTypeManager.MAX_TYPE_CODE + 1];
private ExecutionFactory<?, ?> translator;
/**
@@ -71,16 +67,6 @@
}
public void setFunctionSupport(String function, boolean supports) {
- if (SourceSystemFunctions.CONVERT.equalsIgnoreCase(function)) {
- for (int i = 0; i < converts.length; i++) {
- if (i == DefaultTypeCodes.OBJECT || i == DefaultTypeCodes.CLOB || i ==
DefaultTypeCodes.XML) {
- continue;
- }
- for (int j = 0; j < converts.length; j++) {
- converts[i][j] = j != DefaultTypeCodes.CLOB && j !=
DefaultTypeCodes.XML;
- }
- }
- }
functionMap.put(function, Boolean.valueOf(supports));
}
@@ -108,13 +94,12 @@
@Override
public boolean supportsConvert(int sourceType, int targetType) {
- return converts[sourceType][targetType];
+ if (this.translator == null) {
+ return true;
+ }
+ return this.translator.supportsConvert(sourceType, targetType);
}
- public void setSupportsConvert(int sourceType, int targetType, boolean value) {
- this.converts[sourceType][targetType] = value;
- }
-
public void setTranslator(ExecutionFactory<?, ?> translator) {
this.translator = translator;
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2012-03-09
19:38:02 UTC (rev 3931)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2012-03-09
20:18:08 UTC (rev 3932)
@@ -226,14 +226,6 @@
SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
- if (FunctionLibrary.isConvert(function)) {
- Class<?> fromType = function.getArg(0).getType();
- Class<?> targetType = function.getType();
- if (fromType == targetType) {
- return true; //this should be removed in rewrite
- }
- return caps.supportsConvert(DataTypeManager.getTypeCode(fromType),
DataTypeManager.getTypeCode(targetType));
- }
//capabilities check is only valid for non-schema scoped functions
//technically the other functions are scoped to SYS or their function model, but
that's
//not formally part of their metadata yet
@@ -243,6 +235,14 @@
if (!caps.supportsFunction(function.getFunctionDescriptor().getName())) {
return false;
}
+ if (FunctionLibrary.isConvert(function)) {
+ Class<?> fromType = function.getArg(0).getType();
+ Class<?> targetType = function.getType();
+ if (fromType == targetType) {
+ return true; //this should be removed in rewrite
+ }
+ return caps.supportsConvert(DataTypeManager.getTypeCode(fromType),
DataTypeManager.getTypeCode(targetType));
+ }
} else if (!isSameConnector(modelID, schema, metadata, capFinder)) {
return false; //not the right schema
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2012-03-09
19:38:02 UTC (rev 3931)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2012-03-09
20:18:08 UTC (rev 3932)
@@ -6566,7 +6566,13 @@
@Test public void testConvertSignature() throws Exception {
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
- caps.setSupportsConvert(DefaultTypeCodes.INTEGER, DefaultTypeCodes.STRING, true);
+ caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
+ caps.setTranslator(new ExecutionFactory<Object, Object>() {
+ @Override
+ public boolean supportsConvert(int fromType, int toType) {
+ return (fromType == DefaultTypeCodes.INTEGER && toType ==
DefaultTypeCodes.STRING);
+ }
+ });
ProcessorPlan plan = TestOptimizer.helpPlan("SELECT e1 from pm1.g1 where e1
= e2 and e1 = e3", //$NON-NLS-1$
RealMetadataFactory.example1Cached(), null, new
DefaultCapabilitiesFinder(caps),
new String[] {