added Nick's bugfix

git-svn-id: https://hyracks.googlecode.com/svn/trunk/hyracks@204 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
index f3cb8a9..7d23ba3 100644
--- a/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
+++ b/hyracks-storage-am-btree/src/main/java/edu/uci/ics/hyracks/storage/am/btree/dataflow/BTreeSearchOperatorNodePushable.java
@@ -107,7 +107,8 @@
         writeBuffer = btreeOpHelper.getHyracksContext().getResourceManager().allocateFrame();
         tb = new ArrayTupleBuilder(btree.getMultiComparator().getFieldCount());
         dos = tb.getDataOutput();
-        appender = new FrameTupleAppender(btreeOpHelper.getHyracksContext());                
+        appender = new FrameTupleAppender(btreeOpHelper.getHyracksContext());    
+        appender.reset(writeBuffer, true);
     }
     	
     private void writeSearchResults() throws Exception {
@@ -144,15 +145,9 @@
                 rangePred.setHighKey(highKey);
                 
                 cursor.reset();
-                btree.search(cursor, rangePred, leafFrame, interiorFrame);
-                appender.reset(writeBuffer, true);
-                writeSearchResults();                                                         
-            }
-        	
-        	if (appender.getTupleCount() > 0) {
-    			FrameUtils.flushFrame(writeBuffer, writer);
-    		}
-        	
+                btree.search(cursor, rangePred, leafFrame, interiorFrame);                
+                writeSearchResults();    
+            }       	        	
         } catch (Exception e) {
         	throw new HyracksDataException(e);
         }
@@ -160,6 +155,10 @@
 	
 	@Override
 	public void close() throws HyracksDataException {
+		if (appender.getTupleCount() > 0) {
+			FrameUtils.flushFrame(writeBuffer, writer);
+		}
+    			
 		writer.close();
 		try {
 			cursor.close();
@@ -169,6 +168,9 @@
 	}
 
 	@Override
-	public void flush() throws HyracksDataException {		
+	public void flush() throws HyracksDataException {	
+		if (appender.getTupleCount() > 0) {
+			FrameUtils.flushFrame(writeBuffer, writer);
+		}
 	}	
 }
\ No newline at end of file