@@ -141,7 +141,16 @@ public class JDBCInterpreter extends KerberosInterpreter {
141141 private static final String DBCP_STRING = "jdbc:apache:commons:dbcp:" ;
142142 private static final String MAX_ROWS_KEY = "zeppelin.jdbc.maxRows" ;
143143
144- private final HashMap <String , Properties > basePropretiesMap ;
144+ private static final Set <String > PRESTO_PROPERTIES = new HashSet <>(Arrays .asList (
145+ "user" , "password" ,
146+ "socksProxy" , "httpProxy" , "clientTags" , "applicationNamePrefix" , "accessToken" ,
147+ "SSL" , "SSLKeyStorePath" , "SSLKeyStorePassword" , "SSLTrustStorePath" ,
148+ "SSLTrustStorePassword" , "KerberosRemoteServiceName" , "KerberosPrincipal" ,
149+ "KerberosUseCanonicalHostname" , "KerberosServicePrincipalPattern" ,
150+ "KerberosConfigPath" , "KerberosKeytabPath" , "KerberosCredentialCachePath" ,
151+ "extraCredentials" , "roles" , "sessionProperties" ));
152+
153+ private final HashMap <String , Properties > basePropertiesMap ;
145154 private final HashMap <String , JDBCUserConfigurations > jdbcUserConfigurationsMap ;
146155 private final HashMap <String , SqlCompleter > sqlCompletersMap ;
147156
@@ -153,7 +162,7 @@ public class JDBCInterpreter extends KerberosInterpreter {
153162 public JDBCInterpreter (Properties property ) {
154163 super (property );
155164 jdbcUserConfigurationsMap = new HashMap <>();
156- basePropretiesMap = new HashMap <>();
165+ basePropertiesMap = new HashMap <>();
157166 sqlCompletersMap = new HashMap <>();
158167 maxLineResults = MAX_LINE_DEFAULT ;
159168 }
@@ -180,7 +189,7 @@ protected boolean runKerberosLogin() {
180189 }
181190
182191 public HashMap <String , Properties > getPropertiesMap () {
183- return basePropretiesMap ;
192+ return basePropertiesMap ;
184193 }
185194
186195 @ Override
@@ -193,20 +202,20 @@ public void open() {
193202 logger .debug ("key: {}, value: {}" , keyValue [0 ], keyValue [1 ]);
194203
195204 Properties prefixProperties ;
196- if (basePropretiesMap .containsKey (keyValue [0 ])) {
197- prefixProperties = basePropretiesMap .get (keyValue [0 ]);
205+ if (basePropertiesMap .containsKey (keyValue [0 ])) {
206+ prefixProperties = basePropertiesMap .get (keyValue [0 ]);
198207 } else {
199208 prefixProperties = new Properties ();
200- basePropretiesMap .put (keyValue [0 ].trim (), prefixProperties );
209+ basePropertiesMap .put (keyValue [0 ].trim (), prefixProperties );
201210 }
202211 prefixProperties .put (keyValue [1 ].trim (), getProperty (propertyKey ));
203212 }
204213 }
205214
206215 Set <String > removeKeySet = new HashSet <>();
207- for (String key : basePropretiesMap .keySet ()) {
216+ for (String key : basePropertiesMap .keySet ()) {
208217 if (!COMMON_KEY .equals (key )) {
209- Properties properties = basePropretiesMap .get (key );
218+ Properties properties = basePropertiesMap .get (key );
210219 if (!properties .containsKey (DRIVER_KEY ) || !properties .containsKey (URL_KEY )) {
211220 logger .error ("{} will be ignored. {}.{} and {}.{} is mandatory." ,
212221 key , DRIVER_KEY , key , key , URL_KEY );
@@ -216,9 +225,9 @@ public void open() {
216225 }
217226
218227 for (String key : removeKeySet ) {
219- basePropretiesMap .remove (key );
228+ basePropertiesMap .remove (key );
220229 }
221- logger .debug ("JDBC PropretiesMap: {}" , basePropretiesMap );
230+ logger .debug ("JDBC PropretiesMap: {}" , basePropertiesMap );
222231
223232 setMaxLineResults ();
224233 setMaxRows ();
@@ -238,9 +247,9 @@ protected boolean isKerboseEnabled() {
238247 }
239248
240249 private void setMaxLineResults () {
241- if (basePropretiesMap .containsKey (COMMON_KEY ) &&
242- basePropretiesMap .get (COMMON_KEY ).containsKey (MAX_LINE_KEY )) {
243- maxLineResults = Integer .valueOf (basePropretiesMap .get (COMMON_KEY ).getProperty (MAX_LINE_KEY ));
250+ if (basePropertiesMap .containsKey (COMMON_KEY ) &&
251+ basePropertiesMap .get (COMMON_KEY ).containsKey (MAX_LINE_KEY )) {
252+ maxLineResults = Integer .valueOf (basePropertiesMap .get (COMMON_KEY ).getProperty (MAX_LINE_KEY ));
244253 }
245254 }
246255
@@ -346,9 +355,9 @@ private String getJDBCDriverName(String user, String propertyKey) {
346355 }
347356
348357 private boolean existAccountInBaseProperty (String propertyKey ) {
349- return basePropretiesMap .get (propertyKey ).containsKey (USER_KEY ) &&
350- !isEmpty ((String ) basePropretiesMap .get (propertyKey ).get (USER_KEY )) &&
351- basePropretiesMap .get (propertyKey ).containsKey (PASSWORD_KEY );
358+ return basePropertiesMap .get (propertyKey ).containsKey (USER_KEY ) &&
359+ !isEmpty ((String ) basePropertiesMap .get (propertyKey ).get (USER_KEY )) &&
360+ basePropertiesMap .get (propertyKey ).containsKey (PASSWORD_KEY );
352361 }
353362
354363 private UsernamePassword getUsernamePassword (InterpreterContext interpreterContext ,
@@ -384,14 +393,14 @@ private void setUserProperty(String propertyKey, InterpreterContext interpreterC
384393 String user = interpreterContext .getAuthenticationInfo ().getUser ();
385394
386395 JDBCUserConfigurations jdbcUserConfigurations = getJDBCConfiguration (user );
387- if (basePropretiesMap .get (propertyKey ).containsKey (USER_KEY ) &&
388- !basePropretiesMap .get (propertyKey ).getProperty (USER_KEY ).isEmpty ()) {
389- String password = getPassword (basePropretiesMap .get (propertyKey ));
396+ if (basePropertiesMap .get (propertyKey ).containsKey (USER_KEY ) &&
397+ !basePropertiesMap .get (propertyKey ).getProperty (USER_KEY ).isEmpty ()) {
398+ String password = getPassword (basePropertiesMap .get (propertyKey ));
390399 if (!isEmpty (password )) {
391- basePropretiesMap .get (propertyKey ).setProperty (PASSWORD_KEY , password );
400+ basePropertiesMap .get (propertyKey ).setProperty (PASSWORD_KEY , password );
392401 }
393402 }
394- jdbcUserConfigurations .setPropertyMap (propertyKey , basePropretiesMap .get (propertyKey ));
403+ jdbcUserConfigurations .setPropertyMap (propertyKey , basePropertiesMap .get (propertyKey ));
395404 if (existAccountInBaseProperty (propertyKey )) {
396405 return ;
397406 }
@@ -407,7 +416,19 @@ private void setUserProperty(String propertyKey, InterpreterContext interpreterC
407416 }
408417
409418 private void createConnectionPool (String url , String user , String propertyKey ,
410- Properties properties ) throws SQLException , ClassNotFoundException {
419+ Properties properties ) throws SQLException , ClassNotFoundException , IOException {
420+
421+ String driverClass = properties .getProperty (DRIVER_KEY );
422+ if (driverClass != null && (driverClass .equals ("com.facebook.presto.jdbc.PrestoDriver" )
423+ || driverClass .equals ("io.prestosql.jdbc.PrestoDriver" ))) {
424+ // Only add valid properties otherwise presto won't work.
425+ for (Object key : properties .keySet ()) {
426+ if (!PRESTO_PROPERTIES .contains (key .toString ())) {
427+ properties .remove (key );
428+ }
429+ }
430+ }
431+
411432 ConnectionFactory connectionFactory =
412433 new DriverManagerConnectionFactory (url , properties );
413434
@@ -420,14 +441,14 @@ private void createConnectionPool(String url, String user, String propertyKey,
420441 ObjectPool connectionPool = new GenericObjectPool (poolableConnectionFactory );
421442
422443 poolableConnectionFactory .setPool (connectionPool );
423- Class .forName (properties . getProperty ( DRIVER_KEY ) );
444+ Class .forName (driverClass );
424445 PoolingDriver driver = new PoolingDriver ();
425446 driver .registerPool (propertyKey + user , connectionPool );
426447 getJDBCConfiguration (user ).saveDBDriverPool (propertyKey , driver );
427448 }
428449
429450 private Connection getConnectionFromPool (String url , String user , String propertyKey ,
430- Properties properties ) throws SQLException , ClassNotFoundException {
451+ Properties properties ) throws SQLException , ClassNotFoundException , IOException {
431452 String jdbcDriver = getJDBCDriverName (user , propertyKey );
432453
433454 if (!getJDBCConfiguration (user ).isConnectionInDBDriverPool (propertyKey )) {
@@ -440,7 +461,7 @@ public Connection getConnection(String propertyKey, InterpreterContext interpret
440461 throws ClassNotFoundException , SQLException , InterpreterException , IOException {
441462 final String user = interpreterContext .getAuthenticationInfo ().getUser ();
442463 Connection connection ;
443- if (propertyKey == null || basePropretiesMap .get (propertyKey ) == null ) {
464+ if (propertyKey == null || basePropertiesMap .get (propertyKey ) == null ) {
444465 return null ;
445466 }
446467
@@ -465,7 +486,7 @@ public Connection getConnection(String propertyKey, InterpreterContext interpret
465486 getProperty ("zeppelin.jdbc.auth.kerberos.proxy.enable" ))) {
466487 connection = getConnectionFromPool (connectionUrl , user , propertyKey , properties );
467488 } else {
468- if (basePropretiesMap .get (propertyKey ).containsKey ("proxy.user.property" )) {
489+ if (basePropertiesMap .get (propertyKey ).containsKey ("proxy.user.property" )) {
469490 connection = getConnectionFromPool (connectionUrl , user , propertyKey , properties );
470491 } else {
471492 UserGroupInformation ugi = null ;
@@ -505,17 +526,17 @@ private String appendProxyUserToURL(String url, String user, String propertyKey)
505526 StringBuilder connectionUrl = new StringBuilder (url );
506527
507528 if (user != null && !user .equals ("anonymous" ) &&
508- basePropretiesMap .get (propertyKey ).containsKey ("proxy.user.property" )) {
529+ basePropertiesMap .get (propertyKey ).containsKey ("proxy.user.property" )) {
509530
510531 Integer lastIndexOfUrl = connectionUrl .indexOf ("?" );
511532 if (lastIndexOfUrl == -1 ) {
512533 lastIndexOfUrl = connectionUrl .length ();
513534 }
514535 logger .info ("Using proxy user as :" + user );
515536 logger .info ("Using proxy property for user as :" +
516- basePropretiesMap .get (propertyKey ).getProperty ("proxy.user.property" ));
537+ basePropertiesMap .get (propertyKey ).getProperty ("proxy.user.property" ));
517538 connectionUrl .insert (lastIndexOfUrl , ";" +
518- basePropretiesMap .get (propertyKey ).getProperty ("proxy.user.property" ) + "=" + user + ";" );
539+ basePropertiesMap .get (propertyKey ).getProperty ("proxy.user.property" ) + "=" + user + ";" );
519540 } else if (user != null && !user .equals ("anonymous" ) && url .contains ("hive" )) {
520541 logger .warn ("User impersonation for hive has changed please refer: http://zeppelin.apache" +
521542 ".org/docs/latest/interpreter/jdbc.html#apache-hive" );
@@ -608,7 +629,7 @@ private boolean isDDLCommand(int updatedCount, int columnCount) throws SQLExcept
608629
609630 public InterpreterResult executePrecode (InterpreterContext interpreterContext ) {
610631 InterpreterResult interpreterResult = null ;
611- for (String propertyKey : basePropretiesMap .keySet ()) {
632+ for (String propertyKey : basePropertiesMap .keySet ()) {
612633 String precode = getProperty (String .format ("%s.precode" , propertyKey ));
613634 if (StringUtils .isNotBlank (precode )) {
614635 interpreterResult = executeSql (propertyKey , precode , interpreterContext );
0 commit comments