瀏覽代碼

HUE-9191 [ui] Add table Foreign Keys icons to the assist

Romain 5 年之前
父節點
當前提交
880f3e2c7f
共有 2 個文件被更改,包括 24 次插入1 次删除
  1. 3 0
      apps/beeswax/src/beeswax/api.py
  2. 21 1
      desktop/core/src/desktop/js/catalog/dataCatalogEntry.js

+ 3 - 0
apps/beeswax/src/beeswax/api.py

@@ -133,8 +133,10 @@ def _autocomplete(db, database=None, table=None, column=None, nested=None, query
           col_props.update(extra_col_options.get(col_props['name'], {}))
 
         primary_keys = [col['name'] for col in extra_col_options.values() if col.get('primary_key') == 'true'] # Until IMPALA-8291
+        foreign_keys = []  # Not supported yet
       else:
         primary_keys = [pk.name for pk in table.primary_keys]
+        foreign_keys = table.foreign_keys
 
       response['support_updates'] = table.is_impala_only
       response['columns'] = [column.name for column in table.cols]
@@ -142,6 +144,7 @@ def _autocomplete(db, database=None, table=None, column=None, nested=None, query
       response['is_view'] = table.is_view
       response['partition_keys'] = [{'name': part.name, 'type': part.type} for part in table.partition_keys]
       response['primary_keys'] = [{'name': pk} for pk in primary_keys]
+      response['foreign_keys'] = [{'name': pk.name, 'to': pk.type} for pk in primary_keys]
     else:
       col = db.get_column(database, table, column)
       if col:

+ 21 - 1
desktop/core/src/desktop/js/catalog/dataCatalogEntry.js

@@ -427,6 +427,12 @@ class DataCatalogEntry {
             primaryKeys[primaryKey.name] = true;
           });
         }
+        const foreignKeys = {};
+        if (sourceMeta.foreign_keys) {
+          sourceMeta.foreign_keys.forEach(foreignKey => {
+            foreignKeys[foreignKey.name] = true;
+          });
+        }
 
         const entities =
           sourceMeta.databases ||
@@ -466,6 +472,9 @@ class DataCatalogEntry {
                       if (sourceMeta.primary_keys) {
                         definition.primaryKey = !!primaryKeys[entity.name];
                       }
+                      if (sourceMeta.foreign_keys) {
+                        definition.foreignKey = !!foreignKeys[entity.name];
+                      }
                       definition.index = index++;
                       catalogEntry.definition = definition;
                       catalogEntry.saveLater();
@@ -1260,6 +1269,17 @@ class DataCatalogEntry {
     return self.definition && !!self.definition.partitionKey;
   }
 
+  /**
+   * Returns true if the entry is a foreign key. Note that the definition has to come from a parent entry, i.e.
+   * getChildren().
+   *
+   * @return {boolean}
+   */
+  isForeignKey() {
+    const self = this;
+    return self.definition && !!self.definition.foreignKey;
+  }
+
   /**
    * Returns true if the entry is either a partition or primary key. Note that the definition has to come from a parent entry, i.e.
    * getChildren().
@@ -1267,7 +1287,7 @@ class DataCatalogEntry {
    * @return {boolean}
    */
   isKey() {
-    return this.isPartitionKey() || this.isPrimaryKey();
+    return this.isPartitionKey() || this.isPrimaryKey() || this.isForeignKey();
   }
 
   /**