فهرست منبع

HUE-7877 [editor] Preparing getting metadata of a sub query

Romain Rigaux 7 سال پیش
والد
کامیت
f5616978f3
2فایلهای تغییر یافته به همراه30 افزوده شده و 1 حذف شده
  1. 17 1
      apps/beeswax/src/beeswax/api.py
  2. 13 0
      apps/beeswax/src/beeswax/server/dbms.py

+ 17 - 1
apps/beeswax/src/beeswax/api.py

@@ -108,7 +108,23 @@ def _autocomplete(db, database=None, table=None, column=None, nested=None):
       tables_meta = db.get_tables_meta(database=database)
       response['tables_meta'] = tables_meta
     elif column is None:
-      table = db.get_table(database, table)
+      if False:
+        class SubQueryTable():
+          def __init__(self, db, query):
+            self.query = query
+            # Table Properties below            
+            self.name = 'Test'
+            # TODO Replace 't.', type different too?
+            self.cols =  db.get_query_metadata(query).data_table.cols()
+            self.hdfs_link = None
+            self.comment = None
+            self.is_impala_only = False
+            self.is_view = False
+            self.partition_keys = []
+            self.properties = {}
+        table = SubQueryTable(db, 'SELECT app, bytes, concat(\'http://\', url) as url2 FROM web_logs')
+      else:
+        table = db.get_table(database, table)
       response['hdfs_link'] = table.hdfs_link
       response['comment'] = table.comment
 

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

@@ -904,6 +904,19 @@ class HiveServer2Dbms(object):
     return result
 
 
+  def get_query_metadata(self, query):
+    hql = 'SELECT * FROM ( %(query)s ) t LIMIT 0' % {'query': query}
+
+    query = hql_query(hql)
+    handle = self.execute_and_wait(query, timeout_sec=15.0)
+
+    if handle:
+      result = self.fetch(handle, rows=5000)
+      self.close(handle)
+
+    return result
+
+
   def explain(self, query):
     return self.client.explain(query)