Author: shawkins
Date: 2012-03-29 12:17:15 -0400 (Thu, 29 Mar 2012)
New Revision: 3957
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestInCriteriaImpl.java
Log:
TEIID-1966 adding support for expanding in pushdown
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-29
01:43:03 UTC (rev 3956)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/CapabilitiesConverter.java 2012-03-29
16:17:15 UTC (rev 3957)
@@ -63,7 +63,7 @@
tgtCaps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED,
srcCaps.supportsCompareCriteriaOrdered());
tgtCaps.setCapabilitySupport(Capability.CRITERIA_LIKE,
srcCaps.supportsLikeCriteria());
setSupports(connectorID, tgtCaps, Capability.CRITERIA_LIKE_ESCAPE,
srcCaps.supportsLikeCriteriaEscapeCharacter(), Capability.CRITERIA_LIKE);
- tgtCaps.setCapabilitySupport(Capability.CRITERIA_IN,
srcCaps.supportsInCriteria());
+ tgtCaps.setCapabilitySupport(Capability.CRITERIA_IN, srcCaps.supportsInCriteria()
|| (srcCaps.supportsCompareCriteriaEquals() && srcCaps.supportsOrCriteria()));
tgtCaps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY,
srcCaps.supportsInCriteriaSubquery());
tgtCaps.setCapabilitySupport(Capability.CRITERIA_ISNULL,
srcCaps.supportsIsNullCriteria());
tgtCaps.setCapabilitySupport(Capability.CRITERIA_OR,
srcCaps.supportsOrCriteria());
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-03-29
01:43:03 UTC (rev 3956)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-03-29
16:17:15 UTC (rev 3957)
@@ -219,6 +219,7 @@
Command command = this.requestMsg.getCommand();
this.expectedColumns = command.getProjectedSymbols().size();
LanguageBridgeFactory factory = new LanguageBridgeFactory(queryMetadata);
+ factory.setConvertIn(!this.connector.supportsInCriteria());
this.translatedCommand = factory.translate(command);
RuntimeMetadata rmd = new RuntimeMetadataImpl(queryMetadata);
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-03-29
01:43:03 UTC (rev 3956)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2012-03-29
16:17:15 UTC (rev 3957)
@@ -35,37 +35,10 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.AndOr;
-import org.teiid.language.Argument;
-import org.teiid.language.BatchedUpdates;
-import org.teiid.language.Call;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Condition;
+import org.teiid.language.*;
import org.teiid.language.DerivedColumn;
-import org.teiid.language.DerivedTable;
-import org.teiid.language.Exists;
-import org.teiid.language.ExpressionValueSource;
-import org.teiid.language.In;
-import org.teiid.language.InsertValueSource;
-import org.teiid.language.IsNull;
-import org.teiid.language.IteratorValueSource;
-import org.teiid.language.Join;
-import org.teiid.language.Like;
-import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
-import org.teiid.language.Not;
-import org.teiid.language.QueryExpression;
-import org.teiid.language.SearchedCase;
-import org.teiid.language.SearchedWhenClause;
import org.teiid.language.Select;
-import org.teiid.language.SortSpecification;
-import org.teiid.language.SubqueryComparison;
-import org.teiid.language.SubqueryIn;
-import org.teiid.language.TableReference;
import org.teiid.language.WindowSpecification;
-import org.teiid.language.With;
-import org.teiid.language.WithItem;
import org.teiid.language.Argument.Direction;
import org.teiid.language.Comparison.Operator;
import org.teiid.language.SortSpecification.Ordering;
@@ -74,62 +47,37 @@
import org.teiid.metadata.ProcedureParameter;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.sql.lang.BatchedUpdateCommand;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.Delete;
-import org.teiid.query.sql.lang.ExistsCriteria;
-import org.teiid.query.sql.lang.FromClause;
import org.teiid.query.sql.lang.GroupBy;
import org.teiid.query.sql.lang.Insert;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.JoinPredicate;
-import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.Limit;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.NotCriteria;
import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.SetClause;
-import org.teiid.query.sql.lang.SetClauseList;
-import org.teiid.query.sql.lang.SetCriteria;
import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.SubqueryCompareCriteria;
-import org.teiid.query.sql.lang.SubqueryFromClause;
-import org.teiid.query.sql.lang.SubquerySetCriteria;
-import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.WithQueryCommand;
-import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
-import org.teiid.query.sql.symbol.Constant;
-import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.*;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
-import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.symbol.SearchedCaseExpression;
-import org.teiid.query.sql.symbol.SelectSymbol;
-import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.WindowFunction;
import org.teiid.translator.TranslatorException;
public class LanguageBridgeFactory {
private RuntimeMetadataImpl metadataFactory = null;
+ private boolean convertIn;
public LanguageBridgeFactory(QueryMetadataInterface metadata) {
if (metadata != null) {
metadataFactory = new RuntimeMetadataImpl(metadata);
}
}
+
+ public void setConvertIn(boolean convertIn) {
+ this.convertIn = convertIn;
+ }
public org.teiid.language.Command translate(Command command) {
if (command == null) return null;
@@ -372,13 +320,25 @@
return like;
}
- In translate(SetCriteria criteria) {
+ Condition translate(SetCriteria criteria) {
Collection expressions = criteria.getValues();
List<org.teiid.language.Expression> translatedExpressions = new
ArrayList<org.teiid.language.Expression>();
for (Iterator i = expressions.iterator(); i.hasNext();) {
translatedExpressions.add(translate((Expression)i.next()));
}
- return new In(translate(criteria.getExpression()),
+ org.teiid.language.Expression expr = translate(criteria.getExpression());
+ if (convertIn) {
+ Condition condition = null;
+ for (org.teiid.language.Expression expression : translatedExpressions) {
+ if (condition == null) {
+ condition = new Comparison(expr, expression,
criteria.isNegated()?Operator.NE:Operator.EQ);
+ } else {
+ condition = new AndOr(new Comparison(expr, expression,
criteria.isNegated()?Operator.NE:Operator.EQ), condition,
criteria.isNegated()?AndOr.Operator.AND:AndOr.Operator.OR);
+ }
+ }
+ return condition;
+ }
+ return new In(expr,
translatedExpressions,
criteria.isNegated());
}
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestInCriteriaImpl.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestInCriteriaImpl.java 2012-03-29
01:43:03 UTC (rev 3956)
+++
branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestInCriteriaImpl.java 2012-03-29
16:17:15 UTC (rev 3957)
@@ -22,30 +22,24 @@
package org.teiid.dqp.internal.datamgr;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
+import org.junit.Test;
+import org.teiid.language.AndOr;
import org.teiid.language.Expression;
import org.teiid.language.In;
import org.teiid.language.Literal;
+import org.teiid.language.AndOr.Operator;
import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.unittest.RealMetadataFactory;
+public class TestInCriteriaImpl {
-import junit.framework.TestCase;
-
-public class TestInCriteriaImpl extends TestCase {
-
- /**
- * Constructor for TestInCriteriaImpl.
- * @param name
- */
- public TestInCriteriaImpl(String name) {
- super(name);
- }
-
public static SetCriteria helpExample(boolean negated) {
- ArrayList values = new ArrayList();
+ ArrayList<org.teiid.query.sql.symbol.Expression> values = new
ArrayList<org.teiid.query.sql.symbol.Expression>();
values.add(TestLiteralImpl.helpExample(100));
values.add(TestLiteralImpl.helpExample(200));
values.add(TestLiteralImpl.helpExample(300));
@@ -59,24 +53,31 @@
return (In)TstLanguageBridgeFactory.factory.translate(helpExample(negated));
}
- public void testGetLeftExpression() throws Exception {
+ @Test public void testGetLeftExpression() throws Exception {
In inCriteria = example(false);
assertNotNull(inCriteria.getLeftExpression());
assertTrue(inCriteria.getLeftExpression() instanceof Literal);
assertEquals(new Integer(300),
((Literal)inCriteria.getLeftExpression()).getValue());
}
+
+ @Test public void testExpansion() throws Exception {
+ SetCriteria inCriteria = helpExample(false);
+ LanguageBridgeFactory lbf = new
LanguageBridgeFactory(RealMetadataFactory.example1Cached());
+ lbf.setConvertIn(true);
+ AndOr or = (AndOr) lbf.translate(inCriteria);
+ assertEquals(Operator.OR, or.getOperator());
+ inCriteria.setNegated(true);
+ AndOr and = (AndOr) lbf.translate(inCriteria);
+ assertEquals(Operator.AND, and.getOperator());
+ }
- public void testGetRightExpressions() throws Exception {
- List values = example(false).getRightExpressions();
+ @Test public void testGetRightExpressions() throws Exception {
+ List<Expression> values = example(false).getRightExpressions();
assertNotNull(values);
assertEquals(4, values.size());
- for (Iterator i = values.iterator(); i.hasNext();) {
- assertTrue(i.next() instanceof Expression);
- }
-
}
- public void testIsNegated() throws Exception {
+ @Test public void testIsNegated() throws Exception {
assertTrue(example(true).isNegated());
assertFalse(example(false).isNegated());
}
Show replies by date