You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by pr...@apache.org on 2017/09/26 06:48:25 UTC

zeppelin git commit: ZEPPELIN-2833 JDBC Interpreter doesn't follow JDBC specification when…

Repository: zeppelin
Updated Branches:
  refs/heads/master 184283c4c -> 0d13c0b56


ZEPPELIN-2833 JDBC Interpreter doesn't follow JDBC specification when…

… getting the results.

### What is this PR for?

Fix for ZEPPELIN-2833. JDBC Interpreter uses result set next() method after it's already reached the end. According the JDBC documentation that may cause SQL exception.

### What type of PR is it?
Bug Fix

### Todos
None

### What is the Jira issue?

https://issues.apache.org/jira/browse/ZEPPELIN-2833

### How should this be tested?

Use Phoenix 4.7+ select * query for tables that have less than 1000 records. Without patch an exception about closed Result set will be thrown.

### Questions:
* Does the licenses files need update?
No
* Is there breaking changes for older versions?
No
* Does this needs documentation?
No

Author: Sergey Soldatov <ss...@apache.org>

Closes #2520 from ss77892/ZEPPELIN-2833 and squashes the following commits:

fa2e6159d [Sergey Soldatov] ZEPPELIN-2833 JDBC Interpreter doesn't follow JDBC specification when getting the results.


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

Branch: refs/heads/master
Commit: 0d13c0b56f9ef480f596353d2f63980efa10761c
Parents: 184283c
Author: Sergey Soldatov <ss...@apache.org>
Authored: Fri Aug 4 13:06:36 2017 -0700
Committer: Prabhjyot Singh <pr...@gmail.com>
Committed: Tue Sep 26 12:18:16 2017 +0530

----------------------------------------------------------------------
 .../org/apache/zeppelin/jdbc/JDBCInterpreter.java     | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d13c0b5/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
index be24aea..2c5258c 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -38,6 +38,7 @@ import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
 import org.apache.commons.dbcp2.PoolableConnectionFactory;
 import org.apache.commons.dbcp2.PoolingDriver;
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.mutable.MutableBoolean;
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.hadoop.conf.Configuration;
@@ -524,7 +525,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
     return null;
   }
 
-  private String getResults(ResultSet resultSet, boolean isTableType)
+  private String getResults(ResultSet resultSet, boolean isTableType, MutableBoolean isComplete)
       throws SQLException {
     ResultSetMetaData md = resultSet.getMetaData();
     StringBuilder msg;
@@ -543,7 +544,11 @@ public class JDBCInterpreter extends KerberosInterpreter {
     msg.append(NEWLINE);
 
     int displayRowCount = 0;
-    while (displayRowCount < getMaxResult() && resultSet.next()) {
+    while (resultSet.next()) {
+      if (displayRowCount >= getMaxResult()) {
+        isComplete.setValue(false);
+        break;
+      }
       for (int i = 1; i < md.getColumnCount() + 1; i++) {
         Object resultObject;
         String resultValue;
@@ -722,10 +727,11 @@ public class JDBCInterpreter extends KerberosInterpreter {
               interpreterResult.add(InterpreterResult.Type.TEXT,
                   "Query executed successfully.");
             } else {
+              MutableBoolean isComplete = new MutableBoolean(true);
               String results = getResults(resultSet,
-                  !containsIgnoreCase(sqlToExecute, EXPLAIN_PREDICATE));
+                  !containsIgnoreCase(sqlToExecute, EXPLAIN_PREDICATE), isComplete);
               interpreterResult.add(results);
-              if (resultSet.next()) {
+              if (!isComplete.booleanValue()) {
                 interpreterResult.add(ResultMessages.getExceedsLimitRowsMessage(getMaxResult(),
                     String.format("%s.%s", COMMON_KEY, MAX_LINE_KEY)));
               }