Author: shawkins
Date: 2009-05-19 16:37:31 -0400 (Tue, 19 May 2009)
New Revision: 981
Added:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestUtil.java
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
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/oracle/TestExtractFunctionModifier.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-473 fix for extract function modifier
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-05-19
18:17:30 UTC (rev 980)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/ExtractFunctionModifier.java 2009-05-19
20:37:31 UTC (rev 981)
@@ -26,7 +26,6 @@
import java.util.List;
import org.teiid.connector.jdbc.translator.BasicFunctionModifier;
-import org.teiid.connector.jdbc.translator.FunctionModifier;
import org.teiid.connector.language.IExpression;
import org.teiid.connector.language.IFunction;
@@ -35,7 +34,7 @@
* Convert the YEAR/MONTH/DAY etc. function into an equivalent Oracle function.
* Format: EXTRACT(YEAR from Element) or EXTRACT(YEAR from DATE '2004-03-03')
*/
-public class ExtractFunctionModifier extends BasicFunctionModifier implements
FunctionModifier {
+public class ExtractFunctionModifier extends BasicFunctionModifier {
public static final String SPACE = " "; //$NON-NLS-1$
private String target;
@@ -44,20 +43,17 @@
this.target = target;
}
- public List translate(IFunction function) {
- StringBuffer buffer = new StringBuffer();
+ public List<?> translate(IFunction function) {
List<IExpression> args = function.getParameters();
- List objs = new ArrayList();
- buffer.append("EXTRACT("); //$NON-NLS-1$
- buffer.append(target);
- buffer.append(SPACE);
- buffer.append("FROM"); //$NON-NLS-1$
-
- buffer.append(SPACE);
- buffer.append(args.get(0));
- buffer.append(")"); //$NON-NLS-1$
- objs.add(buffer.toString());
+ List<Object> objs = new ArrayList<Object>();
+ objs.add("EXTRACT("); //$NON-NLS-1$
+ objs.add(target);
+ objs.add(SPACE);
+ objs.add("FROM"); //$NON-NLS-1$
+ objs.add(SPACE);
+ objs.add(args.get(0));
+ objs.add(")"); //$NON-NLS-1$
return objs;
}
}
Added:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestUtil.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestUtil.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestUtil.java 2009-05-19
20:37:31 UTC (rev 981)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.connector.jdbc;
+
+import static org.junit.Assert.*;
+
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.jdbc.translator.TranslatedCommand;
+import org.teiid.connector.jdbc.translator.Translator;
+import org.teiid.connector.language.ICommand;
+
+import com.metamatrix.cdk.api.EnvironmentUtility;
+
+public class TestUtil {
+
+ public static void helpTestVisitor(String vdb, String input, String expectedOutput,
Translator translator) throws ConnectorException {
+ // Convert from sql to objects
+ ICommand obj = MetadataFactory.helpTranslate(vdb, input);
+
+ TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), translator);
//$NON-NLS-1$
+ tc.translateCommand(obj);
+
+ // Check stuff
+ assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/TestUtil.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2009-05-19
18:17:30 UTC (rev 980)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/mysql/TestMySQLTranslator.java 2009-05-19
20:37:31 UTC (rev 981)
@@ -22,17 +22,13 @@
package org.teiid.connector.jdbc.mysql;
-import static org.junit.Assert.*;
-
import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import org.teiid.connector.jdbc.translator.Translator;
-import org.teiid.connector.language.ICommand;
+import org.teiid.connector.jdbc.TestUtil;
import com.metamatrix.cdk.api.EnvironmentUtility;
@@ -55,22 +51,11 @@
return MetadataFactory.BQT_VDB;
}
- public static void helpTestVisitor(String vdb, String input, String expectedOutput,
Translator translator) throws ConnectorException {
- // Convert from sql to objects
- ICommand obj = MetadataFactory.helpTranslate(vdb, input);
-
- TranslatedCommand tc = new
TranslatedCommand(EnvironmentUtility.createSecurityContext("user"), translator);
//$NON-NLS-1$
- tc.translateCommand(obj);
-
- // Check stuff
- assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- }
-
@Test public void testRewriteConversion1() throws Exception {
String input = "SELECT char(convert(PART_WEIGHT, integer) + 100) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT char((convert(PARTS.PART_WEIGHT, SIGNED INTEGER) +
100)) FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -79,7 +64,7 @@
String input = "SELECT convert(PART_WEIGHT, long) FROM PARTS";
//$NON-NLS-1$
String output = "SELECT convert(PARTS.PART_WEIGHT, SIGNED) FROM PARTS";
//$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -88,7 +73,7 @@
String input = "SELECT convert(convert(PART_WEIGHT, long), string) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT convert(convert(PARTS.PART_WEIGHT, SIGNED), CHAR)
FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -97,7 +82,7 @@
String input = "SELECT convert(convert(PART_WEIGHT, date), string) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT date_format(DATE(PARTS.PART_WEIGHT),
'%Y-%m-%d') FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -105,7 +90,7 @@
String input = "SELECT convert(convert(PART_WEIGHT, time), string) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT date_format(TIME(PARTS.PART_WEIGHT),
'%H:%i:%S') FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -113,7 +98,7 @@
String input = "SELECT convert(convert(PART_WEIGHT, timestamp), string) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT date_format(TIMESTAMP(PARTS.PART_WEIGHT),
'%Y-%m-%d %H:%i:%S.%f') FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -121,7 +106,7 @@
String input = "SELECT ifnull(PART_WEIGHT, 'otherString') FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT ifnull(PARTS.PART_WEIGHT, 'otherString')
FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -129,7 +114,7 @@
String input = "SELECT convert(convert(PART_WEIGHT, integer), string) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT convert(convert(PARTS.PART_WEIGHT, SIGNED INTEGER),
CHAR) FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -137,7 +122,7 @@
String input = "SELECT insert(PART_WEIGHT, 1, 5, 'chimp') FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT insert(PARTS.PART_WEIGHT, 1, 5, 'chimp')
FROM PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -145,7 +130,7 @@
String input = "SELECT locate(PART_WEIGHT, 'chimp', 1) FROM
PARTS"; //$NON-NLS-1$
String output = "SELECT locate(PARTS.PART_WEIGHT, 'chimp', 1) FROM
PARTS"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -153,7 +138,7 @@
String input = "SELECT substring(PART_WEIGHT, 1) FROM PARTS";
//$NON-NLS-1$
String output = "SELECT substring(PARTS.PART_WEIGHT, 1) FROM PARTS";
//$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -161,7 +146,7 @@
String input = "SELECT substring(PART_WEIGHT, 1, 5) FROM PARTS";
//$NON-NLS-1$
String output = "SELECT substring(PARTS.PART_WEIGHT, 1, 5) FROM PARTS";
//$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -169,7 +154,7 @@
String input = "SELECT PART_ID FROM PARTS UNION SELECT PART_ID FROM PARTS
ORDER BY PART_ID"; //$NON-NLS-1$
String output = "(SELECT PARTS.PART_ID FROM PARTS) UNION (SELECT
PARTS.PART_ID FROM PARTS) ORDER BY PART_ID"; //$NON-NLS-1$
- helpTestVisitor(getTestVDB(),
+ TestUtil.helpTestVisitor(getTestVDB(),
input,
output, TRANSLATOR);
}
@@ -178,7 +163,7 @@
String input = "select intkey from bqt1.smalla limit 100";
//$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA LIMIT 100";
//$NON-NLS-1$
- helpTestVisitor(getTestBQTVDB(),
+ TestUtil.helpTestVisitor(getTestBQTVDB(),
input,
output, TRANSLATOR);
}
@@ -187,7 +172,7 @@
String input = "select intkey from bqt1.smalla limit 50, 100";
//$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA LIMIT 50, 100";
//$NON-NLS-1$
- helpTestVisitor(getTestBQTVDB(),
+ TestUtil.helpTestVisitor(getTestBQTVDB(),
input,
output, TRANSLATOR);
}
@@ -196,7 +181,7 @@
String input = "select bitand(intkey, intnum) from bqt1.smalla";
//$NON-NLS-1$
String output = "SELECT convert((SmallA.IntKey & SmallA.IntNum), SIGNED
INTEGER) FROM SmallA"; //$NON-NLS-1$
- TestMySQLTranslator.helpTestVisitor(MetadataFactory.BQT_VDB,
+ TestUtil.helpTestVisitor(MetadataFactory.BQT_VDB,
input,
output, TRANSLATOR);
}
@@ -205,7 +190,7 @@
String input = "select smalla.intkey from bqt1.smalla inner join bqt1.smallb
on smalla.stringkey=smallb.stringkey cross join bqt1.mediuma"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM (SmallA INNER JOIN SmallB ON
SmallA.StringKey = SmallB.StringKey) CROSS JOIN MediumA"; //$NON-NLS-1$
- TestMySQLTranslator.helpTestVisitor(MetadataFactory.BQT_VDB,
+ TestUtil.helpTestVisitor(MetadataFactory.BQT_VDB,
input,
output, TRANSLATOR);
}
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-05-19
18:17:30 UTC (rev 980)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestExtractFunctionModifier.java 2009-05-19
20:37:31 UTC (rev 981)
@@ -24,6 +24,7 @@
import java.sql.Timestamp;
import java.util.Arrays;
+import java.util.List;
import java.util.Properties;
import org.teiid.connector.api.TypeFacility;
@@ -64,18 +65,17 @@
ExtractFunctionModifier mod = new ExtractFunctionModifier (target);
IExpression expr = mod.modify(func);
-
+ List<?> parts = mod.translate(func);
+ assertEquals(7, parts.size());
+ assertFalse(parts.get(5) instanceof String);
OracleSQLTranslator trans = new OracleSQLTranslator();
trans.registerFunctionModifier("extract", mod);
trans.initialize(EnvironmentUtility.createEnvironment(new Properties(), false));
SQLConversionVisitor sqlVisitor = trans.getSQLConversionVisitor();
- //sqlVisitor.setFunctionModifiers(trans.getFunctionModifiers());
sqlVisitor.append(expr);
- //System.out.println(" expected: " + expectedStr + " \t actual:
" + sqlVisitor.toString());
assertEquals(expectedStr, sqlVisitor.toString());
-
return expr;
}
public void test1() throws Exception {
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java 2009-05-19
18:17:30 UTC (rev 980)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java 2009-05-19
20:37:31 UTC (rev 981)
@@ -28,7 +28,7 @@
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.mysql.TestMySQLTranslator;
+import org.teiid.connector.jdbc.TestUtil;
import org.teiid.connector.jdbc.translator.TranslatedCommand;
import org.teiid.connector.jdbc.translator.Translator;
import org.teiid.connector.language.ICommand;
@@ -72,7 +72,7 @@
String input = "select smalla.intkey from bqt1.smalla inner join bqt1.smallb
on smalla.stringkey=smallb.stringkey cross join bqt1.mediuma"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA INNER JOIN SmallB ON
SmallA.StringKey = SmallB.StringKey CROSS JOIN MediumA"; //$NON-NLS-1$
- TestMySQLTranslator.helpTestVisitor(MetadataFactory.BQT_VDB,
+ TestUtil.helpTestVisitor(MetadataFactory.BQT_VDB,
input,
output, TRANSLATOR);
}
@@ -81,7 +81,7 @@
String input = "select smalla.intkey from bqt1.smalla cross join
(bqt1.smallb cross join bqt1.mediuma)"; //$NON-NLS-1$
String output = "SELECT SmallA.IntKey FROM SmallA CROSS JOIN (SmallB CROSS
JOIN MediumA)"; //$NON-NLS-1$
- TestMySQLTranslator.helpTestVisitor(MetadataFactory.BQT_VDB,
+ TestUtil.helpTestVisitor(MetadataFactory.BQT_VDB,
input,
output, TRANSLATOR);
}