[teiid-commits] teiid SVN: r2436 - in trunk: client/src/main/java/org/teiid/adminapi/impl and 7 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Aug 10 23:42:12 EDT 2010


Author: shawkins
Date: 2010-08-10 23:42:11 -0400 (Tue, 10 Aug 2010)
New Revision: 2436

Modified:
   trunk/api/src/main/java/org/teiid/logging/LogConstants.java
   trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
   trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
   trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
   trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
   trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.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/resources/org/teiid/query/execution/i18n.properties
   trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
Log:
TEIID-168 updating mat logic, improving index support, adding logs for mat view loads

Modified: trunk/api/src/main/java/org/teiid/logging/LogConstants.java
===================================================================
--- trunk/api/src/main/java/org/teiid/logging/LogConstants.java	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/api/src/main/java/org/teiid/logging/LogConstants.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -43,6 +43,7 @@
 	public static final String CTX_QUERY_RESOLVER = CTX_QUERY_PLANNER + ".RESOLVER"; //$NON-NLS-1$
 	public static final String CTX_XML_PLANNER = CTX_QUERY_PLANNER + ".XML_PLANNER"; //$NON-NLS-1$
 	public static final String CTX_XML_PLAN = CTX_DQP + ".XML_PLAN"; //$NON-NLS-1$
+	public static final String CTX_MATVIEWS = CTX_DQP + ".MATVIEWS"; //$NON-NLS-1$
 	
 	public static final String CTX_WS = LogConstants.CTX_CONNECTOR + ".WS"; //$NON-NLS-1$
 }

Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -25,6 +25,7 @@
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.xml.bind.annotation.XmlAccessType;
@@ -199,6 +200,10 @@
 		return new ArrayList<Model>(this.models.getMap().values());
 	}
 	
+	public Map<String, ModelMetaData> getModelMetaDatas() {
+		return this.models.getMap();
+	}
+	
 	/**
 	 * This method required to make the JNDI assignment on the model work; if not persistent Management framework
 	 * treating "models" as ReadOnly property. The actual assignment is done in the VDBMetaDataClassInstancefactory

Modified: trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml	2010-08-11 03:42:11 UTC (rev 2436)
@@ -229,7 +229,7 @@
         The optional join hint is applied as a comment on a join clause.
         <example>
           <title>Example Optional Join Hint</title>
-          <programlisting>select a.column1, b.column2 from a inner join /* optional */ b on a.key = b.key</programlisting>
+          <programlisting>select a.column1, b.column2 from a inner join /*+ optional */ b on a.key = b.key</programlisting>
         </example>
       </para>
       <para> Suppose that the preceding example defined a view layer X.

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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -82,7 +82,7 @@
 		boolean valid = true;
 		
 		if (upperBound != null) {
-			if (this.tree.comparator.compare(upperBound, lowerBound) < 0) {
+			if (lowerBound != null && this.tree.comparator.compare(upperBound, lowerBound) < 0) {
 				valid = false;
 			}
 			LinkedList<SearchResult> places = new LinkedList<SearchResult>();

Modified: trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -48,7 +48,7 @@
 public class QueryProcessor implements BatchProducer {
 	
 	public static class ExpiredTimeSliceException extends TeiidRuntimeException {
-		
+		private static final long serialVersionUID = 4585044674826578060L;
 	}
 	
 	private static ExpiredTimeSliceException EXPIRED_TIME_SLICE = new ExpiredTimeSliceException();

Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -138,7 +138,13 @@
     public int compare(java.util.List<T> list1, java.util.List<T> list2) {
         int compare = 0;
         for (int k = 0; k < sortParameters.length; k++) {
+        	if (list1.size() <= sortParameters[k]) {
+            	return 1;
+            }
             T param1 = list1.get(sortParameters[k]);
+            if (list2.size() <= sortParameters[k]) {
+            	return -1;
+            }
             T param2 = list2.get(sortParameters[k]);
 
             if( param1 == null ) {

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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/IndexCondition.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -43,9 +43,6 @@
 		List<Criteria> crits = Criteria.separateCriteriaByAnd(condition);
 		IndexCondition[] conditions = new IndexCondition[keyColumns.size()];
 		for (int i = 0; i < conditions.length; i++) {
-			if (i > 0 && conditions[i - 1].valueSet.size() != 1) {
-				break; //don't yet support any other types of composite key lookups
-			}
 			conditions[i] = new IndexCondition();
 			ElementSymbol keyColumn = keyColumns.get(i);
 			for (Iterator<Criteria> critIter = crits.iterator(); critIter.hasNext();) {

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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -23,7 +23,7 @@
 package org.teiid.query.tempdata;
 
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -365,26 +365,48 @@
 		List<List<Object>> values = null;
 		if (condition != null && rowId == null) {
 			IndexCondition[] indexConditions = IndexCondition.getIndexConditions(condition, columns.subList(0, tree.getKeyLength()));
-			if (indexConditions.length > 1 && indexConditions[indexConditions.length - 1] != null) {
-				List<Object> value = new ArrayList<Object>(indexConditions.length);
-				for (IndexCondition indexCondition : indexConditions) {
-					value.add(indexCondition.valueSet.iterator().next().getValue());
+			for (int i = 0; i < indexConditions.length; i++) {
+				IndexCondition indexCondition = indexConditions[i];
+				if (indexCondition.lower != null) {
+					if (i == 0) {
+						lower = new ArrayList<Object>(tree.getKeyLength());
+						lower.add(indexCondition.lower.getValue());
+					} if (lower != null && lower.size() == i) {
+						lower.add(indexCondition.lower.getValue());
+					}
+				} 
+				if (indexCondition.upper != null) {
+					if (i == 0) {
+						upper = new ArrayList<Object>(tree.getKeyLength());
+						upper.add(indexCondition.upper.getValue());
+					} else if (upper != null && upper.size() == i) {
+						upper.add(indexCondition.upper.getValue());
+					}
+				} 
+				if (!indexCondition.valueSet.isEmpty()) {
+					if (i == 0) {
+						values = new ArrayList<List<Object>>();
+						for (Constant constant : indexCondition.valueSet) {
+							List<Object> value = new ArrayList<Object>(tree.getKeyLength());
+							value.add(constant.getValue());
+							values.add(value);
+						}
+					} else if (values != null && values.size() == 1 && indexCondition.valueSet.size() == 1) {
+						values.iterator().next().add(indexCondition.valueSet.first().getValue());
+					}
 				}
-				values = new ArrayList<List<Object>>(1);
-				values.add(value);
-				//TODO: support other composite key lookups
-			} else {
-				if (indexConditions[0].lower != null) {
-					lower = Arrays.asList(indexConditions[0].lower.getValue());
-				}
-				if (indexConditions[0].upper != null) {
-					upper = Arrays.asList(indexConditions[0].upper.getValue());
-				}
-				if (!indexConditions[0].valueSet.isEmpty()) {
-					values = new ArrayList<List<Object>>();
-					for (Constant constant : indexConditions[0].valueSet) {
-						values.add(Arrays.asList(constant.getValue()));
+			}
+			if (indexConditions.length > 0) {
+				if (values != null) {
+					List<Object> value = values.iterator().next();
+					if (value.size() != tree.getKeyLength()) {
+						values = null;
+						lower = new ArrayList<Object>(value);
+						lower.addAll(Collections.nCopies(tree.getKeyLength() - value.size(), null));
+						upper = new ArrayList<Object>(value);
 					}
+				} else if (lower != null) {
+					lower.addAll(Collections.nCopies(tree.getKeyLength() - lower.size(), null));
 				}
 			}
 		}
@@ -553,5 +575,12 @@
 	CacheHint getCacheHint() {
 		return this.tid.getCacheHint();
 	}
+	
+	int getPkLength() {
+		if (rowId != null) {
+			return 0;
+		}
+		return this.tree.getKeyLength();
+	}
 
 }
\ 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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -36,6 +36,8 @@
 import org.teiid.core.TeiidProcessingException;
 import org.teiid.core.types.DataTypeManager;
 import org.teiid.language.SQLConstants.Reserved;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
 import org.teiid.query.eval.Evaluator;
 import org.teiid.query.execution.QueryExecPlugin;
 import org.teiid.query.mapping.relational.QueryNode;
@@ -209,7 +211,7 @@
 			TempTableStore globalStore, MatTableInfo info)
 			throws QueryMetadataException, TeiidComponentException,
 			TeiidProcessingException, ExpressionEvaluationException {
-		TempTable table;
+		LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryExecPlugin.Util.getString("TempTableDataManager.loading", tableName)); //$NON-NLS-1$
 		QueryMetadataInterface metadata = context.getMetadata();
 		Create create = new Create();
 		create.setTable(group);
@@ -220,7 +222,7 @@
 				create.getPrimaryKey().add(create.getColumns().get(metadata.getPosition(col)-1));
 			}
 		}
-		table = globalStore.addTempTable(tableName, create, bufferManager);
+		TempTable table = globalStore.addTempTable(tableName, create, bufferManager);
 		table.setUpdatable(false);
 		CacheHint hint = table.getCacheHint();
 		if (hint != null) {
@@ -229,7 +231,7 @@
 				info.setTtl(table.getCacheHint().getTtl());
 			}
 		}
-		boolean success = false;
+		int rowCount = -1;
 		try {
 			//TODO: order by primary key nulls first - then have an insert ordered optimization
 			//TODO: use the getCommand logic in RelationalPlanner to reuse commands for this.
@@ -239,12 +241,16 @@
 			TupleSource ts = new BatchCollector.BatchProducerTupleSource(qp);
 			//TODO: if this insert fails, it's unnecessary to do the undo processing
 			table.insert(ts, table.getColumns());
-			success = true;
+			rowCount = table.getRowCount();
 		} finally {
-			if (!success) {
+			if (rowCount == -1) {
 				globalStore.removeTempTableByName(tableName);
+				info.setState(MatState.FAILED_LOAD);
+				LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryExecPlugin.Util.getString("TempTableDataManager.failed_load", tableName)); //$NON-NLS-1$
+			} else {
+				info.setState(MatState.LOADED);
+				LogManager.logInfo(LogConstants.CTX_MATVIEWS, QueryExecPlugin.Util.getString("TempTableDataManager.loaded", tableName, rowCount)); //$NON-NLS-1$
 			}
-			info.setState(success?MatState.LOADED:MatState.FAILED_LOAD);
 		}
 		return table;
 	}

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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -55,6 +55,7 @@
 		private long updateTime = -1;
 		private MatState state = MatState.NOT_LOADED;
 		private long ttl = -1;
+		private boolean valid;
 		
 		synchronized boolean shouldLoad() throws TeiidComponentException {
     		for (;;) {
@@ -65,6 +66,9 @@
 				state = MatState.LOADING;
 				return true;
 			case LOADING:
+				if (valid) {
+					return false;
+				}
 				try {
 					wait();
 				} catch (InterruptedException e) {
@@ -81,10 +85,15 @@
     		}
 		}
 		
-		public synchronized void setState(MatState state) {
+		public synchronized MatState setState(MatState state) {
+			MatState oldState = this.state;
+			if (state == MatState.LOADED) {
+				valid = true;
+			}
 			this.state = state;
 			this.updateTime = System.currentTimeMillis();
 			notifyAll();
+			return oldState;
 		}
 		
 		public synchronized void setTtl(long ttl) {
@@ -99,6 +108,14 @@
 			return state;
 		}
 		
+		public boolean isValid() {
+			return valid;
+		}
+		
+		public void setValid(boolean valid) {
+			this.valid = valid;
+		}
+		
 	}
 	
 	private ConcurrentHashMap<String, MatTableInfo> matTables = new ConcurrentHashMap<String, MatTableInfo>();

Modified: trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties	2010-08-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties	2010-08-11 03:42:11 UTC (rev 2436)
@@ -221,3 +221,7 @@
 XMLTableNode.error=Error evaluating XQuery row context for XMLTable: {0}
 XMLTableNode.path_error=Error evaluating XMLTable column path expression for column: {0}
 XMLTableName.multi_value=Unexpected multi-valued result was returned for XMLTable column "{0}".  Path expressions for non-XML type columns should return at most a single result.
+
+TempTableDataManager.failed_load=Failed to load MatView {0}
+TempTableDataManager.loaded=Loaded MatView {0} with row count {1}
+TempTableDataManager.loading=Loading MatView {0}
\ No newline at end of file

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-10 19:58:37 UTC (rev 2435)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java	2010-08-11 03:42:11 UTC (rev 2436)
@@ -212,4 +212,16 @@
 		execute("select * from x where e1 = 'b' and e2 = 2", new List[] {Arrays.asList("b", 2)}); //$NON-NLS-1$
 	}
 	
+	@Test public void testCompositeKeyPartial() throws Exception {
+		execute("create local temporary table x (e1 string, e2 integer, primary key (e1, e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+		execute("insert into x (e2, e1) values (3, 'b')", 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 (1, 'a')", new List[] {Arrays.asList(1)}); //$NON-NLS-1$
+		execute("select * from x where e1 = 'b'", new List[] {Arrays.asList("b", 2), Arrays.asList("b", 3)}); //$NON-NLS-1$
+		execute("select * from x where e1 < 'c'", new List[] {Arrays.asList("a", 1), Arrays.asList("b", 2), Arrays.asList("b", 3)}); //$NON-NLS-1$
+		execute("select * from x where e2 = 1", new List[] {Arrays.asList("a", 1), Arrays.asList("c", 1)}); //$NON-NLS-1$
+		execute("select * from x where e1 >= 'b'", new List[] {Arrays.asList("b", 2), Arrays.asList("b", 3), Arrays.asList("c", 1)}); //$NON-NLS-1$
+	}
+	
 }



More information about the teiid-commits mailing list