|
|
@@ -32,10 +32,10 @@ from hadoop import cluster
|
|
|
from notebook.models import import_saved_beeswax_query
|
|
|
from useradmin.models import get_default_user_group, install_sample_user, User
|
|
|
|
|
|
-import beeswax.conf
|
|
|
-from beeswax.models import SavedQuery, HQL, IMPALA
|
|
|
from beeswax.design import hql_query
|
|
|
+from beeswax.conf import LOCAL_EXAMPLES_DATA_DIR
|
|
|
from beeswax.hive_site import has_concurrency_support
|
|
|
+from beeswax.models import SavedQuery, HQL, IMPALA
|
|
|
from beeswax.server import dbms
|
|
|
from beeswax.server.dbms import get_query_server_config, QueryServerException
|
|
|
|
|
|
@@ -57,6 +57,7 @@ class Command(BaseCommand):
|
|
|
db_name = args[1] if len(args) > 1 else 'default'
|
|
|
user = User.objects.get(username=pwd.getpwuid(os.getuid()).pw_name)
|
|
|
else:
|
|
|
+ interpreter = options.get('interpreter')
|
|
|
app_name = options['app_name']
|
|
|
db_name = options.get('db_name', 'default')
|
|
|
user = options['user']
|
|
|
@@ -68,8 +69,8 @@ class Command(BaseCommand):
|
|
|
# Documents will belong to this user but we run the install as the current user
|
|
|
try:
|
|
|
sample_user = install_sample_user(user)
|
|
|
- self._install_queries(sample_user, app_name)
|
|
|
- self._install_tables(user, app_name, db_name, tables)
|
|
|
+ self._install_queries(sample_user, app_name, interpreter=interpreter)
|
|
|
+ self._install_tables(user, app_name, db_name, tables, interpreter=interpreter)
|
|
|
except Exception as ex:
|
|
|
exception = ex
|
|
|
|
|
|
@@ -88,21 +89,21 @@ class Command(BaseCommand):
|
|
|
else:
|
|
|
raise exception
|
|
|
|
|
|
- def _install_tables(self, django_user, app_name, db_name, tables):
|
|
|
- data_dir = beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get()
|
|
|
+ def _install_tables(self, django_user, app_name, db_name, tables, interpreter=None):
|
|
|
+ data_dir = LOCAL_EXAMPLES_DATA_DIR.get()
|
|
|
table_file = open(os.path.join(data_dir, tables))
|
|
|
table_list = json.load(table_file)
|
|
|
table_file.close()
|
|
|
|
|
|
for table_dict in table_list:
|
|
|
- table = SampleTable(table_dict, app_name, db_name)
|
|
|
+ table = SampleTable(table_dict, app_name, db_name, interpreter=interpreter)
|
|
|
try:
|
|
|
table.install(django_user)
|
|
|
except Exception as ex:
|
|
|
raise InstallException(_('Could not install table: %s') % ex)
|
|
|
|
|
|
- def _install_queries(self, django_user, app_name):
|
|
|
- design_file = open(os.path.join(beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get(), 'designs.json'))
|
|
|
+ def _install_queries(self, django_user, app_name, interpreter=None):
|
|
|
+ design_file = open(os.path.join(LOCAL_EXAMPLES_DATA_DIR.get(), 'designs.json'))
|
|
|
design_list = json.load(design_file)
|
|
|
design_file.close()
|
|
|
|
|
|
@@ -113,16 +114,16 @@ class Command(BaseCommand):
|
|
|
for design_dict in design_list:
|
|
|
design = SampleQuery(design_dict)
|
|
|
try:
|
|
|
- design.install(django_user)
|
|
|
+ design.install(django_user, interpreter=interpreter)
|
|
|
except Exception as ex:
|
|
|
- raise InstallException(_('Could not install query: %s') % ex)
|
|
|
+ raise InstallException(_('Could not install %s query: %s') % (app_name, ex))
|
|
|
|
|
|
|
|
|
class SampleTable(object):
|
|
|
"""
|
|
|
Represents a table loaded from the tables.json file
|
|
|
"""
|
|
|
- def __init__(self, data_dict, app_name, db_name='default'):
|
|
|
+ def __init__(self, data_dict, app_name, db_name='default', interpreter=None):
|
|
|
self.name = data_dict['table_name']
|
|
|
if 'partition_files' in data_dict:
|
|
|
self.partition_files = data_dict['partition_files']
|
|
|
@@ -130,14 +131,14 @@ class SampleTable(object):
|
|
|
self.partition_files = None
|
|
|
self.filename = data_dict['data_file']
|
|
|
self.hql = data_dict['create_hql']
|
|
|
- self.query_server = get_query_server_config(app_name)
|
|
|
+ self.query_server = get_query_server_config(app_name, connector=interpreter)
|
|
|
self.app_name = app_name
|
|
|
self.db_name = db_name
|
|
|
self.columns = data_dict.get('columns')
|
|
|
self.is_transactional = data_dict.get('transactional')
|
|
|
|
|
|
# Sanity check
|
|
|
- self._data_dir = beeswax.conf.LOCAL_EXAMPLES_DATA_DIR.get()
|
|
|
+ self._data_dir = LOCAL_EXAMPLES_DATA_DIR.get()
|
|
|
if self.partition_files:
|
|
|
for partition_spec, filename in list(self.partition_files.items()):
|
|
|
filepath = os.path.join(self._data_dir, filename)
|
|
|
@@ -341,7 +342,7 @@ class SampleQuery(object):
|
|
|
self.data = data_dict['data']
|
|
|
|
|
|
|
|
|
- def install(self, django_user):
|
|
|
+ def install(self, django_user, interpreter=None):
|
|
|
"""
|
|
|
Install queries. Raise InstallException on failure.
|
|
|
"""
|
|
|
@@ -376,7 +377,7 @@ class SampleQuery(object):
|
|
|
doc2.save()
|
|
|
except Document2.DoesNotExist:
|
|
|
# Create document from saved query
|
|
|
- notebook = import_saved_beeswax_query(query)
|
|
|
+ notebook = import_saved_beeswax_query(query, interpreter=interpreter)
|
|
|
data = notebook.get_data()
|
|
|
data['isSaved'] = True
|
|
|
uuid = data.get('uuid')
|