You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by jo...@apache.org on 2017/01/08 13:54:32 UTC

zeppelin git commit: [ZEPPELIN-1884] Prevent NullPointerException when JDBC query.

Repository: zeppelin
Updated Branches:
  refs/heads/master bdc0c8ac9 -> 3a12f3032


[ZEPPELIN-1884] Prevent NullPointerException when JDBC query.

### What is this PR for?
Sometimes users don't want to set the properties which they don't want to care about and `common.max_count` of JDBC interpreter is one of that property.
If it does not set the `common.max_count`, NullPointerException will occur.

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

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1884

### How should this be tested?
 - Set properties like as following image and run select query.
![image](https://cloud.githubusercontent.com/assets/3348133/21585284/02c433ee-d072-11e6-8ca1-d120617bb7f1.png)

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

Author: astroshim <hs...@zepl.com>

Closes #1832 from astroshim/ZEPPELIN-1884 and squashes the following commits:

9c20a02 [astroshim] move maxline to open()
f1efda7 [astroshim] add checking commonkey exists


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

Branch: refs/heads/master
Commit: 3a12f3032666334cba931ab152b60b969c8f3541
Parents: bdc0c8a
Author: astroshim <hs...@zepl.com>
Authored: Mon Jan 2 21:53:48 2017 -0800
Committer: Jongyoul Lee <jo...@apache.org>
Committed: Sun Jan 8 22:54:25 2017 +0900

----------------------------------------------------------------------
 .../apache/zeppelin/jdbc/JDBCInterpreter.java    | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3a12f303/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 407e81e..aaf4fc7 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -80,7 +80,7 @@ public class JDBCInterpreter extends Interpreter {
   static final String JDBC_DEFAULT_PASSWORD_KEY = "default.password";
   static final String COMMON_KEY = "common";
   static final String MAX_LINE_KEY = "max_count";
-  static final String MAX_LINE_DEFAULT = "1000";
+  static final int MAX_LINE_DEFAULT = 1000;
 
   static final String DEFAULT_KEY = "default";
   static final String DRIVER_KEY = "driver";
@@ -121,12 +121,14 @@ public class JDBCInterpreter extends Interpreter {
       };
 
   private static final List<InterpreterCompletion> NO_COMPLETION = new ArrayList<>();
+  private int maxLineResults;
 
   public JDBCInterpreter(Properties property) {
     super(property);
     jdbcUserConfigurationsMap = new HashMap<>();
     propertyKeySqlCompleterMap = new HashMap<>();
     basePropretiesMap = new HashMap<>();
+    maxLineResults = MAX_LINE_DEFAULT;
   }
 
   public HashMap<String, Properties> getPropertiesMap() {
@@ -146,9 +148,9 @@ public class JDBCInterpreter extends Interpreter {
           prefixProperties = basePropretiesMap.get(keyValue[0]);
         } else {
           prefixProperties = new Properties();
-          basePropretiesMap.put(keyValue[0], prefixProperties);
+          basePropretiesMap.put(keyValue[0].trim(), prefixProperties);
         }
-        prefixProperties.put(keyValue[1], property.getProperty(propertyKey));
+        prefixProperties.put(keyValue[1].trim(), property.getProperty(propertyKey));
       }
     }
 
@@ -175,6 +177,14 @@ public class JDBCInterpreter extends Interpreter {
     for (String propertyKey : basePropretiesMap.keySet()) {
       propertyKeySqlCompleterMap.put(propertyKey, createSqlCompleter(null));
     }
+    setMaxLineResults();
+  }
+
+  private void setMaxLineResults() {
+    if (basePropretiesMap.containsKey(COMMON_KEY) &&
+        basePropretiesMap.get(COMMON_KEY).containsKey(MAX_LINE_KEY)) {
+      maxLineResults = Integer.valueOf(basePropretiesMap.get(COMMON_KEY).getProperty(MAX_LINE_KEY));
+    }
   }
 
   private SqlCompleter createSqlCompleter(Connection jdbcConnection) {
@@ -600,8 +610,7 @@ public class JDBCInterpreter extends Interpreter {
   }
 
   public int getMaxResult() {
-    return Integer.valueOf(
-        basePropretiesMap.get(COMMON_KEY).getProperty(MAX_LINE_KEY, MAX_LINE_DEFAULT));
+    return maxLineResults;
   }
 
   boolean isConcurrentExecution() {