Author: shawkins
Date: 2009-09-14 22:31:57 -0400 (Mon, 14 Sep 2009)
New Revision: 1351
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
Log:
TEIID-800 now that the conversion between string and char does not throw an exception, we
need to check for the narrowing case in the resolver.
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-09-14
20:49:25 UTC (rev 1350)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-09-15
02:31:57 UTC (rev 1351)
@@ -214,27 +214,38 @@
public static Constant convertConstant(String sourceTypeName,
String targetTypeName,
- Constant constant) throws
QueryResolverException {
+ Constant constant) {
if (!DataTypeManager.isTransformable(sourceTypeName, targetTypeName)) {
return null;
}
-
- //try to get the converted constant, if this fails then it is not in a valid
format
- Constant result = getProperlyTypedConstant(constant.getValue(),
DataTypeManager.getDataTypeClass(targetTypeName));
+
+ try {
+ //try to get the converted constant, if this fails then it is not in a valid
format
+ Constant result = getProperlyTypedConstant(constant.getValue(),
DataTypeManager.getDataTypeClass(targetTypeName));
+
+ if (DataTypeManager.DefaultDataTypes.STRING.equals(sourceTypeName)) {
+ if (DataTypeManager.DefaultDataTypes.CHAR.equals(targetTypeName)) {
+ String value = (String)constant.getValue();
+ if (value != null && value.length() != 1) {
+ return null;
+ }
+ }
+ return result;
+ }
+
+ //for non-strings, ensure that the conversion is consistent
+ if (!DataTypeManager.isTransformable(targetTypeName, sourceTypeName)) {
+ return null;
+ }
- if (DataTypeManager.DefaultDataTypes.STRING.equals(sourceTypeName)) {
- return result;
+ Constant reverse = getProperlyTypedConstant(result.getValue(),
constant.getType());
+
+ if (constant.equals(reverse)) {
+ return result;
+ }
+ } catch (QueryResolverException e) {
+
}
-
- //for non-strings, ensure that the conversion is consistent
- if (!DataTypeManager.isTransformable(targetTypeName, sourceTypeName)) {
- return null;
- }
- Constant reverse = getProperlyTypedConstant(result.getValue(),
constant.getType());
-
- if (constant.equals(reverse)) {
- return result;
- }
return null;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-09-14
20:49:25 UTC (rev 1350)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-09-15
02:31:57 UTC (rev 1351)
@@ -1492,16 +1492,14 @@
String leftExprTypeName = DataTypeManager.getDataTypeName(leftExpr.getType());
- Constant result = null;
- try {
- result =
ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()),
leftExprTypeName, rightConstant);
- Constant other = ResolverUtil.convertConstant(leftExprTypeName,
DataTypeManager.getDataTypeName(rightConstant.getType()), result);
- if (((Comparable)rightConstant.getValue()).compareTo(other.getValue()) != 0)
{
- return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
- }
- } catch(QueryResolverException e) {
+ Constant result =
ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()),
leftExprTypeName, rightConstant);
+ if (result == null) {
return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
}
+ Constant other = ResolverUtil.convertConstant(leftExprTypeName,
DataTypeManager.getDataTypeName(rightConstant.getType()), result);
+ if (other == null ||
((Comparable)rightConstant.getValue()).compareTo(other.getValue()) != 0) {
+ return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
+ }
if (!DataTypeManager.isImplicitConversion(leftExprTypeName,
DataTypeManager.getDataTypeName(rightConstant.getType()))) {
return crit;
@@ -1558,15 +1556,12 @@
Constant rightConstant = (Constant) next;
- Constant result = null;
- try {
- result =
ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()),
leftExprTypeName, rightConstant);
+ Constant result =
ResolverUtil.convertConstant(DataTypeManager.getDataTypeName(rightConstant.getType()),
leftExprTypeName, rightConstant);
+ if (result != null) {
Constant other = ResolverUtil.convertConstant(leftExprTypeName,
DataTypeManager.getDataTypeName(rightConstant.getType()), result);
- if (((Comparable)rightConstant.getValue()).compareTo(other.getValue()) !=
0) {
+ if (other == null ||
((Comparable)rightConstant.getValue()).compareTo(other.getValue()) != 0) {
result = null;
}
- } catch(QueryResolverException e) {
-
}
if (result != null) {
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-09-14
20:49:25 UTC (rev 1350)
+++
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-09-15
02:31:57 UTC (rev 1351)
@@ -2269,4 +2269,11 @@
helpTestRewriteCriteria(original, expected);
}
+ @Test public void testRewriteChar() {
+ String original = "convert(pm1.g1.e1, char) = '100'";
//$NON-NLS-1$
+ String expected = "1 = 0"; //$NON-NLS-1$
+
+ helpTestRewriteCriteria(original, expected);
+ }
+
}