Author: shawkins
Date: 2010-12-31 20:41:28 -0500 (Fri, 31 Dec 2010)
New Revision: 2810
Modified:
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
branches/7.1.x/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
Log:
TEIID-1410 fix for malformed query with no outer colums
Modified:
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
===================================================================
---
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2010-12-24
21:23:50 UTC (rev 2809)
+++
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2011-01-01
01:41:28 UTC (rev 2810)
@@ -110,12 +110,12 @@
}
StringBuffer select = new StringBuffer();
select.append(SELECT).append(SPACE);
- addSelectSymbols(leftTableInJoin.getNameInSource(), select);
- select.append(COMMA).append(SPACE).append(OPEN);
+ addSelect(leftTableInJoin.getNameInSource(), select, true);
+ select.append(OPEN);
StringBuffer subselect = new StringBuffer();
subselect.append(SELECT).append(SPACE);
- addSelectSymbols(rightTableInJoin.getNameInSource(), subselect);
+ addSelect(rightTableInJoin.getNameInSource(), subselect, false);
subselect.append(SPACE);
subselect.append(FROM).append(SPACE);
subselect.append(rightTableInJoin.getNameInSource()).append('s');
@@ -133,7 +133,7 @@
return childTable.equals(leftTableInJoin);
}
- protected void addSelectSymbols(String tableNameInSource, StringBuffer result) throws
TranslatorException {
+ void addSelect(String tableNameInSource, StringBuffer result, boolean addComma) {
boolean firstTime = true;
for (DerivedColumn symbol : selectSymbols) {
Expression expression = symbol.getExpression();
@@ -143,23 +143,30 @@
if(!isParentToChildJoin() && tableNameInSource.equals(tableName) ||
isParentToChildJoin()) {
if (!firstTime) {
- result.append(", ");
+ result.append(", "); //$NON-NLS-1$
} else {
firstTime = false;
}
result.append(tableName);
result.append('.');
result.append(element.getNameInSource());
+ } else {
+ continue;
}
} else if (expression instanceof AggregateFunction) {
if (!firstTime) {
- result.append(", ");
+ result.append(", "); //$NON-NLS-1$
} else {
firstTime = false;
}
result.append("count()"); //$NON-NLS-1$
+ } else {
+ throw new AssertionError("Unknown select symbol type" + symbol);
//$NON-NLS-1$
}
}
+ if (!firstTime && addComma) {
+ result.append(", "); //$NON-NLS-1$
+ }
}
}
Modified:
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
===================================================================
---
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2010-12-24
21:23:50 UTC (rev 2809)
+++
branches/7.1.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2011-01-01
01:41:28 UTC (rev 2810)
@@ -122,7 +122,7 @@
}
StringBuffer result = new StringBuffer();
result.append(SELECT).append(SPACE);
- addSelectSymbols(table.getNameInSource(), result);
+ addSelectSymbols(result);
result.append(SPACE);
result.append(FROM).append(SPACE);
result.append(table.getNameInSource()).append(SPACE);
@@ -133,7 +133,7 @@
return result.toString();
}
- protected void addSelectSymbols(String tableNameInSource, StringBuffer result) throws
TranslatorException {
+ private void addSelectSymbols(StringBuffer result) throws TranslatorException {
boolean firstTime = true;
for (DerivedColumn symbol : selectSymbols) {
if (!firstTime) {
@@ -204,7 +204,7 @@
public String getRetrieveFieldList() throws TranslatorException {
assertRetrieveValidated();
StringBuffer result = new StringBuffer();
- addSelectSymbols(table.getNameInSource(), result);
+ addSelectSymbols(result);
return result.toString();
}
Modified:
branches/7.1.x/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
===================================================================
---
branches/7.1.x/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2010-12-24
21:23:50 UTC (rev 2809)
+++
branches/7.1.x/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2011-01-01
01:41:28 UTC (rev 2810)
@@ -169,6 +169,13 @@
assertEquals("SELECT Account.AccountName, (SELECT Contact.ContactName FROM
Contacts) FROM Account", visitor.getQuery().toString().trim()); //$NON-NLS-1$
}
+ @Test public void testJoin3() throws Exception {
+ Select command = (Select)translationUtility.parseCommand("SELECT Contacts.Name
FROM Account LEFT OUTER JOIN Contacts ON Account.Id = Contacts.AccountId");
//$NON-NLS-1$
+ SelectVisitor visitor = new
JoinQueryVisitor(translationUtility.createRuntimeMetadata());
+ visitor.visit(command);
+ assertEquals("SELECT (SELECT Contact.ContactName FROM Contacts) FROM
Account", visitor.getQuery().toString().trim()); //$NON-NLS-1$
+ }
+
@Test public void testInWithNameInSourceDifferent() throws Exception {
Select command = (Select)translationUtility.parseCommand("SELECT Contacts.Name
FROM Contacts WHERE Contacts.Name in ('x', 'y')"); //$NON-NLS-1$
SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
Show replies by date