You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2017/11/06 15:43:44 UTC
hive git commit: HIVE-16736 : General Improvements to BufferedRows
(BELUGA BEHR via Ashutosh Chauhan)
Repository: hive
Updated Branches:
refs/heads/master 993a16c3d -> 071db96e9
HIVE-16736 : General Improvements to BufferedRows (BELUGA BEHR via Ashutosh Chauhan)
Signed-off-by: Ashutosh Chauhan <ha...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/071db96e
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/071db96e
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/071db96e
Branch: refs/heads/master
Commit: 071db96e9c0840804d45d0d883b4f2576c00ffe2
Parents: 993a16c
Author: BELUGA BEHR <da...@gmail.com>
Authored: Tue May 23 02:49:00 2017 -0700
Committer: Ashutosh Chauhan <ha...@apache.org>
Committed: Mon Nov 6 07:43:33 2017 -0800
----------------------------------------------------------------------
.../org/apache/hive/beeline/BufferedRows.java | 48 +++++++++-----------
1 file changed, 22 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/071db96e/beeline/src/java/org/apache/hive/beeline/BufferedRows.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/BufferedRows.java b/beeline/src/java/org/apache/hive/beeline/BufferedRows.java
index 5369b08..f7e10a4 100644
--- a/beeline/src/java/org/apache/hive/beeline/BufferedRows.java
+++ b/beeline/src/java/org/apache/hive/beeline/BufferedRows.java
@@ -24,18 +24,20 @@ package org.apache.hive.beeline;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.List;
import com.google.common.base.Optional;
/**
- * Rows implementation which buffers all rows in a linked list.
+ * Rows implementation which buffers all rows
*/
class BufferedRows extends Rows {
- private final LinkedList<Row> list;
+ private final List<Row> list;
private final Iterator<Row> iterator;
+ private int columnCount;
private int maxColumnWidth;
BufferedRows(BeeLine beeLine, ResultSet rs) throws SQLException {
@@ -44,21 +46,17 @@ class BufferedRows extends Rows {
BufferedRows(BeeLine beeLine, ResultSet rs, Optional<Integer> limit) throws SQLException {
super(beeLine, rs);
- list = new LinkedList<Row>();
- int count = rsMeta.getColumnCount();
- list.add(new Row(count));
+ list = new ArrayList<Row>();
+ columnCount = rsMeta.getColumnCount();
+ list.add(new Row(columnCount));
int numRowsBuffered = 0;
- if (limit.isPresent()) {
- while (limit.get() > numRowsBuffered && rs.next()) {
- this.list.add(new Row(count, rs));
- numRowsBuffered++;
- }
- } else {
- while (rs.next()) {
- this.list.add(new Row(count, rs));
- }
+ int maxRowsBuffered = limit.or(Integer.MAX_VALUE);
+
+ while (numRowsBuffered++ < maxRowsBuffered && rs.next()) {
+ this.list.add(new Row(columnCount, rs));
}
+
iterator = list.iterator();
maxColumnWidth = beeLine.getOpts().getMaxColumnWidth();
}
@@ -80,18 +78,16 @@ class BufferedRows extends Rows {
@Override
void normalizeWidths() {
- int[] max = null;
- for (Row row : list) {
- if (max == null) {
- max = new int[row.values.length];
+ if (!list.isEmpty())
+ {
+ int[] max = new int[columnCount];
+ for (Row row : list) {
+ for (int j = 0; j < columnCount; j++) {
+ // if the max column width is too large, reset it to max allowed Column width
+ max[j] = Math.min(Math.max(max[j], row.sizes[j] + 1), maxColumnWidth);
+ }
+ row.sizes = max;
}
- for (int j = 0; j < max.length; j++) {
- // if the max column width is too large, reset it to max allowed Column width
- max[j] = Math.min(Math.max(max[j], row.sizes[j] + 1), maxColumnWidth);
- }
- }
- for (Row row : list) {
- row.sizes = max;
}
}
}