teiid SVN: r2430 - trunk/client/src/test/java/org/teiid/jdbc.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-08-09 13:46:28 -0400 (Mon, 09 Aug 2010)
New Revision: 2430
Modified:
trunk/client/src/test/java/org/teiid/jdbc/TestSocketProfile.java
Log:
TEIID-1192: adding the support for having the underscores in the host names in the JDBC URL.
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestSocketProfile.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestSocketProfile.java 2010-08-09 15:53:18 UTC (rev 2429)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestSocketProfile.java 2010-08-09 17:46:28 UTC (rev 2430)
@@ -76,7 +76,7 @@
assertTrue(!SocketProfile.acceptsURL("jdbc:teiid:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log")); //$NON-NLS-1$
assertTrue(!SocketProfile.acceptsURL("jdbc:teiid:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log;autoCommitTxn=OFF;paritalResultsMode=true")); //$NON-NLS-1$
assertTrue(!SocketProfile.acceptsURL("jdbc:teiid:@localhost:1234;stickyConnections=false;socketsPerVM=4")); //$NON-NLS-1$
- assertTrue(!SocketProfile.acceptsURL("jdbc:teiid:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
+ assertTrue(SocketProfile.acceptsURL("jdbc:teiid:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
}
/** Invalid format of urls*/
14 years, 4 months
teiid SVN: r2429 - in trunk/client/src: test/java/org/teiid/jdbc and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-08-09 11:53:18 -0400 (Mon, 09 Aug 2010)
New Revision: 2429
Modified:
trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java
trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
Log:
TEIID-1192: adding the support for having the underscores in the host names in the JDBC URL.
Modified: trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java 2010-08-08 16:21:55 UTC (rev 2428)
+++ trunk/client/src/main/java/org/teiid/jdbc/SocketProfile.java 2010-08-09 15:53:18 UTC (rev 2429)
@@ -60,7 +60,7 @@
*/
// This host/port pattern allows just a . or a - to be in the host part.
- static final String HOST_PORT_PATTERN = "[\\p{Alnum}\\.\\-]+:\\d+"; //$NON-NLS-1$
+ static final String HOST_PORT_PATTERN = "[\\p{Alnum}\\.\\-\\_]+:\\d+"; //$NON-NLS-1$
static final String URL_PATTERN = "jdbc:(metamatrix|teiid):([\\w|-]+)@mm[s]?://"+HOST_PORT_PATTERN+"(,"+HOST_PORT_PATTERN+")*(;.*)?"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
static Pattern urlPattern = Pattern.compile(URL_PATTERN);
Modified: trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2010-08-08 16:21:55 UTC (rev 2428)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestTeiidDriver.java 2010-08-09 15:53:18 UTC (rev 2429)
@@ -48,7 +48,8 @@
assertFalse(drv.acceptsURL("jdbc:teiid:vdb@/foo/blah/deploy.properties")); //$NON-NLS-1$
assertTrue(drv.acceptsURL("jdbc:teiid:8294601c-9fe9-4244-9499-4a012c5e1476_vdb")); //$NON-NLS-1$
assertTrue(drv.acceptsURL("jdbc:teiid:8294601c-9fe9-4244-9499-4a012c5e1476_vdb@mm://localhost:12345")); //$NON-NLS-1$
-
+ assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb@mm://local-host:12345")); //$NON-NLS-1$
+ assertTrue(drv.acceptsURL("jdbc:teiid:test_vdb@mm://local_host:12345")); //$NON-NLS-1$
}
/** Valid format of urls*/
@@ -88,7 +89,7 @@
assertTrue(!drv.acceptsURL("jdbc:metamatrix:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log")); //$NON-NLS-1$
assertTrue(!drv.acceptsURL("jdbc:metamatrix:@localhost:1234;logLevel=2;logFile=D:\\metamatrix\\work\\DQP\\log\\jdbcLogFile.log;autoCommitTxn=OFF;paritalResultsMode=true")); //$NON-NLS-1$
assertTrue(!drv.acceptsURL("jdbc:metamatrix:@localhost:1234;stickyConnections=false;socketsPerVM=4")); //$NON-NLS-1$
- assertTrue(!drv.acceptsURL("jdbc:metamatrix:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
+ assertTrue(drv.acceptsURL("jdbc:metamatrix:vdb@mm://my_host.mydomain.com:53535,127.0.0.1:1234")); //$NON-NLS-1$
}
/** Invalid format of urls*/
14 years, 4 months
teiid SVN: r2428 - in trunk/engine/src: main/java/org/teiid/query/processor/proc and 18 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-08 12:21:55 -0400 (Sun, 08 Aug 2010)
New Revision: 2428
Added:
trunk/engine/src/main/java/org/teiid/query/sql/proc/ExpressionStatement.java
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/DeepPreOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/AssignmentStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/BreakStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/CommandStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/ContinueStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/IfStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/LoopStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/Statement.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/WhileStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/CommandCollectorVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/Validator.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-168 fixing last checkin TEIID-1190 refining procedure logic
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -61,7 +61,6 @@
import org.teiid.query.sql.proc.Statement;
import org.teiid.query.sql.proc.WhileStatement;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.visitor.CommandCollectorVisitor;
import org.teiid.query.util.CommandContext;
@@ -216,12 +215,8 @@
assignInstr.setVariable(assignStmt.getVariable());
- if(assignStmt.hasCommand()) {
- assignInstr.setExpression(new ScalarSubquery(assignStmt.getCommand()));
- } else if (assignStmt.hasExpression()) {
- Expression asigExpr = assignStmt.getExpression();
- assignInstr.setExpression(asigExpr);
- }
+ Expression asigExpr = assignStmt.getExpression();
+ assignInstr.setExpression(asigExpr);
if(debug) {
analysisRecord.println("\tASSIGNMENT\n" + statement); //$NON-NLS-1$
}
@@ -233,12 +228,8 @@
instruction = error;
RaiseErrorStatement res = (RaiseErrorStatement)statement;
- if(res.hasCommand()) {
- error.setExpression(new ScalarSubquery(res.getCommand()));
- } else if (res.hasExpression()) {
- Expression asigExpr = res.getExpression();
- error.setExpression(asigExpr);
- }
+ Expression asigExpr = res.getExpression();
+ error.setExpression(asigExpr);
if(debug) {
analysisRecord.println("\tERROR STATEMENT:\n" + statement); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -38,7 +38,7 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.id.IDGenerator;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLConstants;
+import org.teiid.dqp.internal.process.Request;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.logging.LogManager;
import org.teiid.query.analysis.AnalysisRecord;
@@ -65,6 +65,7 @@
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.util.VariableContext;
import org.teiid.query.util.CommandContext;
+import org.teiid.query.validator.ValidationVisitor;
/**
@@ -168,7 +169,9 @@
// create a new set of variables including vars
Map nameValueMap = createVariableValuesMap(localContext);
nameValueMap.putAll(QueryResolver.getVariableValues(parentProcCommand.getUserCommand(), metadata));
- // validation visitor?
+ ValidationVisitor visitor = new ValidationVisitor();
+ visitor.setUpdateProc(parentProcCommand);
+ Request.validateWithVisitor(visitor, metadata, command);
if (dynamicCommand.getAsColumns() != null
&& !dynamicCommand.getAsColumns().isEmpty()) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -255,15 +255,6 @@
public void visit(ScalarSubquery obj) {
resolveSubQuery(obj, this.currentGroups);
-
- Collection<SingleElementSymbol> projSymbols = obj.getCommand().getProjectedSymbols();
-
- //Scalar subquery should have one projected symbol (query with one expression
- //in SELECT or stored procedure execution that returns a single value).
- if(projSymbols.size() != 1) {
- QueryResolverException qre = new QueryResolverException(QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0032, obj));
- throw new TeiidRuntimeException(qre);
- }
}
public void visit(ExistsCriteria obj) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -62,6 +62,7 @@
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.proc.DeclareStatement;
+import org.teiid.query.sql.proc.ExpressionStatement;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.proc.Statement;
@@ -241,25 +242,21 @@
case Statement.TYPE_ERROR:
case Statement.TYPE_ASSIGNMENT:
case Statement.TYPE_DECLARE:
- AssignmentStatement assStmt = (AssignmentStatement) statement;
+ ExpressionStatement exprStmt = (ExpressionStatement) statement;
//first resolve the value. this ensures the value cannot use the variable being defined
- if (assStmt.getValue() != null) {
- if (assStmt.hasCommand()) {
- Command cmd = assStmt.getCommand();
- resolveEmbeddedCommand(metadata, externalGroups, cmd, analysis);
- } else if (assStmt.hasExpression()) {
- Expression expr = assStmt.getExpression();
- for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
- resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(), analysis);
- }
- ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
+ if (exprStmt.getExpression() != null) {
+ Expression expr = exprStmt.getExpression();
+ for (SubqueryContainer container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(expr)) {
+ resolveEmbeddedCommand(metadata, externalGroups, container.getCommand(), analysis);
}
+ ResolverVisitor.resolveLanguageObject(expr, null, externalGroups, metadata);
}
//second resolve the variable
if(statement.getType() == Statement.TYPE_DECLARE) {
collectDeclareVariable((DeclareStatement)statement, variables, metadata, externalGroups);
- } else {
+ } else if (statement.getType() == Statement.TYPE_ASSIGNMENT) {
+ AssignmentStatement assStmt = (AssignmentStatement)statement;
ResolverVisitor.resolveLanguageObject(assStmt.getVariable(), null, externalGroups, metadata);
if (statement.getType() == Statement.TYPE_ASSIGNMENT && !assStmt.getVariable().getGroupSymbol().getCanonicalName().equals(ProcedureReservedWords.VARIABLES)) {
throw new QueryResolverException(QueryPlugin.Util.getString("UpdateProcedureResolver.only_variables", assStmt.getVariable())); //$NON-NLS-1$
@@ -269,18 +266,15 @@
}
//third ensure the type matches
- if (assStmt.hasExpression()) {
- Expression expr = assStmt.getExpression();
- Class varType = assStmt.getVariable().getType();
- Class exprType = expr.getType();
-
- if (exprType == null) {
- throw new QueryResolverException(QueryPlugin.Util.getString("ResolveVariablesVisitor.datatype_for_the_expression_not_resolvable")); //$NON-NLS-1$
- }
- String varTypeName = DataTypeManager.getDataTypeName(varType);
- assStmt.setExpression(ResolverUtil.convertExpression(expr, varTypeName, metadata));
+ if (exprStmt.getExpression() != null) {
+ Class<?> varType = exprStmt.getExpectedType();
+ Class<?> exprType = exprStmt.getExpression().getType();
+ if (exprType == null) {
+ throw new QueryResolverException(QueryPlugin.Util.getString("ResolveVariablesVisitor.datatype_for_the_expression_not_resolvable")); //$NON-NLS-1$
+ }
+ String varTypeName = DataTypeManager.getDataTypeName(varType);
+ exprStmt.setExpression(ResolverUtil.convertExpression(exprStmt.getExpression(), varTypeName, metadata));
}
-
break;
case Statement.TYPE_WHILE:
WhileStatement whileStmt = (WhileStatement) statement;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolveVirtualGroupCriteriaVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -33,6 +33,7 @@
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.navigator.DeepPreOrderNavigator;
import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.CriteriaSelector;
import org.teiid.query.sql.proc.TranslateCriteria;
@@ -101,7 +102,7 @@
ResolveVirtualGroupCriteriaVisitor resolveVisitor = new ResolveVirtualGroupCriteriaVisitor(virtualGroup, metadata);
try {
- PreOrderNavigator.doVisit(obj, resolveVisitor);
+ DeepPreOrderNavigator.doVisit(obj, resolveVisitor);
} catch (TeiidRuntimeException e) {
if (e.getChild() instanceof QueryResolverException) {
throw (QueryResolverException)e.getChild();
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -115,11 +115,11 @@
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.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.proc.CriteriaSelector;
+import org.teiid.query.sql.proc.ExpressionStatement;
import org.teiid.query.sql.proc.HasCriteria;
import org.teiid.query.sql.proc.IfStatement;
import org.teiid.query.sql.proc.LoopStatement;
@@ -344,27 +344,27 @@
}
}
return ifStmt;
- case Statement.TYPE_ERROR: //treat error the same as expressions
+ case Statement.TYPE_ERROR:
case Statement.TYPE_DECLARE:
case Statement.TYPE_ASSIGNMENT:
- AssignmentStatement assStmt = (AssignmentStatement) statement;
- // replave variables to references, these references are later
+ ExpressionStatement exprStmt = (ExpressionStatement) statement;
+ // replace variables to references, these references are later
// replaced in the processor with variable values
- if (assStmt.hasExpression()) {
- Expression expr = assStmt.getExpression();
- expr = rewriteExpressionDirect(expr);
- assStmt.setExpression(expr);
- } else if (assStmt.hasCommand()) {
- rewriteSubqueryContainer(assStmt, false);
-
- if(assStmt.getCommand().getType() == Command.TYPE_UPDATE) {
- Update update = (Update)assStmt.getCommand();
- if (update.getChangeList().isEmpty()) {
- assStmt.setExpression(new Constant(INTEGER_ZERO));
- }
- }
- }
- return assStmt;
+ Expression expr = exprStmt.getExpression();
+ if (expr != null) {
+ expr = rewriteExpressionDirect(expr);
+ exprStmt.setExpression(expr);
+ if (expr instanceof ScalarSubquery) {
+ ScalarSubquery ss = (ScalarSubquery)expr;
+ if(ss.getCommand().getType() == Command.TYPE_UPDATE) {
+ Update update = (Update)ss.getCommand();
+ if (update.getChangeList().isEmpty()) {
+ exprStmt.setExpression(new Constant(INTEGER_ZERO));
+ }
+ }
+ }
+ }
+ return exprStmt;
case Statement.TYPE_COMMAND:
CommandStatement cmdStmt = (CommandStatement) statement;
rewriteSubqueryContainer(cmdStmt, false);
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -112,9 +112,7 @@
}
public void visit(HasCriteria obj) {}
public void visit(IfStatement obj) {}
- public void visit(RaiseErrorStatement obj) {
- visit((AssignmentStatement)obj);
- }
+ public void visit(RaiseErrorStatement obj) {}
public void visit(TranslateCriteria obj) {}
public void visit(BreakStatement obj) {}
public void visit(ContinueStatement obj) {}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -24,8 +24,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
import java.util.TreeSet;
import org.teiid.core.util.EquivalenceUtil;
@@ -136,9 +134,10 @@
if (isNegated() ^ sc.isNegated()) {
return false;
}
-
- return getValues().equals(sc.getValues()) &&
- EquivalenceUtil.areEqual(getExpression(), sc.getExpression());
+
+ return getValues().size() == sc.getValues().size() &&
+ getValues().containsAll(sc.getValues()) &&
+ EquivalenceUtil.areEqual(getExpression(), sc.getExpression());
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/DeepPreOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/DeepPreOrderNavigator.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/DeepPreOrderNavigator.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -28,6 +28,8 @@
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.proc.CommandStatement;
+import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -69,6 +71,21 @@
visitNode(obj.getExpression());
}
+ @Override
+ public void visit(CommandStatement obj) {
+ visitVisitor(obj);
+ visitNode(obj.getCommand());
+ visitVisitor(obj);
+ }
+
+ @Override
+ public void visit(LoopStatement obj) {
+ visitVisitor(obj);
+ visitNode(obj.getCommand());
+ visitNode(obj.getBlock());
+ visitVisitor(obj);
+ }
+
public static void doVisit(LanguageObject object, LanguageVisitor visitor) {
DeepPreOrderNavigator nav = new DeepPreOrderNavigator(visitor);
object.acceptVisitor(nav);
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -156,7 +156,7 @@
public void visit(AssignmentStatement obj) {
preVisitVisitor(obj);
visitNode(obj.getVariable());
- visitNode(obj.getValue());
+ visitNode(obj.getExpression());
postVisitVisitor(obj);
}
public void visit(BatchedUpdateCommand obj) {
@@ -192,7 +192,6 @@
}
public void visit(CommandStatement obj) {
preVisitVisitor(obj);
- visitNode(obj.getCommand());
postVisitVisitor(obj);
}
public void visit(CompareCriteria obj) {
@@ -227,7 +226,7 @@
public void visit(DeclareStatement obj) {
preVisitVisitor(obj);
visitNode(obj.getVariable());
- visitNode(obj.getValue());
+ visitNode(obj.getExpression());
postVisitVisitor(obj);
}
public void visit(Delete obj) {
@@ -344,7 +343,6 @@
}
public void visit(LoopStatement obj) {
preVisitVisitor(obj);
- visitNode(obj.getCommand());
visitNode(obj.getBlock());
postVisitVisitor(obj);
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/AssignmentStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/AssignmentStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/AssignmentStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -24,13 +24,11 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
+import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ScalarSubquery;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
@@ -39,12 +37,12 @@
* statement holds references to the variable and it's value which could be an
* <code>Expression</code> or a <code>Command</code>.</p>
*/
-public class AssignmentStatement extends Statement implements SubqueryContainer{
+public class AssignmentStatement extends Statement implements ExpressionStatement {
// the variable to which a value is assigned
private ElementSymbol variable;
- private LanguageObject value;
+ private Expression value;
/**
* Constructor for AssignmentStatement.
@@ -53,53 +51,40 @@
super();
}
- public AssignmentStatement(ElementSymbol variable, LanguageObject value) {
+ public AssignmentStatement(ElementSymbol variable, Command value) {
this.variable = variable;
- if (value instanceof ScalarSubquery) {
- ScalarSubquery scalarSubquery = (ScalarSubquery) value;
- value = scalarSubquery.getCommand();
- }
+ this.value = new ScalarSubquery(value);
+ }
+
+ public AssignmentStatement(ElementSymbol variable, Expression value) {
+ this.variable = variable;
this.value = value;
}
+
+ /**
+ * @see #getExpression()
+ */
+ @Deprecated
+ public Expression getValue() {
+ return value;
+ }
- public boolean hasCommand() {
- return value instanceof Command;
- }
+ /**
+ * @see #setExpression(Expression)
+ */
+ @Deprecated
+ public void setValue(Expression value) {
+ this.value = value;
+ }
- public Command getCommand() {
- if (hasCommand()) {
- return (Command)value;
- }
- return null;
- }
-
- public void setCommand(Command command) {
- this.value = command;
- }
-
- public boolean hasExpression() {
- return value instanceof Expression;
- }
-
public Expression getExpression() {
- if (hasExpression()) {
- return (Expression)value;
- }
- return null;
+ return this.value;
}
public void setExpression(Expression expression) {
this.value = expression;
}
- public LanguageObject getValue() {
- return value;
- }
-
- public void setValue(LanguageObject value) {
- this.value = value;
- }
-
/**
* Get the expression giving the value that is assigned to the variable.
* @return An <code>Expression</code> with the value
@@ -138,7 +123,7 @@
* @return Deep clone
*/
public Object clone() {
- AssignmentStatement clone = new AssignmentStatement((ElementSymbol) this.variable.clone(), (LanguageObject) this.value.clone());
+ AssignmentStatement clone = new AssignmentStatement((ElementSymbol) this.variable.clone(), (Expression) this.value.clone());
return clone;
}
@@ -166,7 +151,7 @@
// Compare the variables
EquivalenceUtil.areEqual(this.getVariable(), other.getVariable()) &&
// Compare the values
- EquivalenceUtil.areEqual(this.getValue(), other.getValue());
+ EquivalenceUtil.areEqual(this.getExpression(), other.getExpression());
// Compare the values
}
@@ -180,16 +165,14 @@
// and criteria clauses, not on the from, order by, or option clauses
int myHash = 0;
myHash = HashCodeUtil.hashCode(myHash, this.getVariable());
- myHash = HashCodeUtil.hashCode(myHash, this.getValue());
+ myHash = HashCodeUtil.hashCode(myHash, this.getExpression());
return myHash;
}
+
+ @Override
+ public Class<?> getExpectedType() {
+ return getVariable().getType();
+ }
+
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/BreakStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/BreakStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/BreakStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -25,7 +25,6 @@
package org.teiid.query.sql.proc;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
* <p> This class represents a break statement in the storedprocedure language.
@@ -76,11 +75,4 @@
return 0;
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/CommandStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/CommandStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/CommandStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -23,10 +23,9 @@
package org.teiid.query.sql.proc;
import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.query.sql.*;
+import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
@@ -121,12 +120,4 @@
return this.getCommand().hashCode();
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/ContinueStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/ContinueStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/ContinueStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -81,11 +81,4 @@
return 0;
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -24,8 +24,9 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
+import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -53,7 +54,7 @@
* @param valueType The type of this variable
*/
public DeclareStatement(ElementSymbol variable, String varType) {
- super(variable, null);
+ super(variable, (Expression)null);
this.varType = varType;
}
@@ -62,7 +63,7 @@
* @param variable The <code>ElementSymbol</code> object that is the variable
* @param valueType The type of this variable
*/
- public DeclareStatement(ElementSymbol variable, String varType, LanguageObject value) {
+ public DeclareStatement(ElementSymbol variable, String varType, Expression value) {
super(variable, value);
this.varType = varType;
}
@@ -108,7 +109,7 @@
if (getValue() == null) {
return new DeclareStatement((ElementSymbol)this.getVariable().clone(), this.varType);
}
- return new DeclareStatement((ElementSymbol)this.getVariable().clone(), this.varType, (LanguageObject)getValue().clone());
+ return new DeclareStatement((ElementSymbol)this.getVariable().clone(), this.varType, (Expression)getValue().clone());
}
/**
Added: trunk/engine/src/main/java/org/teiid/query/sql/proc/ExpressionStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/ExpressionStatement.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/ExpressionStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -0,0 +1,35 @@
+/*
+ * 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.query.sql.proc;
+
+import org.teiid.query.sql.symbol.Expression;
+
+public interface ExpressionStatement {
+
+ Expression getExpression();
+
+ void setExpression(Expression expr);
+
+ Class<?> getExpectedType();
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/proc/ExpressionStatement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/IfStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/IfStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/IfStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -24,9 +24,8 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
+import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
@@ -207,12 +206,4 @@
return myHash;
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/LoopStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/LoopStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/LoopStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -26,9 +26,10 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.*;
-import org.teiid.query.sql.lang.*;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.Query;
+import org.teiid.query.sql.lang.SubqueryContainer;
/**
@@ -170,12 +171,4 @@
return myHash;
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -22,11 +22,9 @@
package org.teiid.query.sql.proc;
-import org.teiid.language.SQLConstants.Reserved;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.GroupSymbol;
/**
@@ -34,7 +32,9 @@
* It extends the <code>Statement</code> that could part of a <code>Block</code>. This
* this object holds and error message.</p>
*/
-public class RaiseErrorStatement extends AssignmentStatement {
+public class RaiseErrorStatement extends Statement implements ExpressionStatement {
+
+ private Expression expression;
/**
* Constructor for RaiseErrorStatement.
@@ -48,33 +48,55 @@
* @param message The error message
*/
public RaiseErrorStatement(Expression message) {
- super(createElementSymbol(), message);
+ expression = message;
}
- private static ElementSymbol createElementSymbol() {
- /*
- * The element symbol created here is just a placeholder for reusing
- * the logic in AssignmentStatement/AssignmentInstruction. It should not
- * matter that it has an invalid ID or GroupSymbol. Setting the type to
- * String allows for the expression to be converted to String as necessary.
- */
- ElementSymbol result = new ElementSymbol(Reserved.ERROR);
- result.setMetadataID(Reserved.ERROR);
- result.setType(String.class);
- result.setGroupSymbol(new GroupSymbol(Reserved.ERROR));
- return result;
- }
-
public void acceptVisitor(LanguageVisitor visitor) {
visitor.visit(this);
}
+ public Expression getExpression() {
+ return expression;
+ }
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
/**
* @see org.teiid.query.sql.proc.AssignmentStatement#getType()
*/
public int getType() {
return TYPE_ERROR;
}
+
+ @Override
+ public RaiseErrorStatement clone() {
+ return new RaiseErrorStatement((Expression) this.expression.clone());
+ }
+
+ @Override
+ public int hashCode() {
+ return expression.hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (!(obj instanceof RaiseErrorStatement)) {
+ return false;
+ }
+
+ RaiseErrorStatement other = (RaiseErrorStatement)obj;
+
+ return other.expression.equals(this.expression);
+ }
+
+ @Override
+ public Class<?> getExpectedType() {
+ return DataTypeManager.DefaultDataClasses.STRING;
+ }
} // END CLASS
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/Statement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/Statement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/Statement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -23,6 +23,7 @@
package org.teiid.query.sql.proc;
import org.teiid.query.sql.*;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
* <p> This class represents the a statement in the stored procedure language.
@@ -96,4 +97,9 @@
* @return Deep clone
*/
public abstract Object clone();
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/WhileStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/WhileStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/WhileStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -28,7 +28,6 @@
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
@@ -154,12 +153,4 @@
return myHash;
}
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -87,9 +87,9 @@
/**
* @see org.teiid.query.sql.symbol.Expression#getType()
*/
- public Class getType() {
+ public Class<?> getType() {
if (this.type == null){
- Expression symbol = (Expression)this.command.getProjectedSymbols().iterator().next();
+ Expression symbol = this.command.getProjectedSymbols().iterator().next();
this.type = symbol.getType();
}
//may still be null if this.command wasn't resolved
@@ -100,7 +100,7 @@
* Set type of ScalarSubquery
* @param type New type
*/
- public void setType(Class type) {
+ public void setType(Class<?> type) {
this.type = type;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/CommandCollectorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/CommandCollectorVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/CommandCollectorVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -36,7 +36,6 @@
import org.teiid.query.sql.lang.SubqueryFromClause;
import org.teiid.query.sql.lang.SubquerySetCriteria;
import org.teiid.query.sql.navigator.PreOrderNavigator;
-import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.CommandStatement;
import org.teiid.query.sql.proc.LoopStatement;
import org.teiid.query.sql.symbol.ScalarSubquery;
@@ -110,17 +109,6 @@
* called directly.
* @param obj Language object
*/
- public void visit(AssignmentStatement obj) {
- if(obj.hasCommand()) {
- this.commands.add(obj.getCommand());
- }
- }
-
- /**
- * Visit a language object and collect symbols. This method should <b>NOT</b> be
- * called directly.
- * @param obj Language object
- */
public void visit(LoopStatement obj) {
this.commands.add(obj.getCommand());
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -384,9 +384,7 @@
* @since 5.0
*/
public void visit(AssignmentStatement obj) {
- if (obj.hasExpression()) {
- obj.setExpression(replaceExpression(obj.getExpression()));
- }
+ obj.setExpression(replaceExpression(obj.getExpression()));
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -41,7 +41,6 @@
import org.teiid.query.sql.lang.AtomicCriteria;
import org.teiid.query.sql.lang.BetweenCriteria;
import org.teiid.query.sql.lang.CacheHint;
-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.Create;
@@ -1420,11 +1419,19 @@
parts.add(registerNode(obj.getVariable()));
if (obj.getValue() != null) {
parts.add(" = "); //$NON-NLS-1$
- parts.add(registerNode(obj.getValue()));
+ addStatementArgument(obj.getExpression());
}
parts.add(";"); //$NON-NLS-1$
}
+ private void addStatementArgument(Expression expr) {
+ if (expr instanceof ScalarSubquery) {
+ parts.add(registerNode(((ScalarSubquery)expr).getCommand()));
+ } else {
+ parts.add(registerNode(expr));
+ }
+ }
+
public void visit(IfStatement obj) {
parts.add(IF);
parts.add("("); //$NON-NLS-1$
@@ -1534,13 +1541,10 @@
}
public void visit(RaiseErrorStatement obj) {
- Object parts[] = new Object[4];
-
- parts[0] = ERROR;
- parts[1] = SPACE;
- parts[2] = registerNode(obj.getExpression());
- parts[3] = ";"; //$NON-NLS-1$
- replaceStringParts(parts);
+ parts.add(ERROR);
+ parts.add(SPACE);
+ addStatementArgument(obj.getExpression());
+ parts.add(";"); //$NON-NLS-1$
}
public void visit(BreakStatement obj) {
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -106,6 +106,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
@@ -152,10 +153,13 @@
// update procedure being validated
private CreateUpdateProcedureCommand updateProc;
+ public void setUpdateProc(CreateUpdateProcedureCommand updateProc) {
+ this.updateProc = updateProc;
+ }
+
public void reset() {
super.reset();
this.isXML = false;
- this.updateProc = null;
}
// ############### Visitor methods for language objects ##################
@@ -369,22 +373,17 @@
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0012, ProcedureReservedWords.INPUTS, ProcedureReservedWords.CHANGING), obj);
}
- if(obj.hasCommand()) {
- Collection projSymbols = obj.getCommand().getProjectedSymbols();
+ }
+
+ @Override
+ public void visit(ScalarSubquery obj) {
+ Collection<SingleElementSymbol> projSymbols = obj.getCommand().getProjectedSymbols();
- //The command execution should result is a value that is assigned to the variable
- // there cannot be more than one column in its results
- if(projSymbols.size() != 1) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0013), obj);
- } else {
- SingleElementSymbol value = (SingleElementSymbol) projSymbols.iterator().next();
- Class valueType = value.getType();
- Class varType = variable.getType();
- if(!varType.equals(valueType)) {
- handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0014), obj);
- }
- }
- }
+ //Scalar subquery should have one projected symbol (query with one expression
+ //in SELECT or stored procedure execution that returns a single value).
+ if(projSymbols.size() != 1) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.RESOLVER_0032, obj.getCommand()), obj.getCommand());
+ }
}
public void visit(CreateUpdateProcedureCommand obj) {
Modified: trunk/engine/src/main/java/org/teiid/query/validator/Validator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/Validator.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/java/org/teiid/query/validator/Validator.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -22,8 +22,8 @@
package org.teiid.query.validator;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.Iterator;
+import java.util.Map;
import org.teiid.core.TeiidComponentException;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -44,18 +44,12 @@
public static final ValidatorReport validate(LanguageObject object, QueryMetadataInterface metadata, AbstractValidationVisitor visitor)
throws TeiidComponentException {
+
+ // Execute on this command
+ executeValidation(object, metadata, visitor);
// Construct combined runtime / query metadata if necessary
if(object instanceof Command) {
- Command command = (Command) object;
- // do not validate subcommands seperatly if it is an update procedure
- int cmdType = command.getType();
- if(cmdType == Command.TYPE_UPDATE_PROCEDURE) {
- // Execute on this command
- executeValidation(command, metadata, visitor);
- return visitor.getReport();
- }
-
// Recursively validate subcommands
Iterator iter = CommandCollectorVisitor.getCommands((Command)object).iterator();
while(iter.hasNext()) {
@@ -63,9 +57,6 @@
validate(subCommand, metadata, visitor);
}
}
-
- // Execute on this command
- executeValidation(object, metadata, visitor);
// Otherwise, return a report
return visitor.getReport();
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-08 16:21:55 UTC (rev 2428)
@@ -819,7 +819,7 @@
String var = null;
Constant type = null;
ElementSymbol variableID = null;
- LanguageObject value = null;
+ Expression value = null;
}
{
<DECLARE>
@@ -844,7 +844,7 @@
*/
AssignmentStatement assignStatement(ParseInfo info) :
{
- LanguageObject value = null;
+ Expression value = null;
String var = null;
ElementSymbol elementID = null;
}
@@ -868,7 +868,7 @@
* arbitrarily deeply in parentheses.
* @throws ParseException if parsing failed
*/
-LanguageObject assignStatementOperand(ParseInfo info) :
+Expression assignStatementOperand(ParseInfo info) :
{
LanguageObject value = null;
}
@@ -884,7 +884,10 @@
)
{
- return value;
+ if (value instanceof Expression) {
+ return (Expression)value;
+ }
+ return new ScalarSubquery((Command)value);
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -3599,7 +3599,7 @@
@Test public void testDeclareStatementWithAssignment1() throws Exception {
ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
String type = new String("string"); //$NON-NLS-1$
- DeclareStatement stmt = new DeclareStatement(a, type, sampleQuery());
+ DeclareStatement stmt = new DeclareStatement(a, type, new ScalarSubquery(sampleQuery()));
helpStmtTest("DECLARE string a = SELECT a1 FROM g WHERE a2 = 5;","DECLARE string a = SELECT a1 FROM g WHERE a2 = 5;", stmt); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcedureProcessor.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -30,6 +30,7 @@
import org.junit.Test;
import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryProcessingException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.TeiidComponentException;
@@ -1296,8 +1297,6 @@
procedure.append("SELECT VARIABLES.e2_total;\n"); //$NON-NLS-1$
procedure.append("END"); //$NON-NLS-1$
-
-
QueryNode sq2n1 = new QueryNode("pm1.sq1", procedure.toString()); //$NON-NLS-1$
FakeMetadataObject sq1 = FakeMetadataFactory.createVirtualProcedure("pm1.sq1", pm1, Arrays.asList(new FakeMetadataObject[] { rs2p1 }), sq2n1); //$NON-NLS-1$
@@ -1400,7 +1399,36 @@
};
helpTestProcess(plan, expected, dataMgr, metadata);
}
+
+ @Test public void testDynamicCommandValidationFails() throws Exception {
+ FakeMetadataFacade metadata = FakeMetadataFactory.example1();
+
+ FakeMetadataObject pm1 = metadata.getStore().findObject("pm1",FakeMetadataObject.MODEL); //$NON-NLS-1$
+
+ FakeMetadataObject rs2 = FakeMetadataFactory.createResultSet("pm1.rs2", pm1, new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FakeMetadataObject rs2p1 = FakeMetadataFactory.createParameter("ret", 1, ParameterInfo.RESULT_SET, DataTypeManager.DefaultDataTypes.OBJECT, rs2); //$NON-NLS-1$
+ FakeMetadataObject rs2p2 = FakeMetadataFactory.createParameter("in", 2, ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING, null); //$NON-NLS-1$
+ QueryNode sq2n1 = new QueryNode("pm1.sq2", "CREATE VIRTUAL PROCEDURE BEGIN\n" //$NON-NLS-1$ //$NON-NLS-2$
+ + "declare object VARIABLES.x; execute string 'SELECT xmlelement(name elem, x)'; select 1; END"); //$NON-NLS-1$
+ FakeMetadataObject sq2 = FakeMetadataFactory.createVirtualProcedure("pm1.sq2", pm1, Arrays.asList(new FakeMetadataObject[] { rs2p1, rs2p2 }), sq2n1); //$NON-NLS-1$
+ metadata.getStore().addObject(rs2);
+ metadata.getStore().addObject(sq2);
+
+ String userUpdateStr = "EXEC pm1.sq2('First')"; //$NON-NLS-1$
+
+ FakeDataManager dataMgr = exampleDataManager(metadata);
+
+ ProcessorPlan plan = getProcedurePlan(userUpdateStr, metadata);
+
+ try {
+ helpTestProcess(plan, null, dataMgr, metadata);
+ fail("exception expected");
+ } catch (QueryProcessingException e) {
+ assertTrue(e.getCause() instanceof QueryValidatorException);
+ }
+ }
+
@Test public void testDynamicCommandWithSingleSelect() throws Exception {
//Test select of a single value in a DynamicCommand
FakeMetadataFacade metadata = FakeMetadataFactory.example1();
Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -41,6 +41,7 @@
import org.junit.Ignore;
import org.junit.Test;
import org.teiid.api.exception.query.QueryMetadataException;
+import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.TeiidComponentException;
@@ -2230,12 +2231,7 @@
String userUpdateStr = "UPDATE vm1.g1 SET e2=40"; //$NON-NLS-1$
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure);
-
- ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr);
- QueryResolver.resolveCommand(userCommand, metadata);
-
- Command command = QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord());
+ Command command = helpResolveUpdateProcedure(procedure, userUpdateStr);
assertEquals("CREATE PROCEDURE\nBEGIN\nDECLARE integer var1;\nROWS_UPDATED = SELECT pm1.g1.e2 FROM pm1.g1 WHERE e2 = INPUTS.e2;\nEND", command.toString());
}
@@ -2644,10 +2640,6 @@
helpResolveException(sql, "Cannot create group \'temp_table\' with multiple columns named \'column1\'"); //$NON-NLS-1$
}
- @Test public void testValidateScalarSubqueryTooManyColumns() {
- helpResolveException("SELECT e2, (SELECT e1, e2 FROM pm1.g1 WHERE e2 = '3') FROM pm1.g2", "There must be exactly one projected symbol of the subquery: (SELECT e1, e2 FROM pm1.g1 WHERE e2 = '3')"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
@Test public void testXMLQuery4() {
helpResolveException("SELECT * FROM xmltest.doc1 group by a2", "Queries against XML documents can not have a GROUP By clause"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -2990,4 +2982,45 @@
helpResolveException("select querystring(xmlparse(document '<a/>'))");
}
+ // validating AssignmentStatement, ROWS_UPDATED element assigned
+ @Test(expected=QueryResolverException.class) public void testCreateUpdateProcedure9() 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 + "ROWS_UPDATED = Select pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
+
+ helpResolveUpdateProcedure(procedure, userUpdateStr);
+ }
+
+ CreateUpdateProcedureCommand helpResolveUpdateProcedure(String procedure,
+ String userUpdateStr) throws QueryParserException,
+ QueryResolverException, TeiidComponentException,
+ QueryMetadataException {
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleUpdateProc(FakeMetadataObject.Props.UPDATE_PROCEDURE, procedure);
+
+ ProcedureContainer userCommand = (ProcedureContainer)QueryParser.getQueryParser().parseCommand(userUpdateStr);
+ QueryResolver.resolveCommand(userCommand, metadata);
+
+ return (CreateUpdateProcedureCommand)QueryResolver.expandCommand(userCommand, metadata, AnalysisRecord.createNonRecordingRecord());
+ }
+
+ // validating AssignmentStatement, variable type and assigned type
+ // do not match
+ @Test(expected=QueryResolverException.class) public void testCreateUpdateProcedure10() 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 + "var1 = Select pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
+ procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
+ procedure = procedure + "END\n"; //$NON-NLS-1$
+
+ String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
+
+ helpResolveUpdateProcedure(procedure, userUpdateStr);
+ }
+
}
\ No newline at end of file
Modified: trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/sql/lang/TestSetCriteria.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -95,23 +95,6 @@
assertTrue("Equivalent set criteria don't compare as equal: " + c1 + ", " + c2, c1.equals(c2)); //$NON-NLS-1$ //$NON-NLS-2$
}
- public void testEquals3() {
- SetCriteria c1 = new SetCriteria();
- c1.setExpression(new ElementSymbol("e1")); //$NON-NLS-1$
- List vals1 = new ArrayList();
- vals1.add(new Constant("a")); //$NON-NLS-1$
- vals1.add(new Constant("a")); //$NON-NLS-1$
- c1.setValues(vals1);
-
- SetCriteria c2 = new SetCriteria();
- c2.setExpression(new ElementSymbol("e1")); //$NON-NLS-1$
- List vals2 = new ArrayList();
- vals2.add(new Constant("a")); //$NON-NLS-1$
- c2.setValues(vals2);
-
- assertTrue("Equivalent set criteria don't compare as equal: " + c1 + ", " + c2, c1.equals(c2)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public void testSelfEquivalence(){
Object s1 = sample1();
int equals = 0;
Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestAssignmentStatement.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -34,6 +34,7 @@
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.symbol.ScalarSubquery;
import junit.framework.TestCase;
@@ -79,7 +80,7 @@
public void testGetCommand() throws Exception {
AssignmentStatement s2 = sample2();
Query query = (Query) QueryParser.getQueryParser().parseCommand("Select x from y"); //$NON-NLS-1$
- assertEquals("Didn't get the same parts ", s2.getCommand(), query); //$NON-NLS-1$
+ assertEquals("Didn't get the same parts ", ((ScalarSubquery)s2.getExpression()).getCommand(), query); //$NON-NLS-1$
}
public void testSelfEquivalence(){
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -352,8 +352,13 @@
createKey("pk", vGroup3, vElements3.subList(0, 1));
+ QueryNode vTrans4 = new QueryNode("VGroup4", "/*+ cache(ttl:100) */ SELECT x FROM matsrc"); //$NON-NLS-1$ //$NON-NLS-2$
+ Table vGroup4 = createVirtualGroup("VGroup4", virtModel, vTrans4); //$NON-NLS-1$
+ vGroup4.setMaterialized(true);
+ createElements(vGroup4,
+ new String[] { "x" }, //$NON-NLS-1$
+ new String[] { DataTypeManager.DefaultDataTypes.STRING});
-
return createTransformationMetadata(metadataStore, "");
}
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-08-07 12:55:23 UTC (rev 2427)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-08-08 16:21:55 UTC (rev 2428)
@@ -1127,37 +1127,6 @@
FakeMetadataObject.Props.UPDATE_PROCEDURE);
}
- // validating AssignmentStatement, ROWS_UPDATED element assigned
- @Test public void testCreateUpdateProcedure9() {
- 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 + "ROWS_UPDATED = Select pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
- // validating AssignmentStatement, variable type and assigned type
- // do not match
- @Test public void testCreateUpdateProcedure10() {
- 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 + "var1 = Select pm1.g1.e1 from pm1.g1;\n"; //$NON-NLS-1$
- procedure = procedure + "ROWS_UPDATED =0;\n"; //$NON-NLS-1$
- procedure = procedure + "END\n"; //$NON-NLS-1$
-
- String userUpdateStr = "UPDATE vm1.g1 SET e1='x'"; //$NON-NLS-1$
-
- helpFailProcedure(procedure, userUpdateStr,
- FakeMetadataObject.Props.UPDATE_PROCEDURE);
- }
-
// validating AssignmentStatement, more than one project symbol on the
// command
@Test public void testCreateUpdateProcedure11() {
@@ -2056,5 +2025,9 @@
@Test public void testValidateStatAgg() {
helpValidate("SELECT stddev_pop(distinct e2) from pm1.g1", new String[] {"STDDEV_POP(DISTINCT e2)"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ @Test public void testValidateScalarSubqueryTooManyColumns() {
+ helpValidate("SELECT e2, (SELECT e1, e2 FROM pm1.g1 WHERE e2 = '3') FROM pm1.g2", new String[] {"SELECT e1, e2 FROM pm1.g1 WHERE e2 = '3'"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
14 years, 4 months
teiid SVN: r2427 - in trunk: engine/src/main/java/org/teiid/dqp/internal/datamgr and 18 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-07 08:55:23 -0400 (Sat, 07 Aug 2010)
New Revision: 2427
Added:
trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
Modified:
trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/SubqueryCompareCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/tempdata/IndexCondition.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-168 adding expanded support for the cache hint (ttl and pref_mem - which are tied into the mat view logic), changing the default hint format to /*+ (oracle/enterprisedb style), updated the setcriteria logic to optimize the case of all constants
Modified: trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -22,6 +22,7 @@
package org.teiid.core.util;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.RandomAccess;
@@ -108,23 +109,24 @@
* 1, 2, 4, 8, ... This has been shown to give a good hash
* for good time complexity.
*/
- public static final int expHashCode(int previous, List x) {
+ public static final int expHashCode(int previous, Collection<?> x) {
if(x == null || x.size() == 0) {
return PRIME*previous;
}
int size = x.size(); // size of collection
int hc = (PRIME*previous) + size; // hash code so far
- if (x instanceof RandomAccess) {
+ if (x instanceof RandomAccess && x instanceof List<?>) {
+ List<?> l = List.class.cast(x);
int index = 1;
int xlen = x.size()+1; // switch to 1-based
while(index < xlen) {
- hc = hashCode(hc, x.get(index-1));
+ hc = hashCode(hc, l.get(index-1));
index = index << 1; // left shift by 1 to double
}
} else {
int skip = 0; // skip between samples
int total = 0; // collection examined already
- Iterator iter = x.iterator(); // collection iterator
+ Iterator<?> iter = x.iterator(); // collection iterator
Object obj = iter.next(); // last iterated object, primed at first
while(total < size) {
for(int i=0; i<skip; i++) { // skip to next sample
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -23,6 +23,7 @@
package org.teiid.dqp.internal.datamgr;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@@ -342,7 +343,7 @@
}
In translate(SetCriteria criteria) {
- List expressions = criteria.getValues();
+ Collection expressions = criteria.getValues();
List translatedExpressions = new ArrayList();
for (Iterator i = expressions.iterator(); i.hasNext();) {
translatedExpressions.add(translate((Expression)i.next()));
Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -407,6 +407,17 @@
ValueIterator valueIter = null;
if (criteria instanceof SetCriteria) {
+ SetCriteria set = (SetCriteria)criteria;
+ if (set.isAllConstants()) {
+ boolean exists = set.getValues().contains(new Constant(leftValue, criteria.getExpression().getType()));
+ if (!exists) {
+ if (set.getValues().contains(Constant.NULL_CONSTANT)) {
+ return null;
+ }
+ return criteria.isNegated();
+ }
+ return !criteria.isNegated();
+ }
valueIter = new CollectionValueIterator(((SetCriteria)criteria).getValues());
} else if (criteria instanceof DependentSetCriteria){
ContextReference ref = (ContextReference)criteria;
@@ -446,7 +457,7 @@
}
if(value != null) {
- if(leftValue.equals(value)) {
+ if(compareValues(leftValue, value) == 0) {
return Boolean.valueOf(!criteria.isNegated());
} // else try next value
} else {
@@ -511,26 +522,26 @@
Object value = valueIter.next();
if(value != null) {
-
+ int compare = compareValues(leftValue, value);
// Compare two non-null values using specified operator
switch(criteria.getOperator()) {
case SubqueryCompareCriteria.EQ:
- result = Boolean.valueOf(leftValue.equals(value));
+ result = Boolean.valueOf(compare == 0);
break;
case SubqueryCompareCriteria.NE:
- result = Boolean.valueOf(!leftValue.equals(value));
+ result = Boolean.valueOf(compare != 0);
break;
case SubqueryCompareCriteria.LT:
- result = Boolean.valueOf((compareValues(leftValue, value) < 0));
+ result = Boolean.valueOf(compare < 0);
break;
case SubqueryCompareCriteria.LE:
- result = Boolean.valueOf((compareValues(leftValue, value) <= 0));
+ result = Boolean.valueOf(compare <= 0);
break;
case SubqueryCompareCriteria.GT:
- result = Boolean.valueOf((compareValues(leftValue, value) > 0));
+ result = Boolean.valueOf(compare > 0);
break;
case SubqueryCompareCriteria.GE:
- result = Boolean.valueOf((compareValues(leftValue, value) >= 0));
+ result = Boolean.valueOf(compare >= 0);
break;
default:
throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0012, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0012, criteria.getOperator()));
@@ -547,13 +558,6 @@
return Boolean.TRUE;
}
break;
- case SubqueryCompareCriteria.NO_QUANTIFIER:
- if (valueIter.hasNext()){
- // The subquery should be scalar, but has produced
- // more than one result value - this is an exception case
- throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0056, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
- }
- return result;
default:
throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0057, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057, criteria.getPredicateQuantifier()));
}
@@ -567,14 +571,6 @@
case SubqueryCompareCriteria.SOME:
result = null;
break;
- case SubqueryCompareCriteria.NO_QUANTIFIER:
- if (valueIter.hasNext()){
- // The subquery should be scalar, but has produced
- // more than one result value - this is an exception case
- throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0056, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
- }
- // null value means unknown for the single-value comparison
- return null;
default:
throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0057, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057, criteria.getPredicateQuantifier()));
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -692,7 +692,10 @@
@Override
public Object getPrimaryKey(Object metadataID) {
if (metadataID instanceof TempMetadataID) {
- return metadataID;
+ if (((TempMetadataID)metadataID).getPrimaryKey() != null) {
+ return metadataID;
+ }
+ return null;
}
return this.actualMetadata.getPrimaryKey(metadataID);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -29,6 +29,7 @@
import org.teiid.core.util.LRUCache;
import org.teiid.query.mapping.relational.QueryNode;
+import org.teiid.query.sql.lang.CacheHint;
/**
@@ -57,6 +58,7 @@
private List<TempMetadataID> primaryKey;
private QueryNode queryNode;
private transient LRUCache<Object, Object> localCache;
+ private CacheHint cacheHint;
//Column metadata
private Object originalMetadataID;
@@ -280,5 +282,13 @@
public void setQueryNode(QueryNode queryNode) {
this.queryNode = queryNode;
}
+
+ public CacheHint getCacheHint() {
+ return cacheHint;
+ }
+
+ public void setCacheHint(CacheHint cacheHint) {
+ this.cacheHint = cacheHint;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -43,6 +43,7 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.id.IDGenerator;
import org.teiid.dqp.internal.process.Request;
+import org.teiid.language.SQLConstants;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.query.QueryPlugin;
@@ -71,6 +72,7 @@
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageObject.Util;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.From;
@@ -904,16 +906,18 @@
Object metadataID = virtualGroup.getMetadataID();
boolean noCache = isNoCacheGroup(metadata, metadataID, option);
boolean isMaterializedGroup = metadata.hasMaterialization(metadataID);
- String cacheString = "select"; //$NON-NLS-1$
+ String cacheString = SQLConstants.Reserved.SELECT;
String groupName = metadata.getFullName(metadataID);
if( isMaterializedGroup) {
Object matMetadataId = metadata.getMaterialization(metadataID);
String matTableName = null;
- boolean isGlobal = matMetadataId == null;
- if (isGlobal) {
+ CacheHint hint = null;
+ boolean isImplicitGlobal = matMetadataId == null;
+ if (isImplicitGlobal) {
matTableName = MAT_PREFIX + groupName;
matMetadataId = getGlobalTempTableMetadataId(virtualGroup, matTableName);
+ hint = ((TempMetadataID)matMetadataId).getCacheHint();
} else {
matTableName = metadata.getFullName(matMetadataId);
}
@@ -922,13 +926,16 @@
//not use cache
qnode = metadata.getVirtualPlan(metadataID);
//TODO: update the table for defaultMat
- recordMaterializationTableAnnotation(virtualGroup, analysisRecord, matTableName, "SimpleQueryResolver.materialized_table_not_used"); //$NON-NLS-1$
+ recordMaterializationTableAnnotation(virtualGroup, analysisRecord, matTableName,
+ QueryPlugin.Util.getString("SimpleQueryResolver.materialized_table_not_used", virtualGroup, matTableName)); //$NON-NLS-1$
}else{
qnode = new QueryNode(groupName, null);
- Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new AllSymbol()), isGlobal);
+ Query query = createMatViewQuery(matMetadataId, matTableName, Arrays.asList(new AllSymbol()), isImplicitGlobal);
+ query.setCacheHint(hint);
qnode.setCommand(query);
cacheString = "matview"; //$NON-NLS-1$
- recordMaterializationTableAnnotation(virtualGroup, analysisRecord, matTableName, "SimpleQueryResolver.Query_was_redirected_to_Mat_table"); //$NON-NLS-1$
+ recordMaterializationTableAnnotation(virtualGroup, analysisRecord, matTableName,
+ QueryPlugin.Util.getString("SimpleQueryResolver.Query_was_redirected_to_Mat_table", virtualGroup, matTableName)); //$NON-NLS-1$
}
} else {
// Not a materialized view - query the primary transformation
@@ -950,12 +957,12 @@
}
private Object getGlobalTempTableMetadataId(GroupSymbol table, String matTableName)
- throws QueryMetadataException, TeiidComponentException {
+ throws QueryMetadataException, TeiidComponentException, QueryResolverException, QueryValidatorException {
TempMetadataStore store = context.getGlobalTableStore().getMetadataStore();
TempMetadataID id = store.getTempGroupID(matTableName);
//define the table preserving the primary key
if (id == null) {
- synchronized (store) {
+ synchronized (table.getMetadataID()) {
id = store.getTempGroupID(matTableName);
if (id == null) {
//this is really just temporary and will be replaced by the real table
@@ -977,6 +984,15 @@
//version column?
//add timestamp?
+ Command c = getCommand(table, metadata.getVirtualPlan(table.getMetadataID()), SQLConstants.Reserved.SELECT, metadata);
+ CacheHint hint = c.getCacheHint();
+ if (hint == null) {
+ hint = new CacheHint();
+ } else {
+ recordMaterializationTableAnnotation(table, analysisRecord, matTableName,
+ QueryPlugin.Util.getString("SimpleQueryResolver.cache_hint_used", table, matTableName, hint)); //$NON-NLS-1$
+ }
+ id.setCacheHint(hint);
}
}
}
@@ -1042,9 +1058,8 @@
AnalysisRecord analysis,
String matTableName, String msg) {
if ( analysis.recordAnnotations() ) {
- Object[] params = new Object[] {virtualGroup, matTableName};
Annotation annotation = new Annotation(Annotation.MATERIALIZED_VIEW,
- QueryPlugin.Util.getString(msg, params),
+ msg,
null,
Priority.LOW);
analysis.addAnnotation(annotation);
Modified: trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -26,7 +26,9 @@
import java.util.HashMap;
import java.util.Map;
+import org.teiid.query.sql.lang.CacheHint;
+
public class ParseInfo implements Serializable{
private static final long serialVersionUID = -7323683731955992888L;
@@ -41,7 +43,7 @@
// treat a double quoted variable as variable instead of string
public boolean ansiQuotedIdentifiers=Boolean.valueOf(System.getProperty("org.teiid.ansiQuotedIdentifiers", Boolean.TRUE.toString())).booleanValue(); //$NON-NLS-1$
- public boolean cache;
+ public CacheHint cacheHint;
public ParseInfo() { }
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -108,7 +108,9 @@
try {
Command result = parseCommandWithParser(sql, parseInfo);
- result.setCache(parseInfo.cache);
+ if (parseInfo.cacheHint != null) {
+ result.setCacheHint(parseInfo.cacheHint);
+ }
return result;
} catch (QueryParserException e) {
if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -25,12 +25,14 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.teiid.core.util.Assertion;
import org.teiid.core.util.StringUtil;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
-import org.teiid.query.sql.lang.Command;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.FromClause;
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.Option;
@@ -166,7 +168,7 @@
}
void setFromClauseOptions(Token groupID, FromClause fromClause){
- String[] parts = getComment(groupID);
+ String[] parts = getComment(groupID).split("\\s"); //$NON-NLS-1$
for (int i = 0; i < parts.length; i++) {
if (parts[i].equalsIgnoreCase(Option.OPTIONAL)) {
@@ -175,24 +177,34 @@
}
}
- private String[] getComment(Token t) {
+ private String getComment(Token t) {
Token optToken = t.specialToken;
if (optToken == null) {
- return new String[0];
+ return ""; //$NON-NLS-1$
}
String hint = optToken.image.substring(2, optToken.image.length() - 2);
- String[] parts = hint.split("\\s"); //$NON-NLS-1$
- return parts;
+ if (hint.startsWith("+")) { //$NON-NLS-1$
+ hint = hint.substring(1);
+ }
+ return hint;
}
+
+ private static Pattern CACHE_HINT = Pattern.compile("\\s*cache(\\(\\s*(pref_mem)?\\s*(ttl:\\d{1,19})?[^)]*\\))?.*", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
void setQueryCacheOption(Token t, ParseInfo p) {
- String[] parts = getComment(t);
+ String hint = getComment(t);
- for (int i = 0; i < parts.length; i++) {
- if (parts[i].equalsIgnoreCase(Command.CACHE)) {
- p.cache = true;
- }
- }
+ Matcher match = CACHE_HINT.matcher(hint);
+ if (match.matches()) {
+ p.cacheHint = new CacheHint();
+ if (match.group(2) !=null) {
+ p.cacheHint.setPrefersMemory(true);
+ }
+ String ttl = match.group(3);
+ if (ttl != null) {
+ p.cacheHint.setTtl(Long.valueOf(ttl.substring(4)));
+ }
+ }
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -40,6 +40,7 @@
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.TreeSet;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
@@ -1833,6 +1834,10 @@
}
private Criteria rewriteCriteria(SetCriteria criteria) throws TeiidComponentException, TeiidProcessingException{
+ if (criteria.isAllConstants() && criteria.getValues().size() > 1) {
+ return criteria;
+ }
+
criteria.setExpression(rewriteExpressionDirect(criteria.getExpression()));
if (isNull(criteria.getExpression())) {
@@ -1843,25 +1848,38 @@
LinkedHashSet newVals = new LinkedHashSet(vals.size());
Iterator valIter = vals.iterator();
+ boolean allConstants = true;
+ boolean hasNull = false;
while(valIter.hasNext()) {
Expression value = rewriteExpressionDirect( (Expression) valIter.next());
if (isNull(value)) {
- continue;
+ hasNull = true;
+ continue;
}
+ allConstants &= value instanceof Constant;
newVals.add(value);
}
+ int size = newVals.size();
+ if (size == 1) {
+ Expression value = (Expression)newVals.iterator().next();
+ return rewriteCriteria(new CompareCriteria(criteria.getExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, value));
+ }
+
criteria.setValues(newVals);
+ if (allConstants) {
+ criteria.setAllConstants(true);
+ criteria.setValues(new TreeSet(newVals));
+ }
- if (newVals.size() == 1) {
- Expression value = (Expression)newVals.iterator().next();
- return rewriteCriteria(new CompareCriteria(criteria.getExpression(), criteria.isNegated()?CompareCriteria.NE:CompareCriteria.EQ, value));
- } else if (newVals.size() == 0) {
- return FALSE_CRITERIA;
+ if (size == 0) {
+ if (hasNull) {
+ return UNKNOWN_CRITERIA;
+ }
+ return getSimpliedCriteria(criteria, criteria.getExpression(), !criteria.isNegated(), true);
}
if(criteria.getExpression() instanceof Function ) {
-
Function leftFunction = (Function)criteria.getExpression();
if(FunctionLibrary.isConvert(leftFunction)) {
return simplifyConvertFunction(criteria);
Added: trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -0,0 +1,69 @@
+/*
+ * 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.query.sql.lang;
+
+import java.io.Serializable;
+
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+public class CacheHint implements Serializable {
+
+ public static final String PREF_MEM = "pref_mem"; //$NON-NLS-1$
+ public static final String TTL = "ttl:"; //$NON-NLS-1$
+ public static final String CACHE = "cache"; //$NON-NLS-1$
+
+ private boolean prefersMemory;
+ private Long ttl;
+
+ public CacheHint() {
+ }
+
+ public CacheHint(boolean prefersMemory, Long ttl) {
+ this.prefersMemory = prefersMemory;
+ this.ttl = ttl;
+ }
+
+ public boolean getPrefersMemory() {
+ return prefersMemory;
+ }
+
+ public void setPrefersMemory(boolean prefersMemory) {
+ this.prefersMemory = prefersMemory;
+ }
+
+ public Long getTtl() {
+ return ttl;
+ }
+
+ public void setTtl(Long ttl) {
+ this.ttl = ttl;
+ }
+
+ @Override
+ public String toString() {
+ SQLStringVisitor ssv = new SQLStringVisitor();
+ ssv.addCacheHint(this);
+ return ssv.getSQLString();
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/lang/CacheHint.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -50,8 +50,6 @@
*/
public abstract class Command implements LanguageObject {
- public static final String CACHE = "cache"; //$NON-NLS-1$
-
/**
* Represents an unknown type of command
*/
@@ -123,7 +121,7 @@
private SymbolMap correlatedReferences;
- private boolean cache;
+ private CacheHint cacheHint;
/**
* Return type of command to make it easier to build switch statements by command type.
@@ -233,7 +231,7 @@
if(this.getOption() != null) {
copy.setOption( (Option) this.getOption().clone() );
}
- copy.cache = this.cache;
+ copy.cacheHint = this.cacheHint;
}
/**
@@ -322,13 +320,17 @@
}
public boolean isCache() {
- return cache;
+ return cacheHint != null;
}
- public void setCache(boolean cache) {
- this.cache = cache;
+ public CacheHint getCacheHint() {
+ return cacheHint;
}
+ public void setCacheHint(CacheHint cacheHint) {
+ this.cacheHint = cacheHint;
+ }
+
/**
* Returns a string representation of an instance of this class.
* @return String representation of object
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -127,10 +127,16 @@
}
DependentSetCriteria criteriaCopy = new DependentSetCriteria(copy, id);
- criteriaCopy.setNegated(isNegated());
criteriaCopy.setValueExpression((Expression) getValueExpression().clone());
criteriaCopy.id = this.id;
return criteriaCopy;
}
+ @Override
+ public void setNegated(boolean negationFlag) {
+ if (!negationFlag) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/SetCriteria.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -24,13 +24,13 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
+import java.util.LinkedHashSet;
+import java.util.TreeSet;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.Expression;
@@ -43,6 +43,7 @@
/** The set of value expressions */
private Collection values;
+ private boolean allConstants;
/**
* Constructs a default instance of this class.
@@ -71,8 +72,8 @@
* currently no values.
* @return The collection of Expression values
*/
- public List getValues() {
- return (this.values != null) ? new ArrayList(this.values) : Collections.EMPTY_LIST;
+ public Collection getValues() {
+ return this.values;
}
/**
@@ -136,10 +137,7 @@
return false;
}
- HashSet thisValues = new HashSet(getValues());
- HashSet otherValues = new HashSet(sc.getValues());
-
- return thisValues.equals(otherValues) &&
+ return getValues().equals(sc.getValues()) &&
EquivalenceUtil.areEqual(getExpression(), sc.getExpression());
}
@@ -153,18 +151,25 @@
copy = (Expression) getExpression().clone();
}
- Collection copyValues = new ArrayList();
- if(getValues() != null) {
- Iterator iter = getValues().iterator();
- while(iter.hasNext()) {
- Expression e = (Expression) iter.next();
- copyValues.add( e.clone() );
- }
+ Collection copyValues = null;
+ if (isAllConstants()) {
+ copyValues = new TreeSet(values);
+ } else {
+ copyValues = LanguageObject.Util.deepClone(new ArrayList(values), Expression.class);
}
-
+
SetCriteria criteriaCopy = new SetCriteria(copy, copyValues);
criteriaCopy.setNegated(isNegated());
+ criteriaCopy.allConstants = allConstants;
return criteriaCopy;
}
+
+ public boolean isAllConstants() {
+ return allConstants;
+ }
+
+ public void setAllConstants(boolean allConstants) {
+ this.allConstants = allConstants;
+ }
} // END CLASS
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/SubqueryCompareCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/SubqueryCompareCriteria.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/SubqueryCompareCriteria.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -60,9 +60,6 @@
private static AtomicInteger ID = new AtomicInteger();
- /** "All" predicate quantifier */
- public static final int NO_QUANTIFIER = 1;
-
/** "Some" predicate quantifier (equivalent to "Any") */
public static final int SOME = 2;
@@ -72,7 +69,7 @@
/** "All" predicate quantifier */
public static final int ALL = 4;
- private int predicateQuantifier = NO_QUANTIFIER;
+ private int predicateQuantifier = ALL;
private Command command;
private String id = "$scc/id" + ID.getAndIncrement(); //$NON-NLS-1$
@@ -140,7 +137,6 @@
*/
public String getPredicateQuantifierAsString() {
switch ( this.predicateQuantifier ) {
- case NO_QUANTIFIER: return ""; //$NON-NLS-1$
case ANY: return "ANY "; //$NON-NLS-1$
case SOME: return "SOME "; //$NON-NLS-1$
case ALL: return "ALL "; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -39,8 +39,10 @@
*/
public class Constant implements Expression, Comparable<Constant> {
+ public static final Constant NULL_CONSTANT = new Constant(null);
+
private Object value;
- private Class type;
+ private Class<?> type;
private boolean multiValued;
/**
@@ -79,7 +81,7 @@
* Get type of constant, if known
* @return Java class name of type
*/
- public Class getType() {
+ public Class<?> getType() {
return this.type;
}
@@ -137,19 +139,22 @@
Constant other = (Constant) obj;
// Check null values first
- if(other.isNull() && this.isNull()) {
- return true;
+ if(other.isNull()) {
+ if (this.isNull()) {
+ return true;
+ }
+ return false;
}
+
+ if (this.isNull()) {
+ return false;
+ }
// Check type - types are never null
if(! other.getType().equals(this.getType())) {
return false;
}
- if(other.isNull() || this.isNull()) {
- return false;
- }
-
return multiValued == other.multiValued && other.getValue().equals(this.getValue());
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -253,6 +253,10 @@
public void visit(SetCriteria obj) {
obj.setExpression( replaceExpression(obj.getExpression()) );
+ if (obj.isAllConstants()) {
+ return;
+ }
+
Collection newValues = new ArrayList(obj.getValues().size());
Iterator valueIter = obj.getValues().iterator();
while(valueIter.hasNext()) {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -40,6 +40,7 @@
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.AtomicCriteria;
import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.CompoundCriteria;
@@ -135,8 +136,8 @@
public static final String UNDEFINED = "<undefined>"; //$NON-NLS-1$
private static final String SPACE = " "; //$NON-NLS-1$
- private static final String BEGIN_COMMENT = "/*"; //$NON-NLS-1$
- private static final String END_COMMENT = "*/"; //$NON-NLS-1$
+ private static final String BEGIN_HINT = "/*+"; //$NON-NLS-1$
+ private static final String END_HINT = "*/"; //$NON-NLS-1$
private static final char ID_ESCAPE_CHAR = '\"';
private LinkedList<Object> parts = new LinkedList<Object>();
@@ -595,11 +596,11 @@
private void addOptionComment(FromClause obj) {
if (obj.isOptional()) {
- parts.add(BEGIN_COMMENT);
+ parts.add(BEGIN_HINT);
parts.add(SPACE);
parts.add(Option.OPTIONAL);
parts.add(SPACE);
- parts.add(END_COMMENT);
+ parts.add(END_HINT);
parts.add(SPACE);
}
}
@@ -816,7 +817,7 @@
}
public void visit(Query obj) {
- addCacheHint(obj);
+ addCacheHint(obj.getCacheHint());
parts.add(registerNode(obj.getSelect()));
if(obj.getInto() != null){
@@ -926,7 +927,7 @@
parts.add(" ("); //$NON-NLS-1$
// value list
- List vals = obj.getValues();
+ Collection vals = obj.getValues();
int size = vals.size();
if(size == 1) {
Iterator iter = vals.iterator();
@@ -946,7 +947,7 @@
}
public void visit(SetQuery obj) {
- addCacheHint(obj);
+ addCacheHint(obj.getCacheHint());
QueryCommand query = obj.getLeftQuery();
if(query instanceof Query) {
parts.add(registerNode(query));
@@ -991,7 +992,7 @@
}
public void visit(StoredProcedure obj) {
- addCacheHint(obj);
+ addCacheHint(obj.getCacheHint());
//exec clause
parts.add(EXEC);
parts.add(SPACE);
@@ -1040,15 +1041,35 @@
}
}
- private void addCacheHint(Command obj) {
- if (obj.isCache()) {
- parts.add(BEGIN_COMMENT);
- parts.add(SPACE);
- parts.add(Command.CACHE);
- parts.add(SPACE);
- parts.add(END_COMMENT);
- parts.add(SPACE);
- }
+ public void addCacheHint(CacheHint obj) {
+ if (obj == null) {
+ return;
+ }
+ parts.add(BEGIN_HINT);
+ parts.add(SPACE);
+ parts.add(CacheHint.CACHE);
+ boolean addParens = false;
+ if (obj.getPrefersMemory()) {
+ parts.add(Tokens.LPAREN);
+ addParens = true;
+ parts.add(CacheHint.PREF_MEM);
+ }
+ if (obj.getTtl() != null) {
+ if (!addParens) {
+ parts.add(Tokens.LPAREN);
+ addParens = true;
+ } else {
+ parts.add(SPACE);
+ }
+ parts.add(CacheHint.TTL);
+ parts.add(obj.getTtl());
+ }
+ if (addParens) {
+ parts.add(Tokens.RPAREN);
+ }
+ parts.add(SPACE);
+ parts.add(END_HINT);
+ parts.add(SPACE);
}
public void visit(SubqueryFromClause obj) {
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/IndexCondition.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/IndexCondition.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/IndexCondition.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -33,7 +33,6 @@
import org.teiid.query.sql.lang.SetCriteria;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.symbol.Expression;
/**
* Accumulates information from criteria about a specific index column.
@@ -105,16 +104,10 @@
}
} else if (criteria instanceof SetCriteria) {
SetCriteria setCriteria = (SetCriteria)criteria;
- if (!setCriteria.getExpression().equals(keyColumn)) {
+ if (!setCriteria.getExpression().equals(keyColumn) || !setCriteria.isAllConstants()) {
continue;
}
- TreeSet<Constant> values = new TreeSet<Constant>();
- for (Expression expr : (List<? extends Expression>)setCriteria.getValues()) {
- if (!(expr instanceof Constant)) {
- continue;
- }
- values.add((Constant)expr);
- }
+ TreeSet<Constant> values = (TreeSet<Constant>) setCriteria.getValues();
conditions[i].addSet(values);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -54,6 +54,7 @@
import org.teiid.query.processor.relational.RelationalNode;
import org.teiid.query.processor.relational.SortUtility;
import org.teiid.query.processor.relational.SortUtility.Mode;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.lang.OrderByItem;
@@ -548,5 +549,9 @@
void setUpdatable(boolean updatable) {
this.updatable = updatable;
}
+
+ CacheHint getCacheHint() {
+ return this.tid.getCacheHint();
+ }
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -47,6 +47,7 @@
import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.QueryProcessor;
import org.teiid.query.resolver.util.ResolverUtil;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Create;
@@ -174,8 +175,8 @@
final String tableName = group.getNonCorrelationName().toUpperCase();
TempTable table = null;
if (group.isGlobalTable()) {
- TempTableStore tts = context.getGlobalTableStore();
- MatTableInfo info = tts.getMatTableInfo(tableName);
+ TempTableStore globalStore = context.getGlobalTableStore();
+ MatTableInfo info = globalStore.getMatTableInfo(tableName);
boolean load = info.shouldLoad();
if (load) {
QueryMetadataInterface metadata = context.getMetadata();
@@ -188,9 +189,10 @@
create.getPrimaryKey().add(create.getColumns().get(metadata.getPosition(col)-1));
}
}
- table = tts.addTempTable(tableName, create, bufferManager);
+ table = globalStore.addTempTable(tableName, create, bufferManager);
+ CacheHint hint = table.getCacheHint();
table.setUpdatable(false);
- table.setPreferMemory(tableName.startsWith(CODE_PREFIX));
+ table.setPreferMemory(hint.getPrefersMemory());
boolean success = false;
try {
//TODO: order by primary key nulls first - then have an insert ordered optimization
@@ -204,12 +206,15 @@
success = true;
} finally {
if (!success) {
- tts.removeTempTableByName(tableName);
+ globalStore.removeTempTableByName(tableName);
}
info.setState(success?MatState.LOADED:MatState.FAILED_LOAD);
+ if (table.getCacheHint().getTtl() != null) {
+ info.setTtl(table.getCacheHint().getTtl());
+ }
}
} else {
- table = tts.getOrCreateTempTable(tableName, query, bufferManager, false);
+ table = globalStore.getOrCreateTempTable(tableName, query, bufferManager, false);
}
} else {
table = contextStore.getOrCreateTempTable(tableName, query, bufferManager, true);
@@ -246,7 +251,8 @@
String queryString = Reserved.SELECT + ' ' + keyElementName + " ," + returnElementName + ' ' + Reserved.FROM + ' ' + codeTableName; //$NON-NLS-1$
id.setQueryNode(new QueryNode(matTableName, queryString));
id.setPrimaryKey(id.getElements().subList(0, 1));
-
+ CacheHint hint = new CacheHint(true, null);
+ id.setCacheHint(hint);
Query query = RelationalPlanner.createMatViewQuery(id, matTableName, Arrays.asList(returnElement), true);
query.setCriteria(new CompareCriteria(keyElement, CompareCriteria.EQ, new Constant(keyValue)));
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -54,6 +54,7 @@
public static class MatTableInfo {
private long updateTime = -1;
private MatState state = MatState.NOT_LOADED;
+ private long ttl = -1;
synchronized boolean shouldLoad() throws TeiidComponentException {
for (;;) {
@@ -71,6 +72,10 @@
}
continue;
case LOADED:
+ if (ttl >= 0 && System.currentTimeMillis() - updateTime - ttl > 0) {
+ state = MatState.LOADING;
+ return true;
+ }
return false;
}
}
@@ -82,6 +87,10 @@
notifyAll();
}
+ public synchronized void setTtl(long ttl) {
+ this.ttl = ttl;
+ }
+
public long getUpdateTime() {
return updateTime;
}
@@ -122,9 +131,12 @@
TempTable addTempTable(String tempTableName, Create create, BufferManager buffer) {
List<ElementSymbol> columns = create.getColumns();
-
+ TempMetadataID existingId = tempMetadataStore.getTempGroupID(tempTableName);
//add metadata
- TempMetadataID id = tempMetadataStore.addTempGroup(tempTableName, columns, false, true);
+ TempMetadataID id = tempMetadataStore.addTempGroup(tempTableName, columns, false, true);
+ if (existingId != null) {
+ id.setCacheHint(existingId.getCacheHint());
+ }
TempTableResolver.addPrimaryKey(create, id);
columns = new ArrayList<ElementSymbol>(create.getColumns());
if (!create.getPrimaryKey().isEmpty()) {
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-08-07 12:55:23 UTC (rev 2427)
@@ -2489,9 +2489,7 @@
subqueryCrit.setOperator(getOperator(operator.image));
// Set predicate quantifier
- if(quantifier == null) {
- subqueryCrit.setPredicateQuantifier(SubqueryCompareCriteria.NO_QUANTIFIER);
- } else if(quantifier.image.equalsIgnoreCase("any")) { //$NON-NLS-1$
+ if(quantifier.image.equalsIgnoreCase("any")) { //$NON-NLS-1$
subqueryCrit.setPredicateQuantifier(SubqueryCompareCriteria.ANY);
} else if(quantifier.image.equalsIgnoreCase("some")) { //$NON-NLS-1$
subqueryCrit.setPredicateQuantifier(SubqueryCompareCriteria.SOME);
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-08-07 12:55:23 UTC (rev 2427)
@@ -863,6 +863,7 @@
QueryResolver.invalid_xpath=Invalid xpath value: {0}
ResolveVariablesVisitor.reserved_word_for_temporary_used=Cursor names cannot begin with "#" as that indicates the name of a temporary table: {0}.
SimpleQueryResolver.materialized_table_not_used=The query against {0} did not use materialization table {1} due to the use of OPTION NOCACHE.
+SimpleQueryResolver.cache_hint_used=Loading materialized view {1} for view {0} using cache hint {2}.
ValidationVisitor.input_variable_data_type_not_match=The expression "{0}" assigned to input variable "{1}" is of type "{2}" which cannot be implicitly converted to the expected type "{3}".
ValidationVisitor.input_variable_can_not_in_function=Input variable "{0}" cannot be an argument of a function in the criteria.
ValidationVisitor.groupby_subquery=Expressions used in a GROUP BY cannot be constant and must not contain subqueries: "{0}".
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestMaterialization.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -143,7 +143,7 @@
TestOptimizer.helpPlanCommand(command, metadata, getGenericFinder(), analysis, new String[] {"SELECT g_0.x FROM MatSrc.MatSrc AS g_0 WHERE g_0.x = '1'"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
}
- @Test public void testCacheHint() throws Exception {
+ @Test public void testDefaultMaterialization() throws Exception {
String userSql = "SELECT * from vgroup2"; //$NON-NLS-1$
QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
@@ -156,11 +156,11 @@
TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MatView.VGroup2.x FROM #MAT_MatView.VGroup2"}, plan);
Collection<Annotation> annotations = analysis.getAnnotations();
assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
- assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$
assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
}
- @Test public void testCacheHintWithPk() throws Exception {
+ @Test public void testDefaultMaterializationWithPK() throws Exception {
String userSql = "SELECT * from vgroup3 where x = 'foo'"; //$NON-NLS-1$
QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
@@ -174,8 +174,25 @@
TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MatView.VGroup3.x, #MAT_MatView.VGroup3.y FROM #MAT_MatView.VGroup3 WHERE #MAT_MatView.VGroup3.x = 'foo'"}, plan);
Collection<Annotation> annotations = analysis.getAnnotations();
assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
- assertTrue("Expected one annotation", annotations.size() == 1); //$NON-NLS-1$
+ assertEquals("Expected one annotation", 1, annotations.size()); //$NON-NLS-1$
assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
}
+
+ @Test public void testDefaultMaterializationWithCacheHint() throws Exception {
+ String userSql = "SELECT * from vgroup4"; //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleMaterializedView();
+ AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
+
+ Command command = helpGetCommand(userSql, metadata, null);
+ CommandContext cc = new CommandContext();
+ cc.setGlobalTableStore(new TempTableStore("SYSTEM"));
+ ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
+ TestOptimizer.checkAtomicQueries(new String[] {"SELECT #MAT_MatView.VGroup4.x FROM #MAT_MatView.VGroup4"}, plan);
+ Collection<Annotation> annotations = analysis.getAnnotations();
+ assertNotNull("Expected annotations but got none", annotations); //$NON-NLS-1$
+ assertEquals("Expected one annotation", 2, annotations.size()); //$NON-NLS-1$
+ assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW); //$NON-NLS-1$
+ }
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestOptionsAndHints.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -31,6 +31,7 @@
import org.junit.Test;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.sql.lang.AbstractCompareCriteria;
+import org.teiid.query.sql.lang.CacheHint;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
@@ -65,7 +66,7 @@
public class TestOptionsAndHints {
- /** Select a From db.g1 MAKENOTDEP, db.g2 MAKENOTDEP WHERE a = b */
+ /*+* Select a From db.g1 MAKENOTDEP, db.g2 MAKENOTDEP WHERE a = b */
@Test public void testOptionMakeNotDepInline4(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("c", "db.g2"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -94,7 +95,7 @@
query);
}
- /** Select a From db.g1 JOIN db.g2 MAKEDEP ON a = b */
+ /*+* Select a From db.g1 JOIN db.g2 MAKEDEP ON a = b */
@Test public void testOptionMakeDepInline1(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -119,7 +120,7 @@
query);
}
- /** Select a From db.g1 MAKEDEP JOIN db.g2 ON a = b */
+ /*+* Select a From db.g1 MAKEDEP JOIN db.g2 ON a = b */
@Test public void testOptionMakeDepInline2(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -144,7 +145,7 @@
query);
}
- /** Select a From (db.g1 MAKEDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKEDEP ON a = c */
+ /*+* Select a From (db.g1 MAKEDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKEDEP ON a = c */
@Test public void testOptionMakeDepInline3(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -175,7 +176,7 @@
query);
}
- /** Select a From db.g1 MAKEDEP, db.g2 MAKEDEP WHERE a = b */
+ /*+* Select a From db.g1 MAKEDEP, db.g2 MAKEDEP WHERE a = b */
@Test public void testOptionMakeDepInline4(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("c", "db.g2"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -213,7 +214,7 @@
assertTrue(((JoinPredicate)predicate.getLeftClause()).getLeftClause().isMakeDep());
}
- /** Select a From db.g1 JOIN db.g2 MAKENOTDEP ON a = b */
+ /*+* Select a From db.g1 JOIN db.g2 MAKENOTDEP ON a = b */
@Test public void testOptionMakeNotDepInline1(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -238,7 +239,7 @@
query);
}
- /** Select a From db.g1 MAKENOTDEP JOIN db.g2 ON a = b */
+ /*+* Select a From db.g1 MAKENOTDEP JOIN db.g2 ON a = b */
@Test public void testOptionMakeNotDepInline2(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -263,7 +264,7 @@
query);
}
- /** Select a From (db.g1 MAKENOTDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKENOTDEP ON a = c */
+ /*+* Select a From (db.g1 MAKENOTDEP JOIN db.g2 ON a = b) LEFT OUTER JOIN db.g3 MAKENOTDEP ON a = c */
@Test public void testOptionMakeNotDepInline3(){
GroupSymbol g1 = new GroupSymbol("db.g1"); //$NON-NLS-1$
GroupSymbol g2 = new GroupSymbol("db.g2"); //$NON-NLS-1$
@@ -380,7 +381,7 @@
query);
}
- /** SELECT a from g OPTION xyx */
+ /*+* SELECT a from g OPTION xyx */
@Test public void testFailsIllegalOption(){
TestParser.helpException("SELECT a from g OPTION xyx"); //$NON-NLS-1$
}
@@ -427,7 +428,7 @@
}
@Test public void testOptionalFromClause1() {
- String sql = "SELECT * FROM /* optional */ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+ optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -441,11 +442,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause1_1() {
- String sql = "SELECT * FROM /* optional*/ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+ optional*/ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -459,11 +460,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause1_2() {
- String sql = "SELECT * FROM /*optional */ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -477,11 +478,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause1_3() {
- String sql = "SELECT * FROM /* optional */ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+ optional */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -495,11 +496,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause1_4() {
- String sql = "SELECT * /* optional */ FROM /* OptiOnal */ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * /*+ optional */ FROM /*+ OptiOnal */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -513,11 +514,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause1_5() {
- String sql = "SELECT * FROM /* OptiOnal */ t1, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+ OptiOnal */ t1, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -531,11 +532,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause2() {
- String sql = "SELECT * FROM t1, /* optional */ t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM t1, /*+ optional */ t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -549,11 +550,11 @@
from.addClause(ufc);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM t1, /*+ optional */ t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause3() {
- String sql = "SELECT * FROM /* optional */ t1 AS a, t2"; //$NON-NLS-1$
+ String sql = "SELECT * FROM /*+ optional */ t1 AS a, t2"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -567,11 +568,11 @@
from.addGroup(new GroupSymbol("t2")); //$NON-NLS-1$
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM /* optional */ t1 AS a, t2", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM /*+ optional */ t1 AS a, t2", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause4() {
- String sql = "SELECT * FROM t1, /* optional */ t2 as a"; //$NON-NLS-1$
+ String sql = "SELECT * FROM t1, /*+ optional */ t2 as a"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -585,11 +586,11 @@
from.addClause(ufc);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ t2 AS a", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM t1, /*+ optional */ t2 AS a", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause5() {
- String sql = "SELECT * FROM t1, /* optional */ (select * from t1, t2) as x"; //$NON-NLS-1$
+ String sql = "SELECT * FROM t1, /*+ optional */ (select * from t1, t2) as x"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -612,11 +613,11 @@
from.addClause(sfc);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM t1, /* optional */ (SELECT * FROM t1, t2) AS x", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM t1, /*+ optional */ (SELECT * FROM t1, t2) AS x", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause6() {
- String sql = "SELECT * FROM t1 INNER JOIN /* optional */ (select a from t1, t2) AS x ON t1.a=x.a"; //$NON-NLS-1$
+ String sql = "SELECT * FROM t1 INNER JOIN /*+ optional */ (select a from t1, t2) AS x ON t1.a=x.a"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -645,11 +646,11 @@
from.addClause(joinPredicate);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT * FROM t1 INNER JOIN /* optional */ (SELECT a FROM t1, t2) AS x ON t1.a = x.a", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT * FROM t1 INNER JOIN /*+ optional */ (SELECT a FROM t1, t2) AS x ON t1.a = x.a", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause7() {
- String sql = "SELECT b FROM t1, /* optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)"; //$NON-NLS-1$
+ String sql = "SELECT b FROM t1, /*+ optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -674,11 +675,11 @@
from.addClause(joinPredicate);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT b FROM t1, /* optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT b FROM t1, /*+ optional */ (t2 INNER JOIN t3 ON t2.a = t3.a)", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause8() {
- String sql = "SELECT b FROM t1, /* optional */ (/* optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)"; //$NON-NLS-1$
+ String sql = "SELECT b FROM t1, /*+ optional */ (/*+ optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -712,11 +713,11 @@
from.addClause(joinPredicate);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT b FROM t1, /* optional */ (/* optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT b FROM t1, /*+ optional */ (/*+ optional */ (SELECT * FROM t1, t2) AS x INNER JOIN t3 ON x.a = t3.a)", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause9() {
- String sql = "SELECT b FROM (t1 LEFT OUTER JOIN /* optional */t2 on t1.a = t2.a) LEFT OUTER JOIN /* optional */t3 on t1.a = t3.a"; //$NON-NLS-1$
+ String sql = "SELECT b FROM (t1 LEFT OUTER JOIN /*+ optional */t2 on t1.a = t2.a) LEFT OUTER JOIN /*+ optional */t3 on t1.a = t3.a"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -746,7 +747,7 @@
from.addClause(joinPredicate2);
query.setFrom(from);
- TestParser.helpTest(sql, "SELECT b FROM (t1 LEFT OUTER JOIN /* optional */ t2 ON t1.a = t2.a) LEFT OUTER JOIN /* optional */ t3 ON t1.a = t3.a", query); //$NON-NLS-1$
+ TestParser.helpTest(sql, "SELECT b FROM (t1 LEFT OUTER JOIN /*+ optional */ t2 ON t1.a = t2.a) LEFT OUTER JOIN /*+ optional */ t3 ON t1.a = t3.a", query); //$NON-NLS-1$
}
@Test public void testOptionalFromClause10(){
@@ -828,11 +829,11 @@
TestParser.helpTest("CREATE PROCEDURE BEGIN DECLARE short var1;"+ //$NON-NLS-1$
" IF(HAS IN CRITERIA ON (a)) BEGIN var1 = SELECT a1 FROM g WHERE a2 = 5; END"+ //$NON-NLS-1$
- " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g, /* optional */ h WHERE a2 = 5; END" + //$NON-NLS-1$
+ " ELSE BEGIN DECLARE short var2; var2 = SELECT b1 FROM g, /*+ optional */ h WHERE a2 = 5; END" + //$NON-NLS-1$
" END", "CREATE PROCEDURE"+"\n"+"BEGIN"+"\n"+"DECLARE short var1;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
"IF(HAS IN CRITERIA ON (a))"+"\n"+"BEGIN"+"\n"+ "var1 = SELECT a1 FROM g WHERE a2 = 5;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
"END"+"\n"+"ELSE"+"\n"+"BEGIN"+"\n"+"DECLARE short var2;"+"\n"+ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "var2 = SELECT b1 FROM g, /* optional */ h WHERE a2 = 5;"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ "var2 = SELECT b1 FROM g, /*+ optional */ h WHERE a2 = 5;"+"\n"+"END"+"\n"+"END", cmd); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
@Test public void testStoredQueryWithOption(){
@@ -844,8 +845,8 @@
TestParser.helpTest("exec proc1() option nocache", "EXEC proc1() OPTION NOCACHE", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$
}
- /** Select a From db.g Option SHOWPLAN */
- /** Select a From db.g Option makedep a.b.c */
+ /*+* Select a From db.g Option SHOWPLAN */
+ /*+* Select a From db.g Option makedep a.b.c */
@Test public void testOptionMakeDependent1(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -867,7 +868,7 @@
query);
}
- /** Select a From db.g Option makedep a.b.c, d.e.f showplan */
+ /*+* Select a From db.g Option makedep a.b.c, d.e.f showplan */
@Test public void testOptionMakeDependent2(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -890,7 +891,7 @@
query);
}
- /** Select a From db.g Option makedep a.b.c, d.e.f, x.y.z */
+ /*+* Select a From db.g Option makedep a.b.c, d.e.f, x.y.z */
@Test public void testOptionMakeDependent3(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -914,7 +915,7 @@
query);
}
- /** Select a From db.g Option makenotdep a.b.c */
+ /*+* Select a From db.g Option makenotdep a.b.c */
@Test public void testOptionMakeNotDependent1(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -936,7 +937,7 @@
query);
}
- /** Select a From db.g Option makenotdep a.b.c, d.e.f showplan */
+ /*+* Select a From db.g Option makenotdep a.b.c, d.e.f showplan */
@Test public void testOptionMakeNotDependent2(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -959,7 +960,7 @@
query);
}
- /** Select a From db.g Option makenotdep a.b.c, d.e.f, x.y.z */
+ /*+* Select a From db.g Option makenotdep a.b.c, d.e.f, x.y.z */
@Test public void testOptionMakeNotDependent3(){
GroupSymbol g = new GroupSymbol("db.g"); //$NON-NLS-1$
From from = new From();
@@ -1037,7 +1038,7 @@
}
@Test public void testCache() {
- String sql = "/* cache */ SELECT * FROM t1"; //$NON-NLS-1$
+ String sql = "/*+ cache */ SELECT * FROM t1"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
@@ -1048,18 +1049,34 @@
from.addClause(ufc);
ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
query.setFrom(from);
- query.setCache(true);
- TestParser.helpTest(sql, "/* cache */ SELECT * FROM t1", query); //$NON-NLS-1$
+ query.setCacheHint(new CacheHint());
+ TestParser.helpTest(sql, "/*+ cache */ SELECT * FROM t1", query); //$NON-NLS-1$
}
@Test public void testCache1() {
- String sql = "/* cache */ execute foo()"; //$NON-NLS-1$
+ String sql = "/*+ cache */ execute foo()"; //$NON-NLS-1$
StoredProcedure sp = new StoredProcedure();
- sp.setCache(true);
+ sp.setCacheHint(new CacheHint());
sp.setProcedureName("foo"); //$NON-NLS-1$
- TestParser.helpTest(sql, "/* cache */ EXEC foo()", sp); //$NON-NLS-1$
+ TestParser.helpTest(sql, "/*+ cache */ EXEC foo()", sp); //$NON-NLS-1$
}
+ @Test public void testExpandedCacheHint() {
+ String sql = "/*+ cache( pref_mem ttl:2000) */ SELECT * FROM t1"; //$NON-NLS-1$
+
+ Query query = new Query();
+ Select select = new Select();
+ select.addSymbol(new AllSymbol());
+ query.setSelect(select);
+ From from = new From();
+ UnaryFromClause ufc = new UnaryFromClause();
+ from.addClause(ufc);
+ ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
+ query.setFrom(from);
+ query.setCacheHint(new CacheHint());
+ TestParser.helpTest(sql, "/*+ cache(pref_mem ttl:2000) */ SELECT * FROM t1", query); //$NON-NLS-1$
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestMaterialization.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -92,4 +92,14 @@
assertEquals(1, hdm.getCommandHistory().size());
}
+ @Test public void testTtl() throws Exception {
+ execute("SELECT * from vgroup4 where x = 'one'", Arrays.asList("one"));
+ assertEquals(1, hdm.getCommandHistory().size());
+ execute("SELECT * from vgroup4 where x is null", Arrays.asList((String)null));
+ assertEquals(1, hdm.getCommandHistory().size());
+ Thread.sleep(150);
+ execute("SELECT * from vgroup4 where x is null", Arrays.asList((String)null));
+ assertEquals(2, hdm.getCommandHistory().size());
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -194,13 +194,14 @@
}
@Test public void testInWithIndexUpdate() throws Exception {
- execute("create local temporary table x (e1 string, e2 integer, primary key (e1))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ execute("create local temporary table x (e1 string, e2 integer, e3 string, primary key (e1))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
execute("insert into x (e2, e1) values (3, 'a')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
execute("insert into x (e2, e1) values (2, 'b')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
execute("insert into x (e2, e1) values (1, 'c')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
execute("insert into x (e2, e1) values (0, 'd')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
- execute("insert into x (e2, e1) values (-1, 'e')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1, e3) values (-1, 'e', 'e')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
execute("update x set e2 = 5 where e1 in ('a', 'c')", new List[] {Arrays.asList(2)}); //$NON-NLS-1$
+ execute("select * from x where e1 in ('b', e3)", new List[] {Arrays.asList("b", 2, null), Arrays.asList("e", -1, "e")}); //$NON-NLS-1$
}
@Test public void testCompositeKeyCompareEquals() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -430,15 +430,6 @@
helpTestCompareSubqueryCriteria(crit, false, Collections.emptyList());
}
- /**
- * Special case: if no predicate quantifier is specified and the subquery returns no rows,
- * the result is false.
- */
- @Test public void testCompareSubqueryCriteriaNoRows3() throws Exception {
- SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
- helpTestCompareSubqueryCriteria(crit, false, Collections.emptyList());
- }
-
@Test public void testCompareSubqueryCriteria2() throws Exception {
SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ALL);
ArrayList values = new ArrayList();
@@ -474,46 +465,6 @@
helpTestCompareSubqueryCriteria(crit, true, values);
}
- @Test public void testCompareSubqueryCriteria6() throws Exception {
- SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
- ArrayList values = new ArrayList();
- values.add("a"); //$NON-NLS-1$
- helpTestCompareSubqueryCriteria(crit, true, values);
- }
-
- @Test public void testCompareSubqueryCriteria7() throws Exception {
- SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
- ArrayList values = new ArrayList();
- values.add("b"); //$NON-NLS-1$
- helpTestCompareSubqueryCriteria(crit, false, values);
- }
-
-
- /**
- * Should fail because the subquery needs to be scalar since it doesn't
- * have a predicate quantifier, but there is more than one value in the
- * ValueIterator
- */
- @Test public void testCompareSubqueryCriteriaFails1() throws Exception {
- SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
- ArrayList values = new ArrayList();
- values.add("a"); //$NON-NLS-1$
- values.add("b"); //$NON-NLS-1$
- values.add("c"); //$NON-NLS-1$
- try {
- helpTestCompareSubqueryCriteria(crit, false, values);
- } catch (ExpressionEvaluationException e) {
- assertEquals("Error Code:ERR.015.006.0056 Message:The subquery of this compare criteria has to be scalar, but returned more than one value: e1 = (<undefined>)", e.getMessage()); //$NON-NLS-1$
- }
- }
-
- @Test public void testCompareSubqueryCriteriaNulls2() throws Exception {
- SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.NO_QUANTIFIER);
- ArrayList values = new ArrayList();
- values.add(null);
- helpTestCompareSubqueryCriteria(crit, false, values);
- }
-
@Test public void testCompareSubqueryCriteriaNulls3() throws Exception {
SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ALL);
ArrayList values = new ArrayList();
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -53,6 +53,7 @@
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.IsNullCriteria;
import org.teiid.query.sql.lang.MatchCriteria;
import org.teiid.query.sql.lang.ProcedureContainer;
import org.teiid.query.sql.lang.Query;
@@ -230,12 +231,16 @@
helpTestRewriteCriteria("convert(pm1.g1.e2, string) not in ('x')", "pm1.g1.e2 IS NOT NULL"); //$NON-NLS-1$ //$NON-NLS-2$
}
- @Test public void testRewriteInCriteriaWithNoValues() throws Exception {
- Criteria crit = new SetCriteria(new ElementSymbol("e1"), Collections.EMPTY_LIST); //$NON-NLS-1$
+ @Test public void testRewriteInCriteriaWithNoValues() throws Exception {
+ ElementSymbol e1 = new ElementSymbol("e1");
+ e1.setGroupSymbol(new GroupSymbol("g1"));
+ Criteria crit = new SetCriteria(e1, Collections.EMPTY_LIST); //$NON-NLS-1$
Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null, null);
-
- assertEquals(QueryRewriter.FALSE_CRITERIA, actual);
+
+ IsNullCriteria inc = new IsNullCriteria(e1);
+ inc.setNegated(true);
+ assertEquals(inc, actual);
}
@Test public void testRewriteBetweenCriteria1() {
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -398,7 +398,7 @@
new UnaryFromClause(new GroupSymbol("m.g3")), //$NON-NLS-1$
JoinType.JOIN_CROSS);
jp.setOptional(true);
- helpTest(jp, "/* optional */ (m.g2 CROSS JOIN m.g3)"); //$NON-NLS-1$
+ helpTest(jp, "/*+ optional */ (m.g2 CROSS JOIN m.g3)"); //$NON-NLS-1$
}
public void testJoinPredicate2() {
@@ -921,7 +921,7 @@
SubqueryFromClause sfc = new SubqueryFromClause("temp", q1); //$NON-NLS-1$
sfc.setOptional(true);
- helpTest(sfc, "/* optional */ (SELECT e1 FROM m.g1) AS temp"); //$NON-NLS-1$
+ helpTest(sfc, "/*+ optional */ (SELECT e1 FROM m.g1) AS temp"); //$NON-NLS-1$
}
public void testSubquerySetCriteria1() {
@@ -962,7 +962,7 @@
public void testOptionalUnaryFromClause() {
UnaryFromClause unaryFromClause = new UnaryFromClause(new GroupSymbol("m.g1"));//$NON-NLS-1$
unaryFromClause.setOptional(true);
- helpTest(unaryFromClause, "/* optional */ m.g1"); //$NON-NLS-1$
+ helpTest(unaryFromClause, "/*+ optional */ m.g1"); //$NON-NLS-1$
}
public void testUpdate1() {
@@ -1692,23 +1692,6 @@
helpTest(scc, "e2 <= SOME (SELECT e1 FROM m.g1)"); //$NON-NLS-1$
}
- public void testSubqueryCompareCriteria3() {
-
- Select s1 = new Select();
- s1.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$
- From f1 = new From();
- f1.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$
- Query q1 = new Query();
- q1.setSelect(s1);
- q1.setFrom(f1);
-
- ElementSymbol expr = new ElementSymbol("e2"); //$NON-NLS-1$
-
- SubqueryCompareCriteria scc = new SubqueryCompareCriteria(expr, q1, SubqueryCompareCriteria.GE, SubqueryCompareCriteria.NO_QUANTIFIER);
-
- helpTest(scc, "e2 >= (SELECT e1 FROM m.g1)"); //$NON-NLS-1$
- }
-
public void testExistsCriteria1() {
Select s1 = new Select();
Modified: trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-06 20:38:03 UTC (rev 2426)
+++ trunk/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-08-07 12:55:23 UTC (rev 2427)
@@ -352,6 +352,8 @@
createKey("pk", vGroup3, vElements3.subList(0, 1));
+
+
return createTransformationMetadata(metadataStore, "");
}
14 years, 4 months
teiid SVN: r2426 - in trunk: runtime/src/main/java/org/teiid/deployers and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-08-06 16:38:03 -0400 (Fri, 06 Aug 2010)
New Revision: 2426
Modified:
trunk/connectors/connector-ldap/src/main/rar/META-INF/ra.xml
trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
Log:
TEIID-1188: missing '$' on the property
Modified: trunk/connectors/connector-ldap/src/main/rar/META-INF/ra.xml
===================================================================
--- trunk/connectors/connector-ldap/src/main/rar/META-INF/ra.xml 2010-08-06 18:42:16 UTC (rev 2425)
+++ trunk/connectors/connector-ldap/src/main/rar/META-INF/ra.xml 2010-08-06 20:38:03 UTC (rev 2426)
@@ -68,7 +68,7 @@
</config-property>
<config-property>
- <description>{$display:"Ldap Context Factory",$description:"LDAP Context factory Class",$required:"true", readOnly:"true"}</description>
+ <description>{$display:"Ldap Context Factory",$description:"LDAP Context factory Class",$required:"true", $readOnly:"true"}</description>
<config-property-name>LdapContextFactory</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>com.sun.jndi.ldap.LdapCtxFactory</config-property-value>
Modified: trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java 2010-08-06 18:42:16 UTC (rev 2425)
+++ trunk/runtime/src/main/java/org/teiid/deployers/ExtendedPropertyMetadata.java 2010-08-06 20:38:03 UTC (rev 2426)
@@ -105,7 +105,9 @@
index++;
}
// add last property
- addProperty(propertyName, values);
+ if (propertyName != null) {
+ addProperty(propertyName, values);
+ }
}
private void addProperty(String name, ArrayList<String> values) {
14 years, 4 months
teiid SVN: r2425 - in trunk/engine/src: main/java/org/teiid/query/tempdata and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-06 14:42:16 -0400 (Fri, 06 Aug 2010)
New Revision: 2425
Modified:
trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
Log:
TEIID-168 updating mat view logic to allow for an ordered insert, a bulk insert is still pending
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2010-08-06 18:15:20 UTC (rev 2424)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2010-08-06 18:42:16 UTC (rev 2425)
@@ -41,6 +41,8 @@
*/
@SuppressWarnings("unchecked")
public class STree {
+
+ public enum InsertMode {ORDERED, NEW, UPDATE}
private static final Random seedGenerator = new Random();
@@ -73,7 +75,7 @@
this.leafManager = leafManager;
this.comparator = comparator;
this.pageSize = Math.max(pageSize, SPage.MIN_PERSISTENT_SIZE);
- pageSize >>>= 4;
+ pageSize >>>= 3;
while (pageSize > 0) {
pageSize >>>= 1;
shift++;
@@ -84,6 +86,23 @@
this.types = types;
this.keytypes = Arrays.copyOf(types, keyLength);
}
+
+ protected SPage findChildTail(SPage page) {
+ if (page == null) {
+ page = header[header.length - 1];
+ while (page.next != null) {
+ page = page.next;
+ }
+ return page;
+ }
+ if (page.children != null) {
+ page = page.children.get(page.children.size() - 1);
+ while (page.next != null) {
+ page = page.next;
+ }
+ }
+ return page;
+ }
/**
* Determine a new random level using an XOR rng.
@@ -149,18 +168,29 @@
return null;
}
- public List insert(List tuple, boolean replace) throws TeiidComponentException {
+ public List insert(List tuple, InsertMode mode) throws TeiidComponentException {
LinkedList<SearchResult> places = new LinkedList<SearchResult>();
- List match = find(tuple, places);
- if (match != null) {
- if (!replace) {
+ List match = null;
+ if (mode == InsertMode.ORDERED) {
+ SPage last = null;
+ while (last == null || last.children != null) {
+ last = findChildTail(last);
+ //TODO: do this lazily
+ TupleBatch batch = last.getValues();
+ places.add(new SearchResult(-batch.getTuples().size() -1, last, batch));
+ }
+ } else {
+ match = find(tuple, places);
+ if (match != null) {
+ if (mode != InsertMode.UPDATE) {
+ return match;
+ }
+ SearchResult last = places.getLast();
+ SPage page = last.page;
+ last.values.getTuples().set(last.index, tuple);
+ page.setValues(last.values);
return match;
}
- SearchResult last = places.getLast();
- SPage page = last.page;
- last.values.getTuples().set(last.index, tuple);
- page.setValues(last.values);
- return match;
}
List key = extractKey(tuple);
int level = randomLevel();
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2010-08-06 18:15:20 UTC (rev 2424)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java 2010-08-06 18:42:16 UTC (rev 2425)
@@ -97,9 +97,8 @@
values = upper.values;
}
} else {
- bound = tree.header[0];
- while (bound.next != null) {
- bound = bound.next;
+ while (bound == null || bound.children != null) {
+ bound = tree.findChildTail(bound);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-08-06 18:15:20 UTC (rev 2424)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-08-06 18:42:16 UTC (rev 2425)
@@ -40,6 +40,7 @@
import org.teiid.common.buffer.TupleSource;
import org.teiid.common.buffer.BufferManager.BufferReserveMode;
import org.teiid.common.buffer.BufferManager.TupleSourceType;
+import org.teiid.common.buffer.STree.InsertMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
@@ -102,7 +103,7 @@
tuple.add(0, rowId.getAndIncrement());
}
currentTuple = tuple;
- insertTuple(tuple);
+ insertTuple(tuple, addRowId);
}
@Override
@@ -256,6 +257,7 @@
private String sessionID;
private TempMetadataID tid;
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private boolean updatable = true;
private int keyBatchSize;
private int leafBatchSize;
@@ -329,23 +331,30 @@
TupleBrowser browser = createTupleBrower(condition, direction);
TupleSource ts = new QueryTupleSource(browser, map, projectedCols, condition);
+
+ boolean usingQueryTupleSource = false;
try {
TupleBuffer tb = null;
if (!orderByUsingIndex && orderBy != null) {
SortUtility sort = new SortUtility(ts, orderBy.getOrderByItems(), Mode.SORT, bm, sessionID, projectedCols);
tb = sort.sort();
- } else {
+ } else if (!updatable) {
tb = bm.createTupleBuffer(projectedCols, sessionID, TupleSourceType.PROCESSOR);
- List next = null;
+ List<?> next = null;
while ((next = ts.nextTuple()) != null) {
tb.addTuple(next);
}
+ } else {
+ usingQueryTupleSource = true;
+ return ts;
}
tb.close();
return tb.createIndexedTupleSource(true);
} finally {
- //ensure the buffers get released
- ts.closeSource();
+ if (!usingQueryTupleSource) {
+ //ensure the buffers get released
+ ts.closeSource();
+ }
}
}
@@ -448,7 +457,7 @@
@Override
protected void undo(List tuple) throws TeiidComponentException, TeiidProcessingException {
if (primaryKeyChangePossible) {
- insertTuple(tuple);
+ insertTuple(tuple, false);
} else {
updateTuple(tuple);
}
@@ -506,7 +515,7 @@
@Override
protected void undo(List tuple) throws TeiidComponentException, TeiidProcessingException {
- insertTuple(tuple);
+ insertTuple(tuple, false);
}
};
int updateCount = up.process();
@@ -514,8 +523,8 @@
return CollectionTupleSource.createUpdateCountTupleSource(updateCount);
}
- private void insertTuple(List<Object> list) throws TeiidComponentException, TeiidProcessingException {
- if (tree.insert(list, false) != null) {
+ private void insertTuple(List<Object> list, boolean ordered) throws TeiidComponentException, TeiidProcessingException {
+ if (tree.insert(list, ordered?InsertMode.ORDERED:InsertMode.NEW) != null) {
throw new TeiidProcessingException(QueryPlugin.Util.getString("TempTable.duplicate_key")); //$NON-NLS-1$
}
}
@@ -527,7 +536,7 @@
}
private void updateTuple(List<?> tuple) throws TeiidComponentException {
- if (tree.insert(tuple, true) == null) {
+ if (tree.insert(tuple, InsertMode.UPDATE) == null) {
throw new AssertionError("Update failed"); //$NON-NLS-1$
}
}
@@ -535,5 +544,9 @@
void setPreferMemory(boolean preferMemory) {
this.tree.setPreferMemory(preferMemory);
}
+
+ void setUpdatable(boolean updatable) {
+ this.updatable = updatable;
+ }
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-06 18:15:20 UTC (rev 2424)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2010-08-06 18:42:16 UTC (rev 2425)
@@ -189,6 +189,7 @@
}
}
table = tts.addTempTable(tableName, create, bufferManager);
+ table.setUpdatable(false);
table.setPreferMemory(tableName.startsWith(CODE_PREFIX));
boolean success = false;
try {
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2010-08-06 18:15:20 UTC (rev 2424)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2010-08-06 18:42:16 UTC (rev 2425)
@@ -28,6 +28,7 @@
import java.util.List;
import org.junit.Test;
+import org.teiid.common.buffer.STree.InsertMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -44,7 +45,7 @@
STree map = bm.createSTree(elements, "1", 1);
for (int i = 20000; i > 0; i--) {
- assertNull(map.insert(Arrays.asList(i, String.valueOf(i)), true));
+ assertNull(map.insert(Arrays.asList(i, String.valueOf(i)), InsertMode.NEW));
assertEquals(20000 - i + 1, map.getRowCount());
}
@@ -53,7 +54,7 @@
}
assertEquals(0, map.getRowCount());
- assertNull(map.insert(Arrays.asList(1, String.valueOf(1)), true));
+ assertNull(map.insert(Arrays.asList(1, String.valueOf(1)), InsertMode.NEW));
}
}
14 years, 4 months
teiid SVN: r2424 - in trunk/client/src: test/java/org/teiid/adminapi/impl and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-08-06 14:15:20 -0400 (Fri, 06 Aug 2010)
New Revision: 2424
Modified:
trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
trunk/client/src/test/java/org/teiid/adminapi/impl/TestModelMetaData.java
Log:
TEIID-1006: in-correctly placing the VDB with warnings as "inactive", only validation errors count as errors not the warnings.
Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-08-06 05:08:25 UTC (rev 2423)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/ModelMetaData.java 2010-08-06 18:15:20 UTC (rev 2424)
@@ -39,6 +39,7 @@
import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
import org.teiid.adminapi.Model;
+import org.teiid.adminapi.impl.ModelMetaData.ValidationError.Severity;
@XmlAccessorType(XmlAccessType.NONE)
@@ -206,11 +207,21 @@
@ManagementProperty(description = "Model Validity Errors", readOnly=true, managed=true)
public List<ValidationError> getErrors(){
+ return getValidationErrors(Severity.ERROR);
+ }
+
+ public List<ValidationError> getValidationErrors(ValidationError.Severity severity){
if (this.errors == null) {
return Collections.emptyList();
}
- return this.errors;
- }
+ List<ValidationError> list = new ArrayList<ValidationError>();
+ for (ValidationError ve: this.errors) {
+ if (Severity.valueOf(ve.severity) == severity) {
+ list.add(ve);
+ }
+ }
+ return list;
+ }
public void addError(String severity, String message) {
if (this.errors == null) {
Modified: trunk/client/src/test/java/org/teiid/adminapi/impl/TestModelMetaData.java
===================================================================
--- trunk/client/src/test/java/org/teiid/adminapi/impl/TestModelMetaData.java 2010-08-06 05:08:25 UTC (rev 2423)
+++ trunk/client/src/test/java/org/teiid/adminapi/impl/TestModelMetaData.java 2010-08-06 18:15:20 UTC (rev 2424)
@@ -27,6 +27,7 @@
import org.junit.Test;
import org.teiid.adminapi.Model;
+@SuppressWarnings("nls")
public class TestModelMetaData {
@Test
@@ -56,4 +57,13 @@
assertTrue(!model.getProperties().isEmpty());
}
+
+ public void testErrors() {
+ ModelMetaData m = new ModelMetaData();
+ m.addError("ERROR", "I am Error");
+ m.addError("WARNING", "I am warning");
+
+ assertFalse(m.getErrors().isEmpty());
+ assertEquals(1, m.getErrors().size());
+ }
}
14 years, 4 months
teiid SVN: r2423 - in trunk/engine/src: main/java/org/teiid/query/optimizer/relational/rules and 10 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-08-06 01:08:25 -0400 (Fri, 06 Aug 2010)
New Revision: 2423
Modified:
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataStore.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/BatchedUpdateNode.java
trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-536 allowing for the evaluation of uncorrelated scalarsubqueries prior to pushdown if they cannot be pushed to the source.
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -41,28 +41,35 @@
private static final int LOCAL_CACHE_SIZE = 8;
+ public enum Type {
+ VIRTUAL,
+ TEMP,
+ SCALAR
+ }
+
private String ID; // never null, upper cased fully-qualified string
- private int selectPosition = -1; //used for order by symbol resolving. refers to the position in the select clause
- private int position;
- private Class<?> type; // type of this element, only for element
+ private Type metadataType = Type.VIRTUAL;
+
+ //Table metadata
+ private Collection<TempMetadataID> accessPatterns;
private List<TempMetadataID> elements; // of TempMetadataID, only for group
- private Object originalMetadataID;
- private boolean isVirtual = true; // virtual by default
- private boolean isTempTable;
- private Collection<TempMetadataID> accessPatterns;
private int cardinality = QueryMetadataInterface.UNKNOWN_CARDINALITY;
- private LRUCache<Object, Object> localCache;
- private boolean scalarGroup;
private List<TempMetadataID> primaryKey;
private QueryNode queryNode;
+ private transient LRUCache<Object, Object> localCache;
+ //Column metadata
+ private Object originalMetadataID;
+ private int position;
+ private Class<?> type; // type of this element, only for element
+
/**
* Constructor for group form of metadata ID.
* @param ID Fully-qualified, upper-case name of ID
* @param elements List of TempMetadataID representing elements
*/
public TempMetadataID(String ID, List<TempMetadataID> elements) {
- this(ID, elements, true, false);
+ this(ID, elements, Type.VIRTUAL);
}
/**
@@ -71,15 +78,14 @@
* @param elements List of TempMetadataID representing elements
* @param isVirtual whether or not the group is a virtual group
*/
- public TempMetadataID(String ID, List<TempMetadataID> elements, boolean isVirtual, boolean isTempTable) {
+ public TempMetadataID(String ID, List<TempMetadataID> elements, Type type) {
this.ID = ID;
this.elements = elements;
int pos = 1;
for (TempMetadataID tempMetadataID : elements) {
tempMetadataID.setPosition(pos++);
}
- this.isVirtual = isVirtual;
- this.isTempTable = isTempTable;
+ this.metadataType = type;
}
/**
@@ -147,7 +153,7 @@
* @return True if virtual
*/
public boolean isVirtual() {
- return this.isVirtual;
+ return metadataType == Type.VIRTUAL;
}
/**
@@ -156,7 +162,7 @@
* @since 5.5
*/
public boolean isTempTable() {
- return this.isTempTable;
+ return this.metadataType == Type.TEMP;
}
/**
@@ -222,17 +228,13 @@
}
public void setTempTable(boolean isTempTable) {
- this.isTempTable = isTempTable;
+ if (isTempTable) {
+ this.metadataType = Type.TEMP;
+ } else {
+ this.metadataType = Type.VIRTUAL;
+ }
}
- public int getSelectPosition() {
- return this.selectPosition;
- }
-
- public void setSelectPosition(int position) {
- this.selectPosition = position;
- }
-
Object getProperty(Object key) {
if (this.localCache != null) {
return this.localCache.get(key);
@@ -248,11 +250,11 @@
}
public boolean isScalarGroup() {
- return scalarGroup;
+ return this.metadataType == Type.SCALAR;
}
- public void setScalarGroup(boolean scalarGroup) {
- this.scalarGroup = scalarGroup;
+ public void setScalarGroup() {
+ this.metadataType = Type.SCALAR;
}
public List<TempMetadataID> getPrimaryKey() {
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataStore.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataStore.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
+import org.teiid.query.metadata.TempMetadataID.Type;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -115,7 +116,7 @@
}
// Create group ID
- TempMetadataID groupID = new TempMetadataID(tempName, elementIDs, isVirtual, isTempTable);
+ TempMetadataID groupID = new TempMetadataID(tempName, elementIDs, isVirtual?Type.VIRTUAL:Type.TEMP);
this.tempGroups.put(tempName, groupID);
return groupID;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CriteriaCapabilityValidatorVisitor.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -367,14 +367,14 @@
@Override
public void visit(ScalarSubquery obj) {
try {
- // Check if compares are allowed
- if(! this.caps.supportsCapability(Capability.QUERY_SUBQUERIES_SCALAR)) {
- markInvalid();
- return;
+ if(!this.caps.supportsCapability(Capability.QUERY_SUBQUERIES_SCALAR)
+ || validateSubqueryPushdown(obj, modelID, metadata, capFinder) == null) {
+ if (obj.getCommand().getCorrelatedReferences() == null) {
+ obj.setShouldEvaluate(true);
+ } else {
+ markInvalid();
+ }
}
- if (validateSubqueryPushdown(obj, modelID, metadata, capFinder) == null) {
- markInvalid();
- }
} catch(QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch(TeiidComponentException e) {
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -23,6 +23,7 @@
package org.teiid.query.optimizer.relational.rules;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -78,10 +79,22 @@
PlanNode endNode = NodeEditor.findParent(startNode.getType()==NodeConstants.Types.SOURCE?startNode.getParent():startNode, NodeConstants.Types.SOURCE);
+ boolean rewrite = false;
+ if (newGroups != null && newGroups.size() == 1) {
+ for (Expression expression : (Collection<Expression>)symbolMap.values()) {
+ if (!(expression instanceof ElementSymbol)) {
+ rewrite = true;
+ break;
+ }
+ }
+ } else {
+ rewrite = true;
+ }
+
while(current != endNode) {
// Make translations as defined in node in each current node
- convertNode(current, oldGroup, newGroups, symbolMap, metadata);
+ convertNode(current, oldGroup, newGroups, symbolMap, metadata, rewrite);
PlanNode parent = current.getParent();
@@ -162,7 +175,7 @@
// symbols. In that case, some additional work can be done because we can assume
// that an oldElement isn't being replaced by an expression using elements from
// multiple new groups.
- static void convertNode(PlanNode node, GroupSymbol oldGroup, Set<GroupSymbol> newGroups, Map symbolMap, QueryMetadataInterface metadata)
+ static void convertNode(PlanNode node, GroupSymbol oldGroup, Set<GroupSymbol> newGroups, Map symbolMap, QueryMetadataInterface metadata, boolean rewrite)
throws QueryPlannerException {
// Convert expressions from correlated subquery references;
@@ -203,7 +216,7 @@
if(type == NodeConstants.Types.SELECT) {
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
- crit = convertCriteria(crit, symbolMap, metadata);
+ crit = convertCriteria(crit, symbolMap, metadata, rewrite);
node.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit);
if (!singleMapping) {
@@ -223,7 +236,7 @@
List<Criteria> joinCrits = (List<Criteria>) node.getProperty(NodeConstants.Info.JOIN_CRITERIA);
if(joinCrits != null && !joinCrits.isEmpty()) {
Criteria crit = new CompoundCriteria(joinCrits);
- crit = convertCriteria(crit, symbolMap, metadata);
+ crit = convertCriteria(crit, symbolMap, metadata, rewrite);
if (crit instanceof CompoundCriteria) {
node.setProperty(NodeConstants.Info.JOIN_CRITERIA, ((CompoundCriteria)crit).getCriteria());
} else {
@@ -275,11 +288,14 @@
return expression;
}
- static Criteria convertCriteria(Criteria criteria, final Map symbolMap, QueryMetadataInterface metadata)
+ static Criteria convertCriteria(Criteria criteria, final Map symbolMap, QueryMetadataInterface metadata, boolean rewrite)
throws QueryPlannerException {
ExpressionMappingVisitor.mapExpressions(criteria, symbolMap);
+ if (!rewrite) {
+ return criteria;
+ }
// Simplify criteria if possible
try {
return QueryRewriter.rewriteCriteria(criteria, null, null, metadata);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -371,6 +371,7 @@
};
DeepPostOrderNavigator.doVisit(command, visitor);
}
+ command.setProcessorPlan(container.getCommand().getProcessorPlan());
container.setCommand(command);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCopyCriteria.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -131,7 +131,7 @@
Criteria tgtCrit = (Criteria) crit.clone();
try {
- tgtCrit = FrameUtil.convertCriteria(tgtCrit, tgtMap, metadata);
+ tgtCrit = FrameUtil.convertCriteria(tgtCrit, tgtMap, metadata, true);
} catch (QueryPlannerException err) {
LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, err, "Could not remap target criteria in RuleCopyCriteria"); //$NON-NLS-1$
return false;
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -756,7 +756,7 @@
throws QueryPlannerException {
while (node != null) {
- FrameUtil.convertNode(node, null, null, exprMap, metadata);
+ FrameUtil.convertNode(node, null, null, exprMap, metadata, true);
switch (node.getType()) {
case NodeConstants.Types.SOURCE:
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushSelectCriteria.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -562,7 +562,7 @@
copyNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE);
}
- FrameUtil.convertNode(copyNode, sourceGroup, null, symbolMap.asMap(), metadata);
+ FrameUtil.convertNode(copyNode, sourceGroup, null, symbolMap.asMap(), metadata, true);
PlanNode intermediateParent = NodeEditor.findParent(projectNode, NodeConstants.Types.ACCESS, NodeConstants.Types.SOURCE | NodeConstants.Types.SET_OP);
if (intermediateParent != null) {
intermediateParent.addAsParent(copyNode);
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -25,6 +25,7 @@
import static org.teiid.query.analysis.AnalysisRecord.*;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.teiid.api.exception.query.ExpressionEvaluationException;
@@ -35,6 +36,7 @@
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.eval.Evaluator;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.rewriter.QueryRewriter;
@@ -42,7 +44,7 @@
import org.teiid.query.util.CommandContext;
-public class AccessNode extends RelationalNode {
+public class AccessNode extends SubqueryAwareRelationalNode {
// Initialization state
private Command command;
@@ -110,15 +112,15 @@
}
protected boolean prepareNextCommand(Command atomicCommand) throws TeiidComponentException, TeiidProcessingException {
- return prepareCommand(atomicCommand, this, this.getContext(), this.getContext().getMetadata());
+ return prepareCommand(atomicCommand, getEvaluator(Collections.emptyMap()), this.getContext(), this.getContext().getMetadata());
}
- static boolean prepareCommand(Command atomicCommand, RelationalNode node, CommandContext context, QueryMetadataInterface metadata)
+ static boolean prepareCommand(Command atomicCommand, Evaluator eval, CommandContext context, QueryMetadataInterface metadata)
throws ExpressionEvaluationException, TeiidComponentException,
TeiidProcessingException {
try {
// Defect 16059 - Rewrite the command once the references have been replaced with values.
- QueryRewriter.evaluateAndRewrite(atomicCommand, node.getDataManager(), context, metadata);
+ QueryRewriter.evaluateAndRewrite(atomicCommand, eval, context, metadata);
} catch (QueryValidatorException e) {
throw new TeiidProcessingException(e, QueryExecPlugin.Util.getString("AccessNode.rewrite_failed", atomicCommand)); //$NON-NLS-1$
}
@@ -185,6 +187,7 @@
}
public void closeDirect() {
+ super.closeDirect();
closeSources();
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/BatchedUpdateNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/BatchedUpdateNode.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/BatchedUpdateNode.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -33,6 +34,7 @@
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.eval.Evaluator;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.sql.lang.BatchedUpdateCommand;
import org.teiid.query.sql.lang.Command;
@@ -45,7 +47,7 @@
* Node that batches commands sent to the DataManager.
* @since 4.2
*/
-public class BatchedUpdateNode extends RelationalNode {
+public class BatchedUpdateNode extends SubqueryAwareRelationalNode {
private static final List<Integer> ZERO_COUNT_TUPLE = Arrays.asList(Integer.valueOf(0));
@@ -98,7 +100,9 @@
boolean needProcessing = false;
if(shouldEvaluate != null && shouldEvaluate.get(i)) {
updateCommand = (Command) updateCommand.clone();
- needProcessing = AccessNode.prepareCommand(updateCommand, this, context, context.getMetadata());
+ Evaluator eval = getEvaluator(Collections.emptyMap());
+ eval.initialize(context, getDataManager());
+ needProcessing = AccessNode.prepareCommand(updateCommand, eval, context, context.getMetadata());
} else {
needProcessing = RelationalNodeUtil.shouldExecute(updateCommand, true);
}
@@ -146,6 +150,7 @@
* @since 4.2
*/
public void closeDirect() {
+ super.closeDirect();
if (tupleSource != null) {
tupleSource.closeSource();
tupleSource = null;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -229,7 +229,7 @@
GroupSymbol variables = new GroupSymbol(name);
externalGroups.addGroup(variables);
TempMetadataID tid = metadata.addTempGroup(name, symbols);
- tid.setScalarGroup(true);
+ tid.setScalarGroup();
variables.setMetadataID(tid);
return variables;
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/SetQueryResolver.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -36,15 +36,14 @@
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
-import org.teiid.query.metadata.TempMetadataID;
import org.teiid.query.resolver.CommandResolver;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.lang.QueryCommand;
import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.util.ErrorMessageKeys;
@@ -139,12 +138,11 @@
* @return True if the ORDER BY contains the element
*/
public static boolean orderByContainsVariable(OrderBy orderBy, SingleElementSymbol ses, int position) {
- for (final Iterator iterator = orderBy.getSortKeys().iterator(); iterator.hasNext();) {
- final ElementSymbol element = (ElementSymbol)iterator.next();
- if (position == ((TempMetadataID)element.getMetadataID()).getSelectPosition()) {
- return true;
- }
- }
+ for (OrderByItem item : orderBy.getOrderByItems()) {
+ if (item.getExpressionPosition() == position) {
+ return true;
+ }
+ }
return false;
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -427,7 +427,6 @@
if (matchedSymbol != null) {
TempMetadataID tempMetadataID = new TempMetadataID(symbol.getName(), matchedSymbol.getType());
int position = knownElements.indexOf(matchedSymbol);
- tempMetadataID.setSelectPosition(position);
symbol.setMetadataID(tempMetadataID);
symbol.setType(matchedSymbol.getType());
return position;
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -62,7 +62,6 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
-import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.processor.relational.DependentValueSource;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
@@ -180,7 +179,8 @@
private CreateUpdateProcedureCommand procCommand;
private boolean rewriteSubcommands;
- private ProcessorDataManager dataMgr;
+ private boolean processing;
+ private Evaluator evaluator;
private Map variables; //constant propagation
private int commandType;
@@ -189,12 +189,14 @@
this.metadata = metadata;
this.context = context;
this.procCommand = procCommand;
+ this.evaluator = new Evaluator(Collections.emptyMap(), null, context);
}
- public static Command evaluateAndRewrite(Command command, ProcessorDataManager dataMgr, CommandContext context, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
+ public static Command evaluateAndRewrite(Command command, Evaluator eval, CommandContext context, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
QueryRewriter queryRewriter = new QueryRewriter(metadata, context, null);
- queryRewriter.dataMgr = dataMgr;
+ queryRewriter.evaluator = eval;
queryRewriter.rewriteSubcommands = true;
+ queryRewriter.processing = true;
return queryRewriter.rewriteCommand(command, false);
}
@@ -1049,7 +1051,7 @@
private Criteria rewriteDependentSetCriteria(DependentSetCriteria dsc)
throws TeiidComponentException, TeiidProcessingException{
- if (dataMgr == null) {
+ if (!processing) {
return rewriteCriteria(dsc);
}
SetCriteria setCrit = new SetCriteria();
@@ -1147,9 +1149,9 @@
}
private Criteria evaluateCriteria(Criteria crit) throws TeiidComponentException, TeiidProcessingException{
- if(EvaluatableVisitor.isFullyEvaluatable(crit, true)) {
+ if(EvaluatableVisitor.isFullyEvaluatable(crit, !processing)) {
try {
- Boolean eval = new Evaluator(Collections.emptyMap(), this.dataMgr, context).evaluateTVL(crit, Collections.emptyList());
+ Boolean eval = evaluator.evaluateTVL(crit, Collections.emptyList());
if (eval == null) {
return UNKNOWN_CRITERIA;
@@ -1807,7 +1809,7 @@
private Criteria getSimpliedCriteria(Criteria crit, Expression a, boolean outcome, boolean nullPossible) {
if (nullPossible) {
if (outcome) {
- if (this.dataMgr != null) {
+ if (processing) {
return crit;
}
IsNullCriteria inc = new IsNullCriteria(a);
@@ -1885,7 +1887,7 @@
if (expression instanceof ElementSymbol) {
ElementSymbol es = (ElementSymbol)expression;
Class<?> type = es.getType();
- if (dataMgr == null && es.isExternalReference()) {
+ if (!processing && es.isExternalReference()) {
String grpName = es.getGroupSymbol().getCanonicalName();
if (variables == null) {
@@ -1922,7 +1924,11 @@
} else if (expression instanceof SearchedCaseExpression) {
expression = rewriteCaseExpression((SearchedCaseExpression)expression);
} else if (expression instanceof ScalarSubquery) {
- rewriteSubqueryContainer((ScalarSubquery)expression, true);
+ ScalarSubquery subquery = (ScalarSubquery)expression;
+ if (subquery.shouldEvaluate() && processing) {
+ return new Constant(evaluator.evaluate(subquery, null), subquery.getType());
+ }
+ rewriteSubqueryContainer(subquery, true);
return expression;
} else if (expression instanceof ExpressionSymbol) {
if (expression instanceof AggregateSymbol) {
@@ -1936,7 +1942,7 @@
rewriteExpressions(expression);
}
- if(dataMgr == null) {
+ if(!processing) {
if (!EvaluatableVisitor.isFullyEvaluatable(expression, true)) {
return expression;
}
@@ -1944,7 +1950,7 @@
return expression;
}
- Object value = new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(expression, Collections.emptyList());
+ Object value = evaluator.evaluate(expression, Collections.emptyList());
if (value instanceof Constant) {
return (Constant)value; //multi valued substitution
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/ScalarSubquery.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -43,9 +43,10 @@
private static AtomicInteger ID = new AtomicInteger();
private Command command;
- private Class type;
+ private Class<?> type;
private int hashCode;
private String id = "$sc/id" + ID.getAndIncrement(); //$NON-NLS-1$
+ private boolean shouldEvaluate;
/**
* Default constructor
@@ -58,6 +59,14 @@
this.setCommand(subqueryCommand);
}
+ public boolean shouldEvaluate() {
+ return shouldEvaluate;
+ }
+
+ public void setShouldEvaluate(boolean shouldEvaluate) {
+ this.shouldEvaluate = shouldEvaluate;
+ }
+
@Override
public String getContextSymbol() {
return id;
@@ -150,6 +159,7 @@
ScalarSubquery clone = new ScalarSubquery(copyCommand);
//Don't invoke the lazy-loading getType()
clone.setType(this.type);
+ clone.shouldEvaluate = this.shouldEvaluate;
return clone;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/EvaluatableVisitor.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -130,7 +130,11 @@
}
public void visit(ScalarSubquery obj){
- evaluationNotPossible(EvaluationLevel.PUSH_DOWN);
+ if (obj.shouldEvaluate()) {
+ evaluationNotPossible(EvaluationLevel.PROCESSING);
+ } else {
+ evaluationNotPossible(EvaluationLevel.PUSH_DOWN);
+ }
}
public void visit(DependentSetCriteria obj) {
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -1349,27 +1349,6 @@
});
}
- @Test public void testCompareSubquery4() {
- ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 > (select e1 FROM pm2.g1 where e2 = 13)", example1(), //$NON-NLS-1$
- new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 1, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // NestedLoopJoinStrategy
- 0, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
@Test public void testExistsSubquery1() {
ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where exists (select e1 FROM pm2.g1)", example1(), //$NON-NLS-1$
new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
@@ -1391,48 +1370,6 @@
});
}
- @Test public void testScalarSubquery1() {
- ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') from pm1.g1", example1(), //$NON-NLS-1$
- new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 1, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // NestedLoopJoinStrategy
- 0, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 0, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
- @Test public void testScalarSubquery2() {
- ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') as X from pm1.g1", example1(), //$NON-NLS-1$
- new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 1, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // NestedLoopJoinStrategy
- 0, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 0, // Project
- 0, // Select
- 0, // Sort
- 0 // UnionAll
- });
- }
-
@Test public void testTempGroup() {
ProcessorPlan plan = helpPlan("select e1 from tm1.g1 where e1 = 'x'", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
new String[] { "SELECT e1 FROM tm1.g1" }); //$NON-NLS-1$
@@ -5747,14 +5684,14 @@
caps.setFunctionSupport("convert", true); //$NON-NLS-1$
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
- String sql = "select e1 from pm1.g1 where e1 = convert((exec pm1.sq11(1, 2)), integer)"; //$NON-NLS-1$
+ String sql = "select pm1.g1.e1, pm1.g1.e2 from pm1.g1 where e1 = convert((exec pm1.sq11(e2, 2)), integer)"; //$NON-NLS-1$
helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null,
capFinder,
new String[] {
- "SELECT e1 FROM pm1.g1"}, //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, //$NON-NLS-1$
SHOULD_SUCCEED);
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSubqueryPushdown.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -217,7 +217,7 @@
/**
* Check that scalar subquery in select is pushed
*/
- public void DEFER_testPushSubqueryInSelectClause1() {
+ public void testPushSubqueryInSelectClause1() {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
@@ -710,6 +710,41 @@
new String[] { "SELECT g_0.e1, (convert((SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1), integer) + 1) FROM pm1.g1 AS g_0" }, SHOULD_SUCCEED); //$NON-NLS-1$
checkNodeTypes(plan, FULL_PUSHDOWN);
}
-
-
+
+ @Test public void testScalarSubquery2() {
+ ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where pm1.g1.e1 = 'x') as X from pm1.g1", example1(), //$NON-NLS-1$
+ new String[] { "SELECT e1 FROM pm1.g1" }); //$NON-NLS-1$
+ checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 1, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 0, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
+ /**
+ * Technically this is not a full push-down, but the subquery will be evaluated prior to pushdown
+ */
+ @Test public void testCompareSubquery4() {
+ ProcessorPlan plan = helpPlan("Select e1 from pm1.g1 where e1 > (select e1 FROM pm2.g1 where e2 = 13)", example1(), //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 > (SELECT g_1.e1 FROM pm2.g1 AS g_1 WHERE g_1.e2 = 13)" }); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+ }
+
+ @Test public void testScalarSubquery1() {
+ ProcessorPlan plan = helpPlan("Select e1, (select e1 FROM pm2.g1 where e1 = 'x') from pm1.g1", example1(), //$NON-NLS-1$
+ new String[] { "SELECT g_0.e1, (SELECT g_1.e1 FROM pm2.g1 AS g_1 WHERE g_1.e1 = 'x') FROM pm1.g1 AS g_0" }); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestGroupRecontext.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -122,7 +122,7 @@
SubqueryCompareCriteria crit = new SubqueryCompareCriteria(e1, query, SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ALL);
SubqueryCompareCriteria expected = new SubqueryCompareCriteria(x1, query, SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ALL);
- FrameUtil.convertCriteria(crit, symbolMap, null);
+ FrameUtil.convertCriteria(crit, symbolMap, null, true);
assertEquals(crit, expected);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-06 05:00:38 UTC (rev 2422)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-08-06 05:08:25 UTC (rev 2423)
@@ -23,6 +23,7 @@
package org.teiid.query.processor;
import static org.junit.Assert.*;
+import static org.teiid.query.optimizer.TestOptimizer.*;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -7483,6 +7484,32 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testUncorrelatedScalarSubqueryPushdown() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ FakeMetadataFacade metadata = example1();
+
+ BasicSourceCapabilities caps = getTypicalCapabilities();
+ caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_SCALAR, false);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
+ caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpPlan("select pm1.g1.e1 from pm1.g1 where e1 < (select max(vm1.g1.e1) from vm1.g1)", metadata, //$NON-NLS-1$
+ null, capFinder,
+ new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < (SELECT MAX(g_1.e1) FROM pm1.g1 AS g_1)" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ checkNodeTypes(plan, FULL_PUSHDOWN);
+
+ HardcodedDataManager hdm = new HardcodedDataManager();
+ hdm.addData("SELECT MAX(g_0.e1) FROM pm1.g1 AS g_0", new List[] {Arrays.asList("c")});
+ hdm.addData("SELECT g_0.e1 FROM pm1.g1 AS g_0 WHERE g_0.e1 < 'c'", new List[] {Arrays.asList("a")});
+
+ List[] expected = new List[] {
+ Arrays.asList("a"),
+ };
+
+ helpProcess(plan, hdm, expected);
+ }
private static final boolean DEBUG = false;
}
14 years, 4 months