Преглед на файлове

HUE-9077 [ksql] Implementing the autocomplete piece of the Editor API

Romain преди 6 години
родител
ревизия
758ca0d23b

+ 6 - 6
desktop/libs/kafka/src/kafka/ksql_client.py

@@ -24,9 +24,9 @@ from django.core.cache import cache
 from django.utils.translation import ugettext as _
 
 from desktop.lib.i18n import smart_unicode
+from desktop.lib.rest.http_client import RestException
 
 from kafka.conf import KAFKA
-from libzookeeper.conf import zkensemble
 
 
 LOG = logging.getLogger(__name__)
@@ -64,16 +64,16 @@ class KSqlApi(object):
 
   def show_tables(self):
     try:
-      response = self._client.ksql('show tables')
-      return json.loads(response)['tables']['tables']
-    except RestException as e:
-      raise KafkaApiException(e)
+      response = self.client.ksql('SHOW TABLES')
+      return response[0]['tables']
+    except Exception as e:
+      raise KSqlApiException(e)
 
 
   def query(self, statement):
     result = []
 
-    for line in self._client.query(statement):
+    for line in self.client.query(statement):
       data_line = json.loads(line)
       result.append(data_line['row']['columns']) # TODO: streams, dataline['errorMessage']
 

+ 1 - 1
desktop/libs/notebook/src/notebook/conf.py

@@ -96,7 +96,7 @@ def get_ordered_interpreters(user=None):
       "options": i['options'],
       'dialect': i.get('dialect', i['name']).lower(),
       'category': i.get('category', 'editor'),
-      "is_sql": i.get('is_sql') or i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy"],
+      "is_sql": i.get('is_sql') or i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy", "ksql"],
       "is_catalog": i['interface'] in ["hms",],
     }
     for i in interpreters

+ 6 - 48
desktop/libs/notebook/src/notebook/connectors/ksql.py

@@ -23,7 +23,7 @@ from django.core.urlresolvers import reverse
 from django.utils.translation import ugettext as _
 
 from desktop.lib.i18n import force_unicode
-from kafka.ksql_client import KSqlApi
+from kafka.ksql_client import KSqlApi as KSqlClientApi
 
 from notebook.connectors.base import Api, QueryError
 
@@ -41,19 +41,16 @@ def query_error_handler(func):
   return decorator
 
 
-class KafkaApi(Api):
+class KSqlApi(Api):
 
   def __init__(self, user, interpreter=None):
     Api.__init__(self, user, interpreter=interpreter)
 
-    self.db = KSqlApi(user=user)
+    self.db = KSqlClientApi(user=user)
 
 
   @query_error_handler
   def execute(self, notebook, snippet):
-    if self.db is None:
-      raise AuthenticationRequired()
-
     data, description = query_and_fetch(self.db, snippet['statement'], 1000)
     has_result_set = data is not None
 
@@ -72,10 +69,12 @@ class KafkaApi(Api):
       }
     }
 
+
   @query_error_handler
   def check_status(self, notebook, snippet):
     return {'status': 'available'}
 
+
   @query_error_handler
   def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
     response = {}
@@ -86,48 +85,7 @@ class KafkaApi(Api):
       elif table is None:
         response['tables_meta'] = self.db.show_tables()
       else:
-        response = {
-          u'status': 0,
-          u'comment': u'test test test 22',
-          u'hdfs_link': u'/filebrowser/view=/user/hive/warehouse/web_logs',
-          u'extended_columns': [
-            {u'comment': u'', u'type': u'bigint', u'name': u'_version_'},
-            {u'comment': u'The app', u'type': u'string', u'name': u'app'},
-            {u'comment': u'test test   test 22', u'type': u'smallint', u'name': u'bytes'},
-            {u'comment': u'The citi', u'type': u'string', u'name': u'city'},
-            {u'comment': u'', u'type': u'string', u'name': u'client_ip'},
-            {u'comment': u'', u'type': u'tinyint', u'name': u'code'},
-            {u'comment': u'', u'type': u'string', u'name': u'country_code'},
-            {u'comment': u'', u'type': u'string', u'name': u'country_code3'},
-            {u'comment': u'', u'type': u'string', u'name': u'country_name'},
-            {u'comment': u'', u'type': u'string', u'name': u'device_family'},
-            {u'comment': u'', u'type': u'string', u'name': u'extension'},
-            {u'comment': u'', u'type': u'float', u'name': u'latitude'},
-            {u'comment': u'', u'type': u'float', u'name': u'longitude'},
-            {u'comment': u'', u'type': u'string', u'name': u'method'},
-            {u'comment': u'', u'type': u'string', u'name': u'os_family'},
-            {u'comment': u'', u'type': u'string', u'name': u'os_major'},
-            {u'comment': u'', u'type': u'string', u'name': u'protocol'},
-            {u'comment': u'', u'type': u'string', u'name': u'record'},
-            {u'comment': u'', u'type': u'string', u'name': u'referer'},
-            {u'comment': u'', u'type': u'bigint', u'name': u'region_code'},
-            {u'comment': u'', u'type': u'string', u'name': u'request'},
-            {u'comment': u'', u'type': u'string', u'name': u'subapp'},
-            {u'comment': u'', u'type': u'string', u'name': u'time'},
-            {u'comment': u'', u'type': u'string', u'name': u'url'},
-            {u'comment': u'', u'type': u'string', u'name': u'user_agent'},
-            {u'comment': u'', u'type': u'string', u'name': u'user_agent_family'},
-            {u'comment': u'', u'type': u'string', u'name': u'user_agent_major'},
-            {u'comment': u'', u'type': u'string', u'name': u'id'},
-            {u'comment': u'', u'type': u'string', u'name': u'date'}
-          ],
-          u'support_updates': False,
-          u'partition_keys': [
-            {u'type': u'string', u'name': u'date'}
-          ],
-          u'columns': [u'_version_', u'app', u'bytes', u'city', u'client_ip', u'code', u'country_code', u'country_code3', u'country_name', u'device_family', u'extension', u'latitude', u'longitude', u'method', u'os_family', u'os_major', u'protocol', u'record', u'referer', u'region_code', u'request', u'subapp', u'time', u'url', u'user_agent', u'user_agent_family', u'user_agent_major', u'id', u'date'],
-          u'is_view': False
-        }
+        response = {}
 
     except Exception as e:
       LOG.warn('Autocomplete data fetching error: %s' % e)