Эх сурвалжийг харах

[notebook] Offer to view the data of a table and scroll

Currently generate a SELECT * and trigger the execution in the frontend.
Follow-up refactoring is going to standardize the API.
Romain Rigaux 10 жил өмнө
parent
commit
4b267283f8

+ 8 - 0
apps/beeswax/src/beeswax/server/dbms.py

@@ -264,6 +264,14 @@ class HiveServer2Dbms(object):
     return self.execute_statement(hql)
     return self.execute_statement(hql)
 
 
 
 
+  def get_select_star_query(self, database, table):
+    if table.partition_keys:  # Filter on max number of partitions for partitioned tables
+      hql = self._get_sample_partition_query(database, table, limit=10000) # Currently need a limit
+    else:
+      hql = "SELECT * FROM `%s`.`%s`" % (database, table.name)
+    return hql
+
+
   def execute_statement(self, hql):
   def execute_statement(self, hql):
     if self.server_name == 'impala':
     if self.server_name == 'impala':
       query = hql_query(hql, QUERY_TYPES[1])
       query = hql_query(hql, QUERY_TYPES[1])

+ 1 - 1
apps/metastore/src/metastore/templates/describe_table.mako

@@ -310,7 +310,7 @@ ${ assist.assistPanel() }
               <div class="inline-block pull-right">
               <div class="inline-block pull-right">
                 <a class="inactive-action" href="javascript: void(0);"><i class="fa fa-star"></i></a>
                 <a class="inactive-action" href="javascript: void(0);"><i class="fa fa-star"></i></a>
                 <a class="inactive-action margin-left-5" href="#" id="import-data-btn" title="${_('Import Data')}"><i class="fa fa-arrow-circle-o-down"></i></a>
                 <a class="inactive-action margin-left-5" href="#" id="import-data-btn" title="${_('Import Data')}"><i class="fa fa-arrow-circle-o-down"></i></a>
-                <a class="inactive-action margin-left-5" href="${ url('metastore:read_table', database=database, table=table.name) }" title="${_('Browse Data')}"><i class="fa fa-list"></i></a>
+                <a class="inactive-action margin-left-5" href="${ url('notebook:browse', database=database, table=table.name) }" title="${_('Browse Data')}"><i class="fa fa-list"></i></a>
                 % if has_write_access:
                 % if has_write_access:
                   <a class="inactive-action margin-left-5" href="#dropTable" data-toggle="modal" title="${_('Drop')} ${view_or_table_noun}"><i class="fa fa-times"></i></a>
                   <a class="inactive-action margin-left-5" href="#dropTable" data-toggle="modal" title="${_('Drop')} ${view_or_table_noun}"><i class="fa fa-times"></i></a>
                 % endif
                 % endif

+ 5 - 0
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -202,3 +202,8 @@ class HS2Api(Api):
   def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
   def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
     db = self._get_db(snippet)
     db = self._get_db(snippet)
     return _autocomplete(db, database, table, column, nested)
     return _autocomplete(db, database, table, column, nested)
+
+  def get_select_star_query(self, snippet, database, table):
+    db = self._get_db(snippet)
+    table = db.get_table(database, table)
+    return db.get_select_star_query(database, table)

+ 12 - 10
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -666,12 +666,14 @@
       if (self.status() == 'running') {
       if (self.status() == 'running') {
         self.checkStatus();
         self.checkStatus();
       }
       }
-
-      if (self.status() == 'loading') {
+      else if (self.status() == 'loading') {
         self.status('failed');
         self.status('failed');
         self.progress(0);
         self.progress(0);
         self.jobs([]);
         self.jobs([]);
       }
       }
+      else if (self.status() == 'ready-execute') {
+        self.execute();
+      }
     };
     };
   };
   };
 
 
@@ -861,13 +863,13 @@
 
 
     self.authSession = function () {
     self.authSession = function () {
       self.createSession(new Session(vm, {
       self.createSession(new Session(vm, {
-            'type': vm.authSessionType(),
-            'properties': [
-              {'name': 'user', 'value': vm.authSessionUsername()},
-              {'name': 'password', 'value': vm.authSessionPassword()}
-            ]
-          }),
-          vm.authSessionCallback()  // On new session we don't automatically execute the snippet after the aut. On session expiration we do or we refresh assist DB when login-in.
+          'type': vm.authSessionType(),
+          'properties': [
+            {'name': 'user', 'value': vm.authSessionUsername()},
+            {'name': 'password', 'value': vm.authSessionPassword()}
+          ]
+        }),
+        vm.authSessionCallback()  // On new session we don't automatically execute the snippet after the aut. On session expiration we do or we refresh assist DB when login-in.
       );
       );
     };
     };
 
 
@@ -1206,7 +1208,7 @@
           self.selectedNotebook(self.notebooks()[0]);
           self.selectedNotebook(self.notebooks()[0]);
         }
         }
       });
       });
-      if (self.selectedNotebook().snippets().length === 0 && self.editorMode) {
+      if (self.selectedNotebook().snippets().length === 0 && self.editorMode) { // Add snippet in new Editor
         self.selectedNotebook().newSnippet();
         self.selectedNotebook().newSnippet();
       }
       }
     };
     };

+ 1 - 0
desktop/libs/notebook/src/notebook/urls.py

@@ -41,6 +41,7 @@ urlpatterns = patterns('notebook.views',
   url(r'^copy$', 'copy', name='copy'),
   url(r'^copy$', 'copy', name='copy'),
 
 
   url(r'^editor$', 'editor', name='editor'),
   url(r'^editor$', 'editor', name='editor'),
+  url(r'^browse(?P<database>\w+)/(?P<table>\w+)$', 'browse', name='browse'),
 )
 )
 
 
 # APIs
 # APIs

+ 18 - 17
desktop/libs/notebook/src/notebook/views.py

@@ -90,19 +90,20 @@ def new(request):
   return notebook(request)
   return notebook(request)
 
 
 
 
-def browse(request):
-  database = request.GET.get('database', 'default')
-  table = request.GET.get('table')
+def browse(request, database, table):
   editor_type = request.GET.get('type', 'hive')
   editor_type = request.GET.get('type', 'hive')
-    
+
+  snippet = {'type': editor_type}
+  sql_select = get_api(request.user, snippet, request.fs, request.jt).get_select_star_query(snippet, database, table)
+
   editor = Notebook()
   editor = Notebook()
-  editor.data = json.dumps({  
+  editor.data = json.dumps({
     'description':'',
     'description':'',
-    'sessions':[  
-      {  
+    'sessions':[
+      {
          'type':'hive',
          'type':'hive',
-         'properties':[  
- 
+         'properties':[
+
          ],
          ],
          'id':None
          'id':None
       }
       }
@@ -110,17 +111,17 @@ def browse(request):
     'selectedSnippet':'hive',
     'selectedSnippet':'hive',
     'type': 'query-%s' % editor_type,
     'type': 'query-%s' % editor_type,
 
 
-    'snippets':[  
-      {  
+    'snippets':[
+      {
          'status':'ready-execute',
          'status':'ready-execute',
          'id':'e8b323b3-88ef-3a84-6264-af11fa5fbefb',
          'id':'e8b323b3-88ef-3a84-6264-af11fa5fbefb',
-         'statement_raw':'select * from %(database)s',
-         'statement':'select * from sample_07',
-         'type':'hive',
-         'properties':{  
-            'files':[  
+         'statement_raw': sql_select,
+         'statement': sql_select,
+         'type': editor_type,
+         'properties':{
+            'files':[
             ],
             ],
-            'settings':[  
+            'settings':[
             ]
             ]
          },
          },
          'name': 'Browse',
          'name': 'Browse',