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, "");
}