Ver código fonte

HUE-7955 [notebook] Add async to get sample data API

Romain Rigaux 7 anos atrás
pai
commit
6ec5cc4d30

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

@@ -358,7 +358,7 @@ class HiveServer2Dbms(object):
     return resp
 
 
-  def get_sample(self, database, table, column=None, nested=None, limit=100):
+  def get_sample(self, database, table, column=None, nested=None, limit=100, async=False):
     result = None
     hql = None
 
@@ -379,11 +379,14 @@ class HiveServer2Dbms(object):
 
     if hql:
       query = hql_query(hql)
-      handle = self.execute_and_wait(query, timeout_sec=5.0)
+      if async:
+        return self.execute_and_watch(query)
+      else:
+        handle = self.execute_and_wait(query, timeout_sec=5.0)
 
-      if handle:
-        result = self.fetch(handle, rows=100)
-        self.close(handle)
+        if handle:
+          result = self.fetch(handle, rows=100)
+          self.close(handle)
 
     return result
 

+ 1 - 2
desktop/libs/indexer/src/indexer/api3.py

@@ -148,7 +148,6 @@ def guess_field_types(request):
   elif file_format['inputFormat'] == 'query':
     query_id = file_format['query']['id'] if file_format['query'].get('id') else file_format['query']
 
-    # Only support non expired query history. Otherwise would need to get schema without executing a query.
     notebook = Notebook(document=Document2.objects.document(user=request.user, doc_id=query_id)).get_data()
     snippet = notebook['snippets'][0]
     db = get_api(request, snippet)
@@ -157,7 +156,7 @@ def guess_field_types(request):
       snippet['query'] = snippet['statement'] #self._get_current_statement(db, snippet) # TODO multi statement
       sample = db.autocomplete(snippet=snippet, database='', table='')
       format_ = {
-          "sample": [[], [], [], [], []],
+          "sample": [[], [], [], [], []], # TODO manual exec and try/catch on query handle
           "columns": [
               Field(col['name'], HiveFormat.FIELD_TYPE_TRANSLATE.get(col['type'], 'string')).to_dict()
               for col in sample['extended_columns']

+ 1 - 1
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -450,7 +450,7 @@ class HS2Api(Api):
   def get_sample_data(self, snippet, database=None, table=None, column=None):
     try:
       db = self._get_db(snippet)
-      return _get_sample_data(db, database, table, column)
+      return _get_sample_data(db, database, table, column) # TODO async in all signatures
     except QueryServerException, ex:
       raise QueryError(ex.message)