[teiid-commits] teiid SVN: r2494 - in branches/7.1.x/engine/src: main/java/org/teiid/query/tempdata and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Aug 26 14:24:46 EDT 2010


Author: shawkins
Date: 2010-08-26 14:24:46 -0400 (Thu, 26 Aug 2010)
New Revision: 2494

Modified:
   branches/7.1.x/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
   branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
   branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
Log:
TEIID-1229 fix for partial composite index handling

Modified: branches/7.1.x/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java	2010-08-26 16:01:31 UTC (rev 2493)
+++ branches/7.1.x/engine/src/main/java/org/teiid/common/buffer/TupleBrowser.java	2010-08-26 18:24:46 UTC (rev 2494)
@@ -22,6 +22,7 @@
 
 package org.teiid.common.buffer;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -48,6 +49,8 @@
 	private TupleBatch values;
 	private boolean updated;
 	private boolean direction;
+	
+	private boolean inPartial;
 
 	/**
 	 * Construct a value based browser
@@ -73,10 +76,17 @@
 		this.tree = sTree;
 		this.direction = direction;
 		
+		init(lowerBound, upperBound);
+	}
+
+	private void init(List<Object> lowerBound,
+			List<Object> upperBound)
+			throws TeiidComponentException {
 		if (lowerBound != null) {
+			lowerBound.addAll(Collections.nCopies(tree.getKeyLength() - lowerBound.size(), null));
 			setPage(lowerBound);
 		} else {
-			page = sTree.header[0];
+			page = tree.header[0];
 		}
 		
 		boolean valid = true;
@@ -91,7 +101,9 @@
 			bound = upper.page;
 			boundIndex = upper.index;
 			if (boundIndex < 0) {
-				boundIndex = Math.min(upper.values.getTuples().size() - 1, -boundIndex -1);
+				//we are guaranteed by find to not get back the -1 index, unless
+				//there are now tuples, in which case a bound of -1 is fine
+				boundIndex = Math.min(upper.values.getTuples().size(), -boundIndex -1) - 1;
 			}
 			if (!direction) {
 				values = upper.values;
@@ -143,12 +155,17 @@
 			TeiidProcessingException {
 		for (;;) {
 			//first check for value iteration
-			if (valueSet != null) {
+			if (!inPartial && valueSet != null) {
 				if (valueSet.isEmpty()) {
 					resetState();
 					return null;
 				}
-				List<?> newValue = direction?valueSet.remove(0):valueSet.remove(valueSet.size() -1);
+				List<Object> newValue = direction?valueSet.remove(0):valueSet.remove(valueSet.size() -1);
+				if (newValue.size() < tree.getKeyLength()) {
+					init(new ArrayList<Object>(newValue), newValue);
+					inPartial = true;
+					continue;
+				}
 				if (values != null) {
 					int possibleIndex = Collections.binarySearch(values.getTuples(), newValue, tree.comparator);
 					if (possibleIndex >= 0) {
@@ -179,6 +196,10 @@
 				return values.getTuples().get(index);
 			}
 			if (page == null) {
+				if (inPartial) {
+					inPartial = false;
+					continue;
+				}
 				return null;
 			}
 			if (values == null) {
@@ -217,7 +238,7 @@
 	}
 	
 	private int getOffset() {
-		if (valueSet != null) {
+		if (!inPartial && valueSet != null) {
 			return 0;
 		}
 		return direction?1:-1;

Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTable.java	2010-08-26 16:01:31 UTC (rev 2493)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/tempdata/TempTable.java	2010-08-26 18:24:46 UTC (rev 2494)
@@ -23,7 +23,6 @@
 package org.teiid.query.tempdata;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -123,7 +122,7 @@
 		private TupleBrowser browser;
 
 		private QueryTupleSource(TupleBrowser browser, Map map,
-				List<SingleElementSymbol> projectedCols, Criteria condition) {
+				List<? extends SingleElementSymbol> projectedCols, Criteria condition) {
 			this.browser = browser;
 			this.indexes = RelationalNode.getProjectionIndexes(map, projectedCols);
 			this.eval = new Evaluator(map, null, null);
@@ -281,47 +280,46 @@
 		this.leafBatchSize = bm.getSchemaSize(columns.subList(0, primaryKeyLength));
 	}
 	
+	
 	private int reserveBuffers() {
 		return bm.reserveBuffers(leafBatchSize + (tree.getHeight() - 1)*keyBatchSize, BufferReserveMode.WAIT);
 	}
 
-	public TupleSource createTupleSource(final List<SingleElementSymbol> projectedCols, final Criteria condition, OrderBy orderBy) throws TeiidComponentException, TeiidProcessingException {
+	public TupleSource createTupleSource(final List<? extends SingleElementSymbol> projectedCols, final Criteria condition, OrderBy orderBy) throws TeiidComponentException, TeiidProcessingException {
 		Map map = RelationalNode.createLookupMap(getColumns());
 		
 		Boolean direction = null;
 		boolean orderByUsingIndex = false;
 		if (orderBy != null && rowId == null) {
 			int[] orderByIndexes = RelationalNode.getProjectionIndexes(map, orderBy.getSortKeys());
-			if (orderByIndexes.length < tree.getKeyLength()) {
-				orderByUsingIndex = false;
-			} else {
-				orderByUsingIndex = true;
-				for (int i = 0; i < tree.getKeyLength(); i++) {
-					if (orderByIndexes[i] != i) {
+			orderByUsingIndex = true;
+			for (int i = 0; i < tree.getKeyLength(); i++) {
+				if (orderByIndexes.length <= i) {
+					break;
+				}
+				if (orderByIndexes[i] != i) {
+					orderByUsingIndex = false;
+					break;
+				}
+			}
+			if (orderByUsingIndex) {
+				for (OrderByItem item : orderBy.getOrderByItems()) {
+					if (item.getNullOrdering() != null) {
 						orderByUsingIndex = false;
 						break;
 					}
-				}
-				if (orderByUsingIndex) {
-					for (int i = 0; i < tree.getKeyLength(); i++) {
-						OrderByItem item = orderBy.getOrderByItems().get(i);
-						if (item.getNullOrdering() != null) {
+					if (item.isAscending()) {
+						if (direction == null) {
+							direction = OrderBy.ASC;
+						} else if (direction != OrderBy.ASC) {
 							orderByUsingIndex = false;
 							break;
 						}
-						if (item.isAscending()) {
-							if (direction == null) {
-								direction = OrderBy.ASC;
-							} else if (direction != OrderBy.ASC) {
-								orderByUsingIndex = false;
-								break;
-							}
-						} else if (direction == null) {
-							direction = OrderBy.DESC;
-						} else if (direction != OrderBy.DESC) {
-							orderByUsingIndex = false;
-							break;
-						}
+					} else if (direction == null) {
+						direction = OrderBy.DESC;
+					} else if (direction != OrderBy.DESC) {
+						orderByUsingIndex = false;
+						break;
 					}
 				}
 			}
@@ -391,24 +389,11 @@
 							value.add(constant.getValue());
 							values.add(value);
 						}
-					} else if (values != null && values.size() == 1 && indexCondition.valueSet.size() == 1) {
+					} else if (values != null && values.size() == 1 && values.iterator().next().size() == i && indexCondition.valueSet.size() == 1) {
 						values.iterator().next().add(indexCondition.valueSet.first().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));
-				}
-			}
 		}
 		if (values != null) {
 			return new TupleBrowser(this.tree, values, direction);

Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java	2010-08-26 16:01:31 UTC (rev 2493)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTempTables.java	2010-08-26 18:24:46 UTC (rev 2494)
@@ -236,6 +236,16 @@
 		sampleTable();
 		execute("select * from x where e1 >= 'b' order by e1 desc, e2 desc", new List[] {Arrays.asList("c", 1), Arrays.asList("b", 3), Arrays.asList("b", 2)}); //$NON-NLS-1$
 	}
+	
+	@Test public void testCompositeKeyPartial5() throws Exception {
+		sampleTable();
+		execute("select * from x where e1 in ('a', 'b')", new List[] {Arrays.asList("a", 1), Arrays.asList("b", 2), Arrays.asList("b", 3)}); //$NON-NLS-1$
+	}
+	
+	@Test public void testCompositeKeyPartial6() 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("select * from x where e1 in ('a', 'b') order by e1 desc", new List[0]); //$NON-NLS-1$
+	}
 
 	private void sampleTable() throws Exception {
 		execute("create local temporary table x (e1 string, e2 integer, primary key (e1, e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$



More information about the teiid-commits mailing list