Author: shawkins
Date: 2010-01-19 22:58:44 -0500 (Tue, 19 Jan 2010)
New Revision: 1758
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
Log:
TEIID-934 fix to mysql lpad/rpad with two arguments
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2010-01-19
22:22:14 UTC (rev 1757)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/mysql/MySQLTranslator.java 2010-01-20
03:58:44 UTC (rev 1758)
@@ -35,6 +35,7 @@
import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.jdbc.translator.ConvertModifier;
import org.teiid.connector.jdbc.translator.FunctionModifier;
import org.teiid.connector.jdbc.translator.LocateFunctionModifier;
@@ -46,6 +47,19 @@
*/
public class MySQLTranslator extends Translator {
+ /**
+ * Adds support for the 2 argument form of padding
+ */
+ private final class PadFunctionModifier extends FunctionModifier {
+ @Override
+ public List<?> translate(IFunction function) {
+ if (function.getParameters().size() == 2) {
+ function.getParameters().add(getLanguageFactory().createLiteral(" ",
TypeFacility.RUNTIME_TYPES.STRING)); //$NON-NLS-1$
+ }
+ return null;
+ }
+ }
+
@Override
public void initialize(ConnectorEnvironment env) throws ConnectorException {
super.initialize(env);
@@ -54,7 +68,8 @@
registerFunctionModifier(SourceSystemFunctions.BITOR, new
BitFunctionModifier("|", getLanguageFactory())); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.BITXOR, new
BitFunctionModifier("^", getLanguageFactory())); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOCATE, new
LocateFunctionModifier(getLanguageFactory()));
-
+ registerFunctionModifier(SourceSystemFunctions.LPAD, new PadFunctionModifier());
+ registerFunctionModifier(SourceSystemFunctions.RPAD, new PadFunctionModifier());
//add in type conversion
ConvertModifier convertModifier = new ConvertModifier();
convertModifier.addTypeMapping("signed", FunctionModifier.BYTE,
FunctionModifier.SHORT, FunctionModifier.INTEGER, FunctionModifier.LONG); //$NON-NLS-1$
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-19
22:22:14 UTC (rev 1757)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2010-01-20
03:58:44 UTC (rev 1758)
@@ -313,5 +313,14 @@
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
input,
output, TRANSLATOR);
+ }
+
+ @Test public void testPad() throws Exception {
+ String input = "select lpad(smalla.stringkey, 18), rpad(smalla.stringkey,
12) from bqt1.smalla"; //$NON-NLS-1$
+ String output = "SELECT lpad(SmallA.StringKey, 18, ' '),
rpad(SmallA.StringKey, 12, ' ') FROM SmallA"; //$NON-NLS-1$
+
+ TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
+ input,
+ output, TRANSLATOR);
}
}
Show replies by date