close OLAPEnumerator at exception

Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e14aadf6
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e14aadf6
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e14aadf6

Branch: refs/heads/mhb-master
Commit: e14aadf6a5d64dc47d4a7f26feaae56c8f80ff87
Parents: 53b6c8c
Author: Hongbin Ma <[email protected]>
Authored: Sat Dec 24 18:19:02 2016 +0800
Committer: Hongbin Ma <[email protected]>
Committed: Tue Dec 27 22:15:44 2016 +0800

----------------------------------------------------------------------
 .../kylin/query/enumerator/OLAPEnumerator.java  | 32 +++++++++++++-------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/e14aadf6/query/src/main/java/org/apache/kylin/query/enumerator/OLAPEnumerator.java
----------------------------------------------------------------------
diff --git 
a/query/src/main/java/org/apache/kylin/query/enumerator/OLAPEnumerator.java 
b/query/src/main/java/org/apache/kylin/query/enumerator/OLAPEnumerator.java
index c7b3c71..408d227 100644
--- a/query/src/main/java/org/apache/kylin/query/enumerator/OLAPEnumerator.java
+++ b/query/src/main/java/org/apache/kylin/query/enumerator/OLAPEnumerator.java
@@ -61,20 +61,30 @@ public class OLAPEnumerator implements Enumerator<Object[]> 
{
 
     @Override
     public boolean moveNext() {
-        if (cursor == null) {
-            cursor = queryStorage();
-        }
+        try {
+            if (cursor == null) {
+                cursor = queryStorage();
+            }
 
-        if (!cursor.hasNext()) {
-            return false;
-        }
+            if (!cursor.hasNext()) {
+                return false;
+            }
 
-        ITuple tuple = cursor.next();
-        if (tuple == null) {
-            return false;
+            ITuple tuple = cursor.next();
+            if (tuple == null) {
+                return false;
+            }
+            convertCurrentRow(tuple);
+            return true;
+        } finally {
+            try {
+                if (cursor != null) {
+                    cursor.close();
+                }
+            } catch (Exception e) {
+                logger.info("Error when closing cursor, ignore it", e);
+            }
         }
-        convertCurrentRow(tuple);
-        return true;
     }
 
     private Object[] convertCurrentRow(ITuple tuple) {

Reply via email to