Browse Source

HUE-9280 [flink] Support describe table in left assist

Romain 5 years ago
parent
commit
81498725f3
1 changed files with 20 additions and 2 deletions
  1. 20 2
      desktop/libs/notebook/src/notebook/connectors/flink_sql.py

+ 20 - 2
desktop/libs/notebook/src/notebook/connectors/flink_sql.py

@@ -206,12 +206,12 @@ class FlinkSqlApi(Api):
       elif table is None:
       elif table is None:
         response['tables_meta'] = self.show_tables(database)
         response['tables_meta'] = self.show_tables(database)
       elif column is None:
       elif column is None:
-        columns = self.db.get_columns(table)
+        columns = self.get_columns(database, table)
         response['columns'] = [col['name'] for col in columns]
         response['columns'] = [col['name'] for col in columns]
         response['extended_columns'] = [{
         response['extended_columns'] = [{
             'comment': col.get('comment'),
             'comment': col.get('comment'),
             'name': col.get('name'),
             'name': col.get('name'),
-            'type': str(col['schema'].get('type'))
+            'type': col['type']
           }
           }
           for col in columns
           for col in columns
         ]
         ]
@@ -245,6 +245,24 @@ class FlinkSqlApi(Api):
     return [table[0] for table in resp['results'][0]['data']]
     return [table[0] for table in resp['results'][0]['data']]
 
 
 
 
+  def get_columns(self, database, table):
+    session = self._get_session()
+    session_id = session['id']
+
+    resp = self.db.execute_statement(session_id=session_id, statement='USE %(database)s' % {'database': database})
+    resp = self.db.execute_statement(session_id=session_id, statement='DESCRIBE %(table)s' % {'table': table})
+
+    columns = json.loads(resp['results'][0]['data'][0][0])['columns']
+
+    return [{
+        'name': col['field_name'],
+        'type': col['field_type'],  # Types to unify
+        'comment': '',
+      }
+      for col in columns
+    ]
+
+
   def cancel(self, notebook, snippet):
   def cancel(self, notebook, snippet):
     session = self._get_session()
     session = self._get_session()
     statement_id = snippet['result']['handle']['guid']
     statement_id = snippet['result']['handle']['guid']