This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f45fef  [ZEPPELIN-2891]. Impossible to use jdbc interface with 
presto-jdbc >=0.180
8f45fef is described below

commit 8f45fefb1c45ab163bedb94e3d9a9ef8a35afd91
Author: Jeff Zhang <zjf...@apache.org>
AuthorDate: Thu Mar 19 17:53:43 2020 +0800

    [ZEPPELIN-2891]. Impossible to use jdbc interface with presto-jdbc >=0.180
    
    ### What is this PR for?
    
    This PR is to fix the issue of use presto via jdbc interpreter. In this PR, 
I would only add properties that is valid for Presto jdbc driver. I tested it 
manully on the 2 versions of presto: prestodb, prestosql.
    
    ### What type of PR is it?
    [Bug Fix ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-2891
    
    ### How should this be tested?
    * CI pass and manually tested on prestodb and prestosql.
    
    ### Screenshots (if appropriate)
    
![image](https://user-images.githubusercontent.com/164491/77071708-76f11000-6a27-11ea-812d-7396c0e1ebb9.png)
    
    
![image](https://user-images.githubusercontent.com/164491/77071717-7c4e5a80-6a27-11ea-825e-0b86174a30d5.png)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <zjf...@apache.org>
    
    Closes #3694 from zjffdu/ZEPPELIN-2891 and squashes the following commits:
    
    2a77ae297 [Jeff Zhang] [ZEPPELIN-2891]. Impossible to use jdbc interface 
with presto-jdbc >= 0.180
---
 .../org/apache/zeppelin/jdbc/JDBCInterpreter.java  | 81 ++++++++++++++--------
 1 file changed, 51 insertions(+), 30 deletions(-)

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 7d3ff75..3c9907b 100644
--- a/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
+++ b/jdbc/src/main/java/org/apache/zeppelin/jdbc/JDBCInterpreter.java
@@ -141,7 +141,16 @@ public class JDBCInterpreter extends KerberosInterpreter {
   private static final String DBCP_STRING = "jdbc:apache:commons:dbcp:";
   private static final String MAX_ROWS_KEY = "zeppelin.jdbc.maxRows";
 
-  private final HashMap<String, Properties> basePropretiesMap;
+  private static final Set<String> PRESTO_PROPERTIES = new 
HashSet<>(Arrays.asList(
+          "user", "password",
+          "socksProxy", "httpProxy", "clientTags", "applicationNamePrefix", 
"accessToken",
+          "SSL", "SSLKeyStorePath", "SSLKeyStorePassword", "SSLTrustStorePath",
+          "SSLTrustStorePassword", "KerberosRemoteServiceName", 
"KerberosPrincipal",
+          "KerberosUseCanonicalHostname", "KerberosServicePrincipalPattern",
+          "KerberosConfigPath", "KerberosKeytabPath", 
"KerberosCredentialCachePath",
+          "extraCredentials", "roles", "sessionProperties"));
+
+  private final HashMap<String, Properties> basePropertiesMap;
   private final HashMap<String, JDBCUserConfigurations> 
jdbcUserConfigurationsMap;
   private final HashMap<String, SqlCompleter> sqlCompletersMap;
 
@@ -153,7 +162,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
   public JDBCInterpreter(Properties property) {
     super(property);
     jdbcUserConfigurationsMap = new HashMap<>();
-    basePropretiesMap = new HashMap<>();
+    basePropertiesMap = new HashMap<>();
     sqlCompletersMap = new HashMap<>();
     maxLineResults = MAX_LINE_DEFAULT;
   }
@@ -180,7 +189,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
   }
 
   public HashMap<String, Properties> getPropertiesMap() {
-    return basePropretiesMap;
+    return basePropertiesMap;
   }
 
   @Override
@@ -193,20 +202,20 @@ public class JDBCInterpreter extends KerberosInterpreter {
         logger.debug("key: {}, value: {}", keyValue[0], keyValue[1]);
 
         Properties prefixProperties;
-        if (basePropretiesMap.containsKey(keyValue[0])) {
-          prefixProperties = basePropretiesMap.get(keyValue[0]);
+        if (basePropertiesMap.containsKey(keyValue[0])) {
+          prefixProperties = basePropertiesMap.get(keyValue[0]);
         } else {
           prefixProperties = new Properties();
-          basePropretiesMap.put(keyValue[0].trim(), prefixProperties);
+          basePropertiesMap.put(keyValue[0].trim(), prefixProperties);
         }
         prefixProperties.put(keyValue[1].trim(), getProperty(propertyKey));
       }
     }
 
     Set<String> removeKeySet = new HashSet<>();
-    for (String key : basePropretiesMap.keySet()) {
+    for (String key : basePropertiesMap.keySet()) {
       if (!COMMON_KEY.equals(key)) {
-        Properties properties = basePropretiesMap.get(key);
+        Properties properties = basePropertiesMap.get(key);
         if (!properties.containsKey(DRIVER_KEY) || 
!properties.containsKey(URL_KEY)) {
           logger.error("{} will be ignored. {}.{} and {}.{} is mandatory.",
               key, DRIVER_KEY, key, key, URL_KEY);
@@ -216,9 +225,9 @@ public class JDBCInterpreter extends KerberosInterpreter {
     }
 
     for (String key : removeKeySet) {
-      basePropretiesMap.remove(key);
+      basePropertiesMap.remove(key);
     }
-    logger.debug("JDBC PropretiesMap: {}", basePropretiesMap);
+    logger.debug("JDBC PropretiesMap: {}", basePropertiesMap);
 
     setMaxLineResults();
     setMaxRows();
@@ -238,9 +247,9 @@ public class JDBCInterpreter extends KerberosInterpreter {
   }
 
   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));
+    if (basePropertiesMap.containsKey(COMMON_KEY) &&
+        basePropertiesMap.get(COMMON_KEY).containsKey(MAX_LINE_KEY)) {
+      maxLineResults = 
Integer.valueOf(basePropertiesMap.get(COMMON_KEY).getProperty(MAX_LINE_KEY));
     }
   }
 
@@ -346,9 +355,9 @@ public class JDBCInterpreter extends KerberosInterpreter {
   }
 
   private boolean existAccountInBaseProperty(String propertyKey) {
-    return basePropretiesMap.get(propertyKey).containsKey(USER_KEY) &&
-        !isEmpty((String) basePropretiesMap.get(propertyKey).get(USER_KEY)) &&
-        basePropretiesMap.get(propertyKey).containsKey(PASSWORD_KEY);
+    return basePropertiesMap.get(propertyKey).containsKey(USER_KEY) &&
+        !isEmpty((String) basePropertiesMap.get(propertyKey).get(USER_KEY)) &&
+        basePropertiesMap.get(propertyKey).containsKey(PASSWORD_KEY);
   }
 
   private UsernamePassword getUsernamePassword(InterpreterContext 
interpreterContext,
@@ -384,14 +393,14 @@ public class JDBCInterpreter extends KerberosInterpreter {
     String user = interpreterContext.getAuthenticationInfo().getUser();
 
     JDBCUserConfigurations jdbcUserConfigurations = getJDBCConfiguration(user);
-    if (basePropretiesMap.get(propertyKey).containsKey(USER_KEY) &&
-        !basePropretiesMap.get(propertyKey).getProperty(USER_KEY).isEmpty()) {
-      String password = getPassword(basePropretiesMap.get(propertyKey));
+    if (basePropertiesMap.get(propertyKey).containsKey(USER_KEY) &&
+        !basePropertiesMap.get(propertyKey).getProperty(USER_KEY).isEmpty()) {
+      String password = getPassword(basePropertiesMap.get(propertyKey));
       if (!isEmpty(password)) {
-        basePropretiesMap.get(propertyKey).setProperty(PASSWORD_KEY, password);
+        basePropertiesMap.get(propertyKey).setProperty(PASSWORD_KEY, password);
       }
     }
-    jdbcUserConfigurations.setPropertyMap(propertyKey, 
basePropretiesMap.get(propertyKey));
+    jdbcUserConfigurations.setPropertyMap(propertyKey, 
basePropertiesMap.get(propertyKey));
     if (existAccountInBaseProperty(propertyKey)) {
       return;
     }
@@ -407,7 +416,19 @@ public class JDBCInterpreter extends KerberosInterpreter {
   }
 
   private void createConnectionPool(String url, String user, String 
propertyKey,
-      Properties properties) throws SQLException, ClassNotFoundException {
+      Properties properties) throws SQLException, ClassNotFoundException, 
IOException {
+
+    String driverClass = properties.getProperty(DRIVER_KEY);
+    if (driverClass != null && 
(driverClass.equals("com.facebook.presto.jdbc.PrestoDriver")
+            || driverClass.equals("io.prestosql.jdbc.PrestoDriver"))) {
+      // Only add valid properties otherwise presto won't work.
+      for (Object key : properties.keySet()) {
+        if (!PRESTO_PROPERTIES.contains(key.toString())) {
+          properties.remove(key);
+        }
+      }
+    }
+
     ConnectionFactory connectionFactory =
             new DriverManagerConnectionFactory(url, properties);
 
@@ -420,14 +441,14 @@ public class JDBCInterpreter extends KerberosInterpreter {
     ObjectPool connectionPool = new 
GenericObjectPool(poolableConnectionFactory);
 
     poolableConnectionFactory.setPool(connectionPool);
-    Class.forName(properties.getProperty(DRIVER_KEY));
+    Class.forName(driverClass);
     PoolingDriver driver = new PoolingDriver();
     driver.registerPool(propertyKey + user, connectionPool);
     getJDBCConfiguration(user).saveDBDriverPool(propertyKey, driver);
   }
 
   private Connection getConnectionFromPool(String url, String user, String 
propertyKey,
-      Properties properties) throws SQLException, ClassNotFoundException {
+      Properties properties) throws SQLException, ClassNotFoundException, 
IOException {
     String jdbcDriver = getJDBCDriverName(user, propertyKey);
 
     if (!getJDBCConfiguration(user).isConnectionInDBDriverPool(propertyKey)) {
@@ -440,7 +461,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
       throws ClassNotFoundException, SQLException, InterpreterException, 
IOException {
     final String user =  interpreterContext.getAuthenticationInfo().getUser();
     Connection connection;
-    if (propertyKey == null || basePropretiesMap.get(propertyKey) == null) {
+    if (propertyKey == null || basePropertiesMap.get(propertyKey) == null) {
       return null;
     }
 
@@ -465,7 +486,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
               getProperty("zeppelin.jdbc.auth.kerberos.proxy.enable"))) {
             connection = getConnectionFromPool(connectionUrl, user, 
propertyKey, properties);
           } else {
-            if 
(basePropretiesMap.get(propertyKey).containsKey("proxy.user.property")) {
+            if 
(basePropertiesMap.get(propertyKey).containsKey("proxy.user.property")) {
               connection = getConnectionFromPool(connectionUrl, user, 
propertyKey, properties);
             } else {
               UserGroupInformation ugi = null;
@@ -505,7 +526,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
     StringBuilder connectionUrl = new StringBuilder(url);
 
     if (user != null && !user.equals("anonymous") &&
-        basePropretiesMap.get(propertyKey).containsKey("proxy.user.property")) 
{
+        basePropertiesMap.get(propertyKey).containsKey("proxy.user.property")) 
{
 
       Integer lastIndexOfUrl = connectionUrl.indexOf("?");
       if (lastIndexOfUrl == -1) {
@@ -513,9 +534,9 @@ public class JDBCInterpreter extends KerberosInterpreter {
       }
       logger.info("Using proxy user as :" + user);
       logger.info("Using proxy property for user as :" +
-          
basePropretiesMap.get(propertyKey).getProperty("proxy.user.property"));
+          
basePropertiesMap.get(propertyKey).getProperty("proxy.user.property"));
       connectionUrl.insert(lastIndexOfUrl, ";" +
-          
basePropretiesMap.get(propertyKey).getProperty("proxy.user.property") + "=" + 
user + ";");
+          
basePropertiesMap.get(propertyKey).getProperty("proxy.user.property") + "=" + 
user + ";");
     } else if (user != null && !user.equals("anonymous") && 
url.contains("hive")) {
       logger.warn("User impersonation for hive has changed please refer: 
http://zeppelin.apache"; +
           ".org/docs/latest/interpreter/jdbc.html#apache-hive");
@@ -608,7 +629,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
 
   public InterpreterResult executePrecode(InterpreterContext 
interpreterContext) {
     InterpreterResult interpreterResult = null;
-    for (String propertyKey : basePropretiesMap.keySet()) {
+    for (String propertyKey : basePropertiesMap.keySet()) {
       String precode = getProperty(String.format("%s.precode", propertyKey));
       if (StringUtils.isNotBlank(precode)) {
         interpreterResult = executeSql(propertyKey, precode, 
interpreterContext);

Reply via email to