Bläddra i källkod

PR800 [notebook] Add JDBC Assist for Presto (#800)

* Add JDBC Assist for Presto

* Add missing new line at the end of the file

* Commented example of Presto usage

* Note about Presto in user guide
Grzegorz Kokosiński 6 år sedan
förälder
incheckning
2c5dcb5

+ 7 - 0
desktop/conf.dist/hue.ini

@@ -927,6 +927,13 @@
     #   ## Option 'impersonation_property' used to configure outbound impersonation, e.g. "impersonation_property": "hive.server2.proxy.user".
     #   options='{"url": "jdbc:mysql://localhost:3306/hue", "driver": "com.mysql.jdbc.Driver", "user": "root", "password": "root", "impersonation_property": ""}'
 
+    # [[[presto]]]
+    #   name=Presto SQL
+    #   interface=presto
+    #   ## Specific options for connecting to the Presto server.
+    #   ## The JDBC driver presto-jdbc.jar need to be in the CLASSPATH environment variable.
+    #   ## If 'user' and 'password' are omitted, they will be prompted in the UI.
+    #   options='{"url": "jdbc:presto://localhost:8080/catalog/schema", "driver": "io.prestosql.jdbc.PrestoDriver", "user": "root", "password": "root"}'
 
 ###########################################################################
 # Settings to configure your Analytics Dashboards

+ 7 - 1
desktop/conf/pseudo-distributed.ini.tmpl

@@ -928,7 +928,13 @@
     #   ## If 'user' and 'password' are omitted, they will be prompted in the UI.
     #   ## Option 'impersonation_property' used to configure outbound impersonation, e.g. "impersonation_property": "hive.server2.proxy.user".
     #   options='{"url": "jdbc:mysql://localhost:3306/hue", "driver": "com.mysql.jdbc.Driver", "user": "root", "password": "root", "impersonation_property": ""}'
-
+    # [[[presto]]]
+    #   name=Presto SQL
+    #   interface=presto
+    #   ## Specific options for connecting to the Presto server.
+    #   ## The JDBC driver presto-jdbc.jar need to be in the CLASSPATH environment variable.
+    #   ## If 'user' and 'password' are omitted, they will be prompted in the UI.
+    #   options='{"url": "jdbc:presto://localhost:8080/catalog/schema", "driver": "io.prestosql.jdbc.PrestoDriver", "user": "root", "password": "root"}'
 
 ###########################################################################
 # Settings to configure your Analytics Dashboards

+ 10 - 4
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -359,15 +359,21 @@ def get_api(request, snippet):
     from notebook.connectors.dataeng import DataEngApi
     return DataEngApi(user=request.user, request=request, cluster_name=cluster_name)
   elif interface == 'jdbc':
-    if not interpreter['options'] or interpreter['options'].get('url', '').find('teradata') < 0:
-      from notebook.connectors.jdbc import JdbcApi
-      return JdbcApi(request.user, interpreter=interpreter)
-    else:
+    if interpreter['options'] and interpreter['options'].get('url', '').find('teradata') >= 0:
       from notebook.connectors.jdbc_teradata import JdbcApiTeradata
       return JdbcApiTeradata(request.user, interpreter=interpreter)
+    elif interpreter['options'] and interpreter['options'].get('url', '').find('presto') >= 0:
+      from notebook.connectors.jdbc_presto import JdbcApiPresto
+      return JdbcApiPresto(request.user, interpreter=interpreter)
+    else:
+      from notebook.connectors.jdbc import JdbcApi
+      return JdbcApi(request.user, interpreter=interpreter)
   elif interface == 'teradata':
     from notebook.connectors.jdbc import JdbcApiTeradata
     return JdbcApiTeradata(request.user, interpreter=interpreter)
+  elif interface == 'presto':
+    from notebook.connectors.jdbc_presto import JdbcApiPresto
+    return JdbcApiPresto(request.user, interpreter=interpreter)
   elif interface == 'sqlalchemy':
     from notebook.connectors.sqlalchemyapi import SqlAlchemyApi
     return SqlAlchemyApi(request.user, interpreter=interpreter)

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/jdbc.py

@@ -218,4 +218,4 @@ class Assist():
     #data, description =  query_and_fetch(self.db, 'SELECT %s FROM %s.%s limit 100' % (column, database, table))
     #response['rows'] = data
     #response['columns'] = []
-    return query_and_fetch(self.db, 'SELECT %s FROM %s.%s limit 100' % (column, database, table))
+    return query_and_fetch(self.db, 'SELECT %s FROM %s.%s limit 100' % (column, database, table))

+ 36 - 0
desktop/libs/notebook/src/notebook/connectors/jdbc_presto.py

@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from librdbms.jdbc import query_and_fetch
+
+from notebook.connectors.jdbc import JdbcApi
+from notebook.connectors.jdbc import Assist
+
+class JdbcApiPresto(JdbcApi):
+
+  def _createAssist(self, db):
+    return PrestoAssist(db)
+
+class PrestoAssist(Assist):
+
+  def get_tables_full(self, database, table_names=[]):
+    tables, description = query_and_fetch(self.db, "SELECT TABLE_NAME, null AS TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='%s'" % database)
+    return [{"comment": table[1] and table[1].strip(), "type": "Table", "name": table[0] and table[0].strip()} for table in tables]
+
+  def get_columns_full(self, database, table):
+    columns, description = query_and_fetch(self.db, "SELECT COLUMN_NAME, DATA_TYPE, COMMENT AS COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='%s'" % (database, table))
+    return [{"comment": col[2] and col[2].strip(), "type": col[1], "name": col[0] and col[0].strip()} for col in columns]

+ 5 - 0
docs/user-guide/user-guide.md

@@ -490,6 +490,11 @@ As Solr SQL is pretty recent, there are some caveats, notably Solr lacks support
 which prevents a SQL UX experience comparable to the standard other databases (but we track it in [HUE-3686](https://issues.cloudera.org/browse/HUE-3686)).
 
 ### Presto
+
+Presto is a high performance, distributed SQL query engine for big data.
+
+[Read more about it here](https://prestosql.io/)
+
 ### PostgreSQL
 ### Redshift
 ### BigQuery