فهرست منبع

HUE-8745 [editor] Support AWS Athena using JDBC Driver

Santiago Ciciliani 6 سال پیش
والد
کامیت
99fc7b2142

+ 6 - 0
desktop/libs/notebook/src/notebook/connectors/base.py

@@ -378,6 +378,9 @@ def get_api(request, snippet):
     if interpreter['options'] and interpreter['options'].get('url', '').find('teradata') >= 0:
       from notebook.connectors.jdbc_teradata import JdbcApiTeradata
       return JdbcApiTeradata(request.user, interpreter=interpreter)
+    if interpreter['options'] and interpreter['options'].get('url', '').find('awsathena') >= 0:
+      from notebook.connectors.jdbc_athena import JdbcApiAthena
+      return JdbcApiAthena(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)
@@ -390,6 +393,9 @@ def get_api(request, snippet):
   elif interface == 'teradata':
     from notebook.connectors.jdbc import JdbcApiTeradata
     return JdbcApiTeradata(request.user, interpreter=interpreter)
+  elif interface == 'athena':
+    from notebook.connectors.jdbc import JdbcApiAthena
+    return JdbcApiAthena(request.user, interpreter=interpreter)
   elif interface == 'presto':
     from notebook.connectors.jdbc_presto import JdbcApiPresto
     return JdbcApiPresto(request.user, interpreter=interpreter)

+ 36 - 0
desktop/libs/notebook/src/notebook/connectors/jdbc_athena.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 JdbcApiAthena(JdbcApi):
+
+  def _createAssist(self, db):
+    return AthenaAssist(db)
+
+class AthenaAssist(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]