Author: shawkins
Date: 2010-11-04 22:27:49 -0400 (Thu, 04 Nov 2010)
New Revision: 2706
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
branches/7.1.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.1.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-1346 refining translate criteria logic and adding logging to cache usage.
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-11-04
22:07:24 UTC (rev 2705)
+++
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-11-05
02:27:49 UTC (rev 2706)
@@ -340,23 +340,29 @@
boolean canUseCached = (requestMsg.useResultSetCache() ||
QueryParser.getQueryParser().parseCacheHint(requestMsg.getCommandString()) != null);
- if (rsCache != null && canUseCached) {
- ParseInfo pi = Request.createParseInfo(requestMsg);
- cacheId = new CacheID(this.dqpWorkContext, pi, requestMsg.getCommandString());
- cachable = cacheId.setParameters(requestMsg.getParameterValues());
- if (cachable) {
- CachedResults cr = rsCache.get(cacheId);
- if (cr != null) {
- this.resultsBuffer = cr.getResults();
- this.analysisRecord = cr.getAnalysisRecord();
- request.initMetadata();
- this.originalCommand = cr.getCommand(requestMsg.getCommandString(),
request.metadata, pi);
- request.validateAccess(this.originalCommand);
- this.doneProducingBatches();
- return;
+ if (rsCache != null) {
+ if (!canUseCached) {
+ LogManager.logDetail(LogConstants.CTX_DQP, requestID, "No cache
directive"); //$NON-NLS-1$
+ } else {
+ ParseInfo pi = Request.createParseInfo(requestMsg);
+ cacheId = new CacheID(this.dqpWorkContext, pi, requestMsg.getCommandString());
+ cachable = cacheId.setParameters(requestMsg.getParameterValues());
+ if (cachable) {
+ CachedResults cr = rsCache.get(cacheId);
+ if (cr != null) {
+ this.resultsBuffer = cr.getResults();
+ this.analysisRecord = cr.getAnalysisRecord();
+ request.initMetadata();
+ this.originalCommand = cr.getCommand(requestMsg.getCommandString(),
request.metadata, pi);
+ request.validateAccess(this.originalCommand);
+ this.doneProducingBatches();
+ return;
+ }
+ } else {
+ LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Parameters are not
serializable - cache cannot be used for", cacheId); //$NON-NLS-1$
}
}
- }
+ }
request.processRequest();
originalCommand = request.userCommand;
if (cachable && (requestMsg.useResultSetCache() ||
originalCommand.getCacheHint() != null) && rsCache != null &&
originalCommand.areResultsCachable()) {
@@ -365,6 +371,7 @@
processor = request.processor;
resultsBuffer = processor.createTupleBuffer();
if (this.cid != null && originalCommand.getCacheHint() != null) {
+ LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Using cache hint",
originalCommand.getCacheHint()); //$NON-NLS-1$
resultsBuffer.setPrefersMemory(originalCommand.getCacheHint().getPrefersMemory());
}
collector = new BatchCollector(processor, resultsBuffer) {
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-11-04
22:07:24 UTC (rev 2705)
+++
branches/7.1.x/engine/src/main/java/org/teiid/dqp/internal/process/SessionAwareCache.java 2010-11-05
02:27:49 UTC (rev 2706)
@@ -39,6 +39,8 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
import org.teiid.query.function.metadata.FunctionMethod;
import org.teiid.query.parser.ParseInfo;
import org.teiid.vdb.runtime.VDBKey;
@@ -117,7 +119,10 @@
}
if (result != null) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Cache hit for", id);
//$NON-NLS-1$
cacheHit.getAndIncrement();
+ } else {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Cache miss for", id);
//$NON-NLS-1$
}
return result;
}
@@ -140,6 +145,7 @@
public void put(CacheID id, int determinismLevel, T t, Long ttl){
if (determinismLevel >= FunctionMethod.SESSION_DETERMINISTIC) {
id.setSessionId(id.originalSessionId);
+ LogManager.logTrace(LogConstants.CTX_DQP, "Adding to session/local cache",
id); //$NON-NLS-1$
this.localCache.put(id, t, ttl);
}
else {
@@ -161,6 +167,7 @@
}
if (insert) {
+ LogManager.logTrace(LogConstants.CTX_DQP, "Adding to global/distributed
cache", id); //$NON-NLS-1$
this.distributedCache.put(id, t, ttl);
}
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-11-04
22:07:24 UTC (rev 2705)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-11-05
02:27:49 UTC (rev 2706)
@@ -114,7 +114,6 @@
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.PredicateCriteria.Negatable;
import org.teiid.query.sql.navigator.PostOrderNavigator;
-import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
@@ -544,31 +543,18 @@
if (!(userCmd instanceof TranslatableProcedureContainer)) {
return FALSE_CRITERIA;
}
-
+
Criteria userCriteria = ((TranslatableProcedureContainer)userCmd).getCriteria();
-
- if(userCriteria == null) {
- return FALSE_CRITERIA;
+
+ if (userCriteria == null) {
+ return TRUE_CRITERIA;
}
// get the symbolmap between virtual elements and theie counterpart expressions
// from the virtual group's query transform
CriteriaTranslatorVisitor translateVisitor = new
CriteriaTranslatorVisitor(procCommand.getSymbolMap());
- // check if there is a CriteriaSelector specified to restrict
- // parts of user's criteria to be translated
- // get the CriteriaSelector, elements on the selector and the selector type
- CriteriaSelector selector = transCrit.getSelector();
- HasCriteria hasCrit = new HasCriteria(selector);
-
- // base on the selector evaluate Has criteria, if false
- // return a false criteria
- Criteria result = rewriteCriteria(hasCrit);
-
- if(result.equals(FALSE_CRITERIA)) {
- return FALSE_CRITERIA;
- }
- translateVisitor.setCriteriaSelector(selector);
+ translateVisitor.setCriteriaSelector(transCrit.getSelector());
if(transCrit.hasTranslations()) {
translateVisitor.setTranslations(transCrit.getTranslations());
}
@@ -576,14 +562,12 @@
// create a clone of user's criteria that is then translated
Criteria userClone = (Criteria) userCriteria.clone();
- // CriteriaTranslatorVisitor visits the user's criteria
- PreOrderNavigator.doVisit(userClone, translateVisitor);
+ translateVisitor.translate(userClone);
// translated criteria
- translatedCriteria = translateVisitor.getTranslatedCriteria();
((TranslatableProcedureContainer)userCmd).addImplicitParameters(translateVisitor.getImplicitParams());
- translatedCriteria = rewriteCriteria(translatedCriteria);
+ translatedCriteria = rewriteCriteria(userClone);
// apply any implicit conversions
try {
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java
===================================================================
---
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2010-11-04
22:07:24 UTC (rev 2705)
+++
branches/7.1.x/engine/src/main/java/org/teiid/query/sql/visitor/CriteriaTranslatorVisitor.java 2010-11-05
02:27:49 UTC (rev 2706)
@@ -22,22 +22,23 @@
package org.teiid.query.sql.visitor;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.Assertion;
+import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.BetweenCriteria;
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.DependentSetCriteria;
import org.teiid.query.sql.lang.IsNullCriteria;
import org.teiid.query.sql.lang.MatchCriteria;
import org.teiid.query.sql.lang.SetCriteria;
+import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -52,16 +53,108 @@
* of the elements those translations override any symbol mappings.</p>
*/
public class CriteriaTranslatorVisitor extends ExpressionMappingVisitor {
+
+ class CriteriaTranslatorNavigator extends PreOrderNavigator {
+ public CriteriaTranslatorNavigator() {
+ super(CriteriaTranslatorVisitor.this);
+ }
+
+ /**
+ * <p> This method updates the <code>BetweenCriteria</code> object
it receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions.</p>
+ * @param obj The BetweenCriteria object to be updated with translated expressions
+ */
+ public void visit(BetweenCriteria obj) {
+ if (!selectorContainsCriteriaElements(obj, CriteriaSelector.BETWEEN)) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+ super.visit(obj);
+ }
+
+ /**
+ * <p> This method updates the <code>CompareCriteria</code> object
it receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions.</p>
+ * @param obj The CompareCriteria object to be updated with translated expressions
+ */
+ public void visit(CompareCriteria obj) {
+
+ if (!selectorContainsCriteriaElements(obj, obj.getOperator())) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+
+ super.visit(obj);
+ }
+
+ /**
+ * <p> This method updates the <code>IsNullCriteria</code> object
it receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions.</p>
+ * @param obj The IsNullCriteria object to be updated with translated expressions
+ */
+ public void visit(IsNullCriteria obj) {
+
+ if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IS_NULL)) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+ super.visit(obj);
+ }
+
+ /**
+ * <p> This method updates the <code>MatchCriteria</code> object
it receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions</p>
+ * @param obj The SetCriteria object to be updated with translated expressions
+ */
+ public void visit(MatchCriteria obj) {
+
+ if (!selectorContainsCriteriaElements(obj, CriteriaSelector.LIKE)) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+
+ super.visit(obj);
+ }
+
+ /**
+ * <p> This method updates the <code>SetCriteria</code> object it
receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions</p>
+ * @param obj The SetCriteria object to be updated with translated expressions
+ */
+ public void visit(SetCriteria obj) {
+
+ if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IN)) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+
+ super.visit(obj);
+ }
+
+ /**
+ * <p> This method updates the <code>SetCriteria</code> object it
receives as an
+ * argument by replacing the virtual elements present in the expressions in the
+ * function with translated expressions</p>
+ * @param obj The SetCriteria object to be updated with translated expressions
+ */
+ public void visit(DependentSetCriteria obj) {
+
+ if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IN)) {
+ throw new TeiidRuntimeException(new
QueryValidatorException(QueryPlugin.Util.getString("Translate.error", obj,
selector))); //$NON-NLS-1$
+ }
+
+ super.visit(obj);
+ }
+
+ }
+
// criteria selector specified on the TranslateCriteria obj
private CriteriaSelector selector;
// translation in for of CompareCriteria objs on the TranslateCriteria obj
private Collection translations;
- // list of translated criteria
- private List<Criteria> translatedCriteria = new ArrayList<Criteria>();
-
private Map<ElementSymbol, Reference> implicitParams = new
HashMap<ElementSymbol, Reference>();
/**
@@ -101,101 +194,6 @@
this.translations = translations;
}
- // ############### Visitor methods for language objects ##################
-
- /**
- * <p> This method updates the <code>BetweenCriteria</code> object
it receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions.</p>
- * @param obj The BetweenCriteria object to be updated with translated expressions
- */
- public void visit(BetweenCriteria obj) {
- if (!selectorContainsCriteriaElements(obj, CriteriaSelector.BETWEEN)) {
- return;
- }
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
- /**
- * <p> This method updates the <code>CompareCriteria</code> object
it receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions.</p>
- * @param obj The CompareCriteria object to be updated with translated expressions
- */
- public void visit(CompareCriteria obj) {
-
- if (!selectorContainsCriteriaElements(obj, obj.getOperator())) {
- return;
- }
-
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
- /**
- * <p> This method updates the <code>IsNullCriteria</code> object
it receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions.</p>
- * @param obj The IsNullCriteria object to be updated with translated expressions
- */
- public void visit(IsNullCriteria obj) {
-
- if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IS_NULL)) {
- return;
- }
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
- /**
- * <p> This method updates the <code>MatchCriteria</code> object it
receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions</p>
- * @param obj The SetCriteria object to be updated with translated expressions
- */
- public void visit(MatchCriteria obj) {
-
- if (!selectorContainsCriteriaElements(obj, CriteriaSelector.LIKE)) {
- return;
- }
-
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
- /**
- * <p> This method updates the <code>SetCriteria</code> object it
receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions</p>
- * @param obj The SetCriteria object to be updated with translated expressions
- */
- public void visit(SetCriteria obj) {
-
- if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IN)) {
- return;
- }
-
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
- /**
- * <p> This method updates the <code>SetCriteria</code> object it
receives as an
- * argument by replacing the virtual elements present in the expressions in the
- * function with translated expressions</p>
- * @param obj The SetCriteria object to be updated with translated expressions
- */
- public void visit(DependentSetCriteria obj) {
-
- if (!selectorContainsCriteriaElements(obj, CriteriaSelector.IN)) {
- return;
- }
-
- super.visit(obj);
- translatedCriteria.add(obj);
- }
-
/* ############### Helper Methods ################## */
private boolean selectorContainsCriteriaElements(Criteria criteria, int criteriaType)
{
@@ -249,26 +247,17 @@
return super.replaceExpression(obj);
}
- /**
- * <p>Gets the criteria translated by this visitor, differrent parts of the
user's
- * criteria are translated and they are combined as a
<code>CompoundCriteria</code>
- * using an AND operator. Returns a null if no part of the user's criteria could
- * be translated.</p>
- * @return The criteria after vistor completes translation of the criteria on the
- * virtual group
- */
- public Criteria getTranslatedCriteria() {
- if(translatedCriteria.size() > 0) {
- if(translatedCriteria.size() == 1) {
- return translatedCriteria.get(0);
- }
- return new CompoundCriteria(CompoundCriteria.AND, translatedCriteria);
- }
- return null;
- }
-
public Map<ElementSymbol, Reference> getImplicitParams() {
return implicitParams;
}
+ public void translate(Criteria crit) throws QueryValidatorException {
+ CriteriaTranslatorNavigator nav = new CriteriaTranslatorNavigator();
+ try {
+ crit.acceptVisitor(nav);
+ } catch (TeiidRuntimeException e) {
+ throw (QueryValidatorException)e.getCause();
+ }
+ }
+
}
Modified: branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-11-04
22:07:24 UTC (rev 2705)
+++ branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-11-05
02:27:49 UTC (rev 2706)
@@ -874,4 +874,6 @@
failed_to_unwrap_connection=Failed to unwrap the source connection.
connection_factory_not_found=Failed to find the Connection Factory with JNDI name {0}.
Please check the name or deploy the Connection Factory with specified name.
-RelationalPlanner.nonpushdown_command=Source command "{0}" contains
non-pushdown constructs.
\ No newline at end of file
+RelationalPlanner.nonpushdown_command=Source command "{0}" contains
non-pushdown constructs.
+
+Translate.error=Cannot translate criteria "{0}", it is not matched by selector
"{1}"
\ No newline at end of file
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
---
branches/7.1.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-11-04
22:07:24 UTC (rev 2705)
+++
branches/7.1.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-11-05
02:27:49 UTC (rev 2706)
@@ -1185,30 +1185,69 @@
assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
}
- // virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
+ // virtual group elements used in procedure (TRANSLATE CRITERIA)
@Test public void testRewriteProcedure16() throws Exception {
- String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
- procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
- procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
- procedure = procedure + "Select pm1.g1.e2 from pm1.g1 where TRANSLATE
CRITERIA;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
+ String procedure = exampleTranslateUpdate();
String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1";
//$NON-NLS-1$
String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE e4 = 0.02;\n";
//$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE e4 =
0.02;\n"; //$NON-NLS-1$
rewritProc = rewritProc + "END"; //$NON-NLS-1$
String procReturned = this.getRewritenProcedure(procedure, userQuery,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
+ }
+
+ @Test public void testRewriteNoUserCriteria() throws Exception {
+ String procedure = exampleTranslateUpdate();
+
+ String userQuery = "UPDATE vm1.g3 SET x='x'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE 1 =
1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getRewritenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
+ }
+
+ @Test public void testRewriteOrUserCriteria() throws Exception {
+ String procedure = exampleTranslateUpdate();
+
+ String userQuery = "UPDATE vm1.g3 SET x='x' where x = '1' or
x = '2'"; //$NON-NLS-1$
+
+ String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ rewritProc = rewritProc + "UPDATE pm1.g1 SET e1 = 'x' WHERE (CONCAT(e1,
'm') = '1') OR (CONCAT(e1, 'm') = '2');\n";
//$NON-NLS-1$
+ rewritProc = rewritProc + "END"; //$NON-NLS-1$
+
+ String procReturned = this.getRewritenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+
+ assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
+ }
+
+ private String exampleTranslateUpdate() {
+ String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
+ procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
+ procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
+ procedure = procedure + "update pm1.g1 set pm1.g1.e1 = inputs.x where
TRANSLATE CRITERIA;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+ return procedure;
}
// virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure17() throws Exception {
+ @Test(expected=QueryValidatorException.class) public void testRewriteProcedure17()
throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -1217,16 +1256,8 @@
String userQuery = "UPDATE vm1.g3 SET x='x' where e4= 1";
//$NON-NLS-1$
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1 WHERE
"+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
+ this.getRewritenProcedure(procedure, userQuery,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
}
// Bug 8212 elements in INPUT and CHANGING special groups are cese sensitive
@@ -1367,7 +1398,7 @@
}
// elements being set in updates are dropped if INPUT var is not available
- @Test public void testRewriteProcedure24() throws Exception {
+ @Test(expected=QueryValidatorException.class) public void testRewriteProcedure24()
throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "UPDATE pm1.g1 SET e2=Input.e2 WHERE TRANSLATE LIKE
CRITERIA ON (e1) WITH (e1=concat(pm1.g1.e1, '%'));\n"; //$NON-NLS-1$
@@ -1375,17 +1406,10 @@
String userQuery = "UPDATE vm1.g1 set E2=1 where e2 = 1 and e1 LIKE
'mnopxyz_'"; //$NON-NLS-1$
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "UPDATE pm1.g1 SET e2 = 1 WHERE concat(pm1.g1.e1,
'%') LIKE 'mnopxyz_';\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
+ this.getRewritenProcedure(procedure, userQuery,
+ FakeMetadataObject.Props.UPDATE_PROCEDURE);
+ }
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc,
procReturned); //$NON-NLS-1$
- }
-
// INPUT vars in insert statements replaced by default variable when user's inser
ignores values
@Test public void testRewriteProcedure25() throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
@@ -1429,7 +1453,7 @@
}
// virtual group elements used in procedure in if statement(TRANSLATE CRITERIA)
- @Test public void testRewriteProcedure27() throws Exception {
+ @Test(expected=QueryValidatorException.class) public void testRewriteProcedure27()
throws Exception {
String procedure = "CREATE PROCEDURE "; //$NON-NLS-1$
procedure = procedure + "BEGIN\n"; //$NON-NLS-1$
procedure = procedure + "DECLARE integer var1;\n"; //$NON-NLS-1$
@@ -1438,16 +1462,8 @@
String userQuery = "UPDATE vm1.g1 SET e1='x' where e2 LIKE
'xyz'"; //$NON-NLS-1$
- String rewritProc = "CREATE PROCEDURE\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "BEGIN\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "DECLARE integer var1;\n"; //$NON-NLS-1$
- rewritProc = rewritProc + "SELECT pm1.g1.e2 FROM pm1.g1, pm1.g2 WHERE
"+FALSE_STR+";\n"; //$NON-NLS-1$ //$NON-NLS-2$
- rewritProc = rewritProc + "END"; //$NON-NLS-1$
-
- String procReturned = this.getRewritenProcedure(procedure, userQuery,
+ this.getRewritenProcedure(procedure, userQuery,
FakeMetadataObject.Props.UPDATE_PROCEDURE);
-
- assertEquals("Rewritten command was not expected", rewritProc, procReturned);
//$NON-NLS-1$
}
/**