浏览代码

HUE-2320 [impala] Sync tables at the Impala level in the editor

Added table diff JS calls
Enrico Berti 11 年之前
父节点
当前提交
d2f809e

+ 28 - 1
apps/beeswax/src/beeswax/templates/execute.mako

@@ -950,7 +950,7 @@ ${ dashboard.import_charts() }
 
 
 <script type="text/javascript" charset="utf-8">
-var codeMirror, renderNavigator, resetNavigator, resizeNavigator, dataTable, renderRecent;
+var codeMirror, renderNavigator, resetNavigator, resizeNavigator, dataTable, renderRecent, syncWithHive;
 
 var HIVE_AUTOCOMPLETE_BASE_URL = "${ autocomplete_base_url | n,unicode }";
 var HIVE_AUTOCOMPLETE_FAILS_QUIETLY_ON = [500]; // error codes from beeswax/views.py - autocomplete
@@ -1198,6 +1198,33 @@ $(document).ready(function () {
     }
   }
 
+  % if app_name == 'impala':
+    syncWithHive = function () {
+      // sync tables with Hive
+      hac_jsoncalls({
+        autocompleteBaseURL: "${ autocomplete_base_url_hive | n,unicode }",
+        database: viewModel.database(),
+        onDataReceived: function (data) {
+          if (data.tables) {
+            var _hiveTables = data.tables;
+            hac_getTables(viewModel.database(), function (data) {  //preload tables for the default db
+              var _impalaTables = data.split(" ");
+              var _diff = {
+                added: _hiveTables.diff(_impalaTables),
+                removed: _impalaTables.diff(_hiveTables)
+              }
+              console.log("Tables diff")
+              console.log(_diff);
+            });
+          }
+        }
+      });
+    }
+    if (viewModel.database()) {
+      syncWithHive();
+    }
+  % endif
+
   $("#expandResults").on("click", function(){
     if ($(this).find("i").hasClass("fa-expand")){
       $(this).find("i").removeClass("fa-expand").addClass("fa-compress");

+ 1 - 0
apps/beeswax/src/beeswax/views.py

@@ -406,6 +406,7 @@ def execute_query(request, design_id=None, query_history_id=None):
     'query': query_history, # Backward
     'query_history': query_history,
     'autocomplete_base_url': reverse(get_app_name(request) + ':api_autocomplete_databases', kwargs={}),
+    'autocomplete_base_url_hive': reverse('beeswax:api_autocomplete_databases', kwargs={}),
     'can_edit_name': design and design.id and not design.is_auto,
     'can_edit': design and design.id and design.doc.get().can_write(request.user),
     'action': action,

+ 5 - 4
apps/beeswax/static/js/autocomplete.utils.js

@@ -15,16 +15,17 @@
 // limitations under the License.
 
 function hac_jsoncalls(options) {
-  if (typeof HIVE_AUTOCOMPLETE_BASE_URL != "undefined") {
+  if (typeof HIVE_AUTOCOMPLETE_BASE_URL != "undefined" || typeof options.autocompleteBaseURL != "undefined") {
+    var _baseURL = typeof options.autocompleteBaseURL != "undefined" ? options.autocompleteBaseURL : HIVE_AUTOCOMPLETE_BASE_URL;
     if (options.database == null) {
-      $.getJSON(HIVE_AUTOCOMPLETE_BASE_URL, options.onDataReceived);
+      $.getJSON(_baseURL, options.onDataReceived);
     }
     if (options.database != null) {
       if (options.table != null) {
-        $.getJSON(HIVE_AUTOCOMPLETE_BASE_URL + options.database + "/" + options.table, options.onDataReceived);
+        $.getJSON(_baseURL + options.database + "/" + options.table, options.onDataReceived);
       }
       else {
-        $.getJSON(HIVE_AUTOCOMPLETE_BASE_URL + options.database + "/", options.onDataReceived);
+        $.getJSON(_baseURL + options.database + "/", options.onDataReceived);
       }
     }
   }

+ 6 - 0
desktop/core/static/js/hue.utils.js

@@ -62,6 +62,12 @@ if (!('filter' in Array.prototype)) {
   };
 }
 
+Array.prototype.diff = function (a) {
+  return this.filter(function (i) {
+    return a.indexOf(i) < 0;
+  });
+};
+
 /*
  * Add utility methods to the HUE object
 */