|
@@ -23,7 +23,7 @@ from django.core.urlresolvers import reverse
|
|
|
from django.utils.translation import ugettext as _
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from desktop.lib.i18n import force_unicode
|
|
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
|
|
from notebook.connectors.base import Api, QueryError
|
|
|
|
|
|
|
@@ -41,19 +41,16 @@ def query_error_handler(func):
|
|
|
return decorator
|
|
return decorator
|
|
|
|
|
|
|
|
|
|
|
|
|
-class KafkaApi(Api):
|
|
|
|
|
|
|
+class KSqlApi(Api):
|
|
|
|
|
|
|
|
def __init__(self, user, interpreter=None):
|
|
def __init__(self, user, interpreter=None):
|
|
|
Api.__init__(self, user, interpreter=interpreter)
|
|
Api.__init__(self, user, interpreter=interpreter)
|
|
|
|
|
|
|
|
- self.db = KSqlApi(user=user)
|
|
|
|
|
|
|
+ self.db = KSqlClientApi(user=user)
|
|
|
|
|
|
|
|
|
|
|
|
|
@query_error_handler
|
|
@query_error_handler
|
|
|
def execute(self, notebook, snippet):
|
|
def execute(self, notebook, snippet):
|
|
|
- if self.db is None:
|
|
|
|
|
- raise AuthenticationRequired()
|
|
|
|
|
-
|
|
|
|
|
data, description = query_and_fetch(self.db, snippet['statement'], 1000)
|
|
data, description = query_and_fetch(self.db, snippet['statement'], 1000)
|
|
|
has_result_set = data is not None
|
|
has_result_set = data is not None
|
|
|
|
|
|
|
@@ -72,10 +69,12 @@ class KafkaApi(Api):
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@query_error_handler
|
|
@query_error_handler
|
|
|
def check_status(self, notebook, snippet):
|
|
def check_status(self, notebook, snippet):
|
|
|
return {'status': 'available'}
|
|
return {'status': 'available'}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@query_error_handler
|
|
@query_error_handler
|
|
|
def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
|
|
def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
|
|
|
response = {}
|
|
response = {}
|
|
@@ -86,48 +85,7 @@ class KafkaApi(Api):
|
|
|
elif table is None:
|
|
elif table is None:
|
|
|
response['tables_meta'] = self.db.show_tables()
|
|
response['tables_meta'] = self.db.show_tables()
|
|
|
else:
|
|
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:
|
|
except Exception as e:
|
|
|
LOG.warn('Autocomplete data fetching error: %s' % e)
|
|
LOG.warn('Autocomplete data fetching error: %s' % e)
|