Selaa lähdekoodia

HUE-9077 [connector] Add column listing to ksql autocomplete

Romain 6 vuotta sitten
vanhempi
commit
a55df7db4b

+ 8 - 0
desktop/libs/kafka/src/kafka/ksql_client.py

@@ -94,6 +94,14 @@ class KSqlApi(object):
       raise KSqlApiException(e)
 
 
+  def get_columns(self, table):
+    try:
+      response = self.client.ksql('DESCRIBE %s' % table)
+      return response[0]['sourceDescription']['fields']
+    except Exception as e:
+      raise KSqlApiException(e)
+
+
   def ksql(self, statement):
     response = self.client.ksql(statement)
     print(response)

+ 9 - 0
desktop/libs/notebook/src/notebook/connectors/ksql.py

@@ -96,6 +96,15 @@ class KSqlApi(Api):
             {'name': t['name'], 'type': t['type'], 'comment': 'Topic: %(topic)s Format: %(format)s' % t}
             for t in self.db.show_streams()
           ]
+      elif column is None:
+        columns = self.db.get_columns(table)
+        response['columns'] = [col['name'] for col in columns]
+        response['extended_columns'] = [{
+            'comment': col.get('comment'),
+            'name': col.get('name'),
+            'type': str(col['schema'].get('type'))
+          } for col in columns
+        ]
       else:
         response = {}