You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/05/22 04:45:23 UTC
kylin git commit: minor, close readers in SnapshotTable.takeSnapshot()
Repository: kylin
Updated Branches:
refs/heads/master b6499b5c3 -> 60a254fa1
minor, close readers in SnapshotTable.takeSnapshot()
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/60a254fa
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/60a254fa
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/60a254fa
Branch: refs/heads/master
Commit: 60a254fa10ad16570eb19c7297a0bb713a70a86d
Parents: b6499b5
Author: Yang Li <li...@apache.org>
Authored: Sun May 22 12:45:15 2016 +0800
Committer: Yang Li <li...@apache.org>
Committed: Sun May 22 12:45:15 2016 +0800
----------------------------------------------------------------------
.../apache/kylin/dict/lookup/SnapshotTable.java | 42 ++++++++++++--------
1 file changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/60a254fa/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/SnapshotTable.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/SnapshotTable.java b/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/SnapshotTable.java
index fdc0c44..7e49125 100644
--- a/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/SnapshotTable.java
+++ b/core-dictionary/src/main/java/org/apache/kylin/dict/lookup/SnapshotTable.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.kylin.common.persistence.ResourceStore;
import org.apache.kylin.common.persistence.RootPersistentEntity;
@@ -73,30 +74,39 @@ public class SnapshotTable extends RootPersistentEntity implements ReadableTable
TrieDictionaryBuilder<String> b = new TrieDictionaryBuilder<String>(new StringBytesConverter());
TableReader reader = table.getReader();
- while (reader.next()) {
- String[] row = reader.getRow();
- if (row.length <= maxIndex) {
- throw new IllegalStateException("Bad hive table row, " + tableDesc + " expect " + (maxIndex + 1) + " columns, but got " + Arrays.toString(row));
- }
+ try {
+ while (reader.next()) {
+ String[] row = reader.getRow();
+ if (row.length <= maxIndex) {
+ throw new IllegalStateException("Bad hive table row, " + tableDesc + " expect " + (maxIndex + 1) + " columns, but got " + Arrays.toString(row));
+ }
- for (String cell : row) {
- if (cell != null)
- b.addValue(cell);
+ for (String cell : row) {
+ if (cell != null)
+ b.addValue(cell);
+ }
}
+ } finally {
+ IOUtils.closeQuietly(reader);
}
this.dict = b.build(0);
- reader = table.getReader();
ArrayList<int[]> allRowIndices = new ArrayList<int[]>();
- while (reader.next()) {
- String[] row = reader.getRow();
- int[] rowIndex = new int[row.length];
- for (int i = 0; i < row.length; i++) {
- rowIndex[i] = dict.getIdFromValue(row[i]);
+ reader = table.getReader();
+ try {
+ while (reader.next()) {
+ String[] row = reader.getRow();
+ int[] rowIndex = new int[row.length];
+ for (int i = 0; i < row.length; i++) {
+ rowIndex[i] = dict.getIdFromValue(row[i]);
+ }
+ allRowIndices.add(rowIndex);
}
- allRowIndices.add(rowIndex);
+ } finally {
+ IOUtils.closeQuietly(reader);
}
+
this.rowIndices = allRowIndices;
}
@@ -249,7 +259,7 @@ public class SnapshotTable extends RootPersistentEntity implements ReadableTable
this.rowIndices.add(rowIndex);
}
}
- }else{
+ } else {
rowIndices = new ArrayList<int[]>();
dict = new TrieDictionary<String>();
}