Author: rareddy
Date: 2011-05-26 10:59:56 -0400 (Thu, 26 May 2011)
New Revision: 3200
Modified:
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
Log:
TEIID-1495: more teradata changes based on errors from BQT
Modified:
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java
===================================================================
---
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-25
22:13:57 UTC (rev 3199)
+++
branches/7.4.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teradata/TeradataExecutionFactory.java 2011-05-26
14:59:56 UTC (rev 3200)
@@ -68,19 +68,21 @@
convert.addTypeMapping("double precision", FunctionModifier.DOUBLE);
//$NON-NLS-1$
convert.addTypeMapping("numeric(18,0)", FunctionModifier.BIGINTEGER);
//$NON-NLS-1$
convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.INTEGER, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BIGDECIMAL, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BIGINTEGER, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.FLOAT, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.LONG, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.SHORT, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.DOUBLE, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.BYTE, FunctionModifier.STRING, new
ImplicitConvertModifier());
- convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new
TimeModifier("TIME")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new
TimeModifier("DATE")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new
TimeModifier("TIMESTAMP")); //$NON-NLS-1$
- convert.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new
TimeModifier("TIMESTAMP")); //$NON-NLS-1$
+
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new
CastModifier("TIME")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.DATE, new
CastModifier("DATE")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new
CastModifier("TIMESTAMP")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.DATE, FunctionModifier.TIMESTAMP, new
CastModifier("TIMESTAMP")); //$NON-NLS-1$
+
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.INTEGER, new
CastModifier("integer")); //$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BIGDECIMAL, new
CastModifier("decimal(37,5)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BIGINTEGER, new
CastModifier("numeric(18,0)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.FLOAT, new
CastModifier("float"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BOOLEAN, new
CastModifier("byteint"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.LONG, new
CastModifier("numeric(18,0)"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.SHORT, new
CastModifier("smallint"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.DOUBLE, new
CastModifier("double precision"));//$NON-NLS-1$
+ convert.addConvert(FunctionModifier.STRING, FunctionModifier.BYTE, new
CastModifier("byteint")); //$NON-NLS-1$
convert.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new
FunctionModifier() {
@Override
@@ -308,9 +310,6 @@
Expression expr2 = function.getParameters().get(1);
if (function.getParameters().size() > 2) {
Expression expr3 = function.getParameters().get(2);
- target.add("(");//$NON-NLS-1$
- target.add(expr3);
- target.add("+");//$NON-NLS-1$
target.add("position("); //$NON-NLS-1$
target.addAll(expressionToString(expr1, this.convertModifier));
target.add( " in "); //$NON-NLS-1$
@@ -318,8 +317,7 @@
target.addAll(expressionToString(expr2, this.convertModifier));
target.add(","); //$NON-NLS-1$
target.add(expr3);
- target.add(")"); //$NON-NLS-1$
- target.add("))"); //$NON-NLS-1$
+ target.add("))"); //$NON-NLS-1$
}
else {
target.add("position("); //$NON-NLS-1$
@@ -379,17 +377,9 @@
}
}
- public static class ImplicitConvertModifier extends FunctionModifier {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList(function.getParameters().get(0));
- }
- }
-
-
- public static class TimeModifier extends FunctionModifier {
+ public static class CastModifier extends FunctionModifier {
private String target;
- public TimeModifier(String target) {
+ public CastModifier(String target) {
this.target = target;
}
@Override
Modified:
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java
===================================================================
---
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-25
22:13:57 UTC (rev 3199)
+++
branches/7.4.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/teradata/TestTeradataTranslator.java 2011-05-26
14:59:56 UTC (rev 3200)
@@ -112,17 +112,21 @@
@Test public void testByteToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"string", "1");
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)1), Byte.class),
"string", "cast(1 AS varchar(4000))");
}
@Test public void testByte2ToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Byte((byte)-1), Byte.class),
"string", "-1");
+ helpTest(LANG_FACTORY.createLiteral(new Byte((byte)-1), Byte.class),
"string", "cast(-1 AS varchar(4000))");
}
@Test public void testDoubleToString() throws Exception {
- helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class),
"string", "1.0");
+ helpTest(LANG_FACTORY.createLiteral(new Double(1.0), Double.class),
"string", "cast(1.0 AS varchar(4000))");
}
+ @Test public void testStringToDouble() throws Exception {
+ helpTest(LANG_FACTORY.createLiteral("1.0", String.class),
"double", "cast('1.0' AS double precision)");
+ }
+
@Test public void testInDecompose() throws Exception {
Expression left = LANG_FACTORY.createLiteral("1", String.class);
List<Expression> right = new ArrayList<Expression>();
@@ -196,7 +200,7 @@
@Test public void testLocateFunction() throws Exception {
String input = "SELECT INTKEY, STRINGKEY, SHORTVALUE FROM BQT1.SmallA WHERE
(LOCATE(0, STRINGKEY) = 2) OR (LOCATE(2, SHORTVALUE, 4) = 6) ORDER BY intkey";
- String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM
SmallA WHERE position('0' in SmallA.StringKey) = 2 OR (4+position('2' in
substr(cast(SmallA.ShortValue AS varchar(100)),4))) = 6 ORDER BY SmallA.IntKey";
+ String out = "SELECT SmallA.IntKey, SmallA.StringKey, SmallA.ShortValue FROM
SmallA WHERE position('0' in SmallA.StringKey) = 2 OR position('2' in
substr(cast(SmallA.ShortValue AS varchar(100)),4)) = 6 ORDER BY SmallA.IntKey";
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, null, input, out,
TRANSLATOR);
}
}