Browse Source

[impala] Fix auto complete bug

Impala and HiveServer2 API differs and so it is a bit hacky
Romain Rigaux 12 years ago
parent
commit
d3d32ca9d2

+ 22 - 4
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -44,6 +44,7 @@ LOG = logging.getLogger(__name__)
 class HiveServerTable(Table):
 class HiveServerTable(Table):
   """
   """
   We are parsing DESCRIBE EXTENDED text as the metastore API like GetColumns() misses most of the information.
   We are parsing DESCRIBE EXTENDED text as the metastore API like GetColumns() misses most of the information.
+  Impala only supports a simple DESCRIBE.
   """
   """
   def __init__(self, table_results, table_schema, desc_results, desc_schema):
   def __init__(self, table_results, table_schema, desc_results, desc_schema):
     if not table_results.rows:
     if not table_results.rows:
@@ -95,8 +96,12 @@ class HiveServerTable(Table):
   @property
   @property
   def cols(self):
   def cols(self):
     cols = HiveServerTTableSchema(self.desc_results, self.desc_schema).cols()
     cols = HiveServerTTableSchema(self.desc_results, self.desc_schema).cols()
-    end_cols_index = map(itemgetter('col_name'), cols).index('') # Truncate below extended describe
-    return cols[0:end_cols_index]
+    try:
+      end_cols_index = map(itemgetter('col_name'), cols).index('') # Truncate below extended describe
+      return cols[0:end_cols_index]
+    except:
+      # Impala use non extended describe and 'col' instead of 'col_name'
+      return cols
 
 
   @property
   @property
   def comment(self):
   def comment(self):
@@ -192,7 +197,15 @@ class HiveServerTTableSchema:
     self.schema = schema
     self.schema = schema
 
 
   def cols(self):
   def cols(self):
-    return HiveServerTRowSet(self.columns, self.schema).cols(('col_name', 'data_type', 'comment'))
+    try:
+      return HiveServerTRowSet(self.columns, self.schema).cols(('col_name', 'data_type', 'comment'))
+    except:
+      # Impala API is different
+      cols = HiveServerTRowSet(self.columns, self.schema).cols(('name', 'type', 'comment'))
+      for col in cols: 
+        col['col_name'] = col.pop('name')
+        col['col_type'] = col.pop('type')
+      return cols
 
 
   def col(self, colName):
   def col(self, colName):
     pos = self._get_col_position(colName)
     pos = self._get_col_position(colName)
@@ -421,7 +434,12 @@ class HiveServerClient:
     res = self.call(self._client.GetTables, req)
     res = self.call(self._client.GetTables, req)
 
 
     table_results, table_schema = self.fetch_result(res.operationHandle)
     table_results, table_schema = self.fetch_result(res.operationHandle)
-    desc_results, desc_schema = self.execute_statement('DESCRIBE EXTENDED %s' % table_name)
+    if self.query_server['server_name'] == 'impala':
+      # Impala does not supported extended
+      query = 'DESCRIBE %s' % table_name
+    else:
+      query = 'DESCRIBE EXTENDED %s' % table_name
+    desc_results, desc_schema = self.execute_statement(query)
 
 
     return HiveServerTable(table_results.results, table_schema.schema, desc_results.results, desc_schema.schema)
     return HiveServerTable(table_results.results, table_schema.schema, desc_results.results, desc_schema.schema)
 
 

+ 14 - 0
desktop/core/src/desktop/templates/tours.mako

@@ -43,6 +43,20 @@ $.jHueTour({
       "video": "http://player.vimeo.com/video/73849021",
       "video": "http://player.vimeo.com/video/73849021",
       "blog": "http://gethue.tumblr.com/post/60376973455/hadoop-tutorials-ii-1-prepare-the-data-for-analysis"
       "blog": "http://gethue.tumblr.com/post/60376973455/hadoop-tutorials-ii-1-prepare-the-data-for-analysis"
     },
     },
+    {
+      "name": "saml",
+      "desc": "${_("SSO with SAML")}",
+      "path": "/(useradmin|about)",
+      "video": "http://player.vimeo.com/video/76063637",
+      "blog": "http://gethue.tumblr.com/post/62273866476/sso-with-hue-new-saml-backend"
+    },
+    {
+      "name": "impalavshive",
+      "desc": "${_("Fast SQL qith Impala")}",
+      "path": "/impala",
+      "video": "http://player.vimeo.com/video/75493693",
+      "blog": "http://gethue.tumblr.com/post/62452792255/fast-sql-with-the-impala-query-editor"
+    },
     {
     {
       "name": "pigeditor",
       "name": "pigeditor",
       "desc": "${_("The Pig Editor")}",
       "desc": "${_("The Pig Editor")}",