Author: shawkins
Date: 2011-04-25 11:09:21 -0400 (Mon, 25 Apr 2011)
New Revision: 3113
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseSQLConversionVisitor.java
Log:
TEIID-1567 removing the use of cross join syntax for sybase
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2011-04-20
20:51:20 UTC (rev 3112)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2011-04-25
15:09:21 UTC (rev 3113)
@@ -30,6 +30,7 @@
import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.language.Join;
+import org.teiid.language.LanguageFactory;
import org.teiid.language.LanguageObject;
import org.teiid.language.Limit;
import org.teiid.language.Literal;
@@ -126,14 +127,7 @@
@Override
public List<?> translate(LanguageObject obj, ExecutionContext context) {
//DB2 doesn't support cross join
- if (obj instanceof Join) {
- Join join = (Join)obj;
- if (join.getJoinType() == JoinType.CROSS_JOIN) {
- Literal one = getLanguageFactory().createLiteral(1,
TypeFacility.RUNTIME_TYPES.INTEGER);
- join.setCondition(getLanguageFactory().createCompareCriteria(Operator.EQ, one,
one));
- join.setJoinType(JoinType.INNER_JOIN);
- }
- }
+ convertCrossJoinToInner(obj, getLanguageFactory());
//DB2 needs projected nulls wrapped in casts
if (obj instanceof DerivedColumn) {
DerivedColumn selectSymbol = (DerivedColumn)obj;
@@ -151,6 +145,16 @@
return super.translate(obj, context);
}
+ public static void convertCrossJoinToInner(LanguageObject obj, LanguageFactory lf) {
+ if (obj instanceof Join) {
+ Join join = (Join)obj;
+ if (join.getJoinType() == JoinType.CROSS_JOIN) {
+ Literal one = lf.createLiteral(1, TypeFacility.RUNTIME_TYPES.INTEGER);
+ join.setCondition(lf.createCompareCriteria(Operator.EQ, one, one));
+ join.setJoinType(JoinType.INNER_JOIN);
+ }
+ }
+ }
@Override
public NullOrder getDefaultNullOrder() {
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-04-20
20:51:20 UTC (rev 3112)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-04-25
15:09:21 UTC (rev 3113)
@@ -211,5 +211,10 @@
public boolean supportsCommonTableExpressions() {
return true;
}
+
+ @Override
+ protected boolean supportsCrossJoin() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2011-04-20
20:51:20 UTC (rev 3112)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2011-04-25
15:09:21 UTC (rev 3113)
@@ -37,6 +37,7 @@
import org.teiid.language.Command;
import org.teiid.language.Function;
+import org.teiid.language.LanguageObject;
import org.teiid.language.Limit;
import org.teiid.language.OrderBy;
import org.teiid.language.SetQuery;
@@ -51,6 +52,7 @@
import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.ModFunctionModifier;
+import org.teiid.translator.jdbc.db2.DB2ExecutionFactory;
import org.teiid.translator.jdbc.oracle.ConcatFunctionModifier;
@@ -232,6 +234,14 @@
return parts;
}
+ @Override
+ public List<?> translate(LanguageObject obj, ExecutionContext context) {
+ if (!supportsCrossJoin()) {
+ DB2ExecutionFactory.convertCrossJoinToInner(obj, getLanguageFactory());
+ }
+ return super.translate(obj, context);
+ }
+
@SuppressWarnings("unchecked")
@Override
public List<?> translateLimit(Limit limit, ExecutionContext context) {
@@ -377,4 +387,8 @@
return "CAST('" + formatDateValue(dateValue) +"' AS
DATE)"; //$NON-NLS-1$ //$NON-NLS-2$
}
+ protected boolean supportsCrossJoin() {
+ return false;
+ }
+
}
Modified:
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseSQLConversionVisitor.java
===================================================================
---
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2011-04-20
20:51:20 UTC (rev 3112)
+++
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/sybase/TestSybaseSQLConversionVisitor.java 2011-04-25
15:09:21 UTC (rev 3113)
@@ -242,6 +242,13 @@
input,
output);
}
+
+ @Test public void testCrossJoin() throws Exception {
+ String input = "select smalla.intnum from (bqt1.smalla cross join bqt1.smallb)
left outer join bqt1.mediuma on (smalla.intnum = mediuma.intnum)"; //$NON-NLS-1$
+ String output = "SELECT SmallA.IntNum FROM SmallA INNER JOIN SmallB ON 1 = 1
LEFT OUTER JOIN MediumA ON SmallA.IntNum = MediumA.IntNum"; //$NON-NLS-1$
+
+ helpTestVisitor(getBQTVDB(), input, output);
+ }
}