Browse Source

HUE-8687 [frontend] Move the reminding autocompleter logic into the webpack bundle

This also adds node based jasmine testing with jsdom as the preferred test execution as it's much quicker than karma. Karma with Chrome headless can still be run with "npm run test-karma"
Johan Ahlen 6 năm trước cách đây
mục cha
commit
a88901f9cd
51 tập tin đã thay đổi với 4075 bổ sung6805 xóa
  1. 3 3
      .eslintrc.js
  2. 1 1
      apps/beeswax/src/beeswax/templates/execute.mako
  3. 1 1
      desktop/core/src/desktop/js/api/apiHelper.js
  4. 30 27
      desktop/core/src/desktop/js/apps/notebook/aceAutocompleteWrapper.js
  5. 2 3
      desktop/core/src/desktop/js/apps/notebook/notebook.ko.js
  6. 39 30
      desktop/core/src/desktop/js/apps/notebook/spec/aceAutocompleteWrapperSpec.js
  7. 1 1
      desktop/core/src/desktop/js/catalog/contextCatalog.js
  8. 1 1
      desktop/core/src/desktop/js/catalog/dataCatalog.js
  9. 2 0
      desktop/core/src/desktop/js/catalog/dataCatalogEntry.js
  10. 1 1
      desktop/core/src/desktop/js/catalog/generalDataCatalog.js
  11. 1 1
      desktop/core/src/desktop/js/ext/ko.selectize.custom.js
  12. 12 6
      desktop/core/src/desktop/js/hue.js
  13. 4 4
      desktop/core/src/desktop/js/jquery/plugins/jquery.filechooser.js
  14. 1 1
      desktop/core/src/desktop/js/jquery/plugins/jquery.hdfstree.js
  15. 1 1
      desktop/core/src/desktop/js/jquery/plugins/jquery.tableextender.js
  16. 1 1
      desktop/core/src/desktop/js/jquery/plugins/jquery.tableextender2.js
  17. 6 3
      desktop/core/src/desktop/js/ko/bindings/ko.dropzone.js
  18. 2 2
      desktop/core/src/desktop/js/ko/bindings/ko.tagEditor.js
  19. 1 1
      desktop/core/src/desktop/js/parse/sqlParseSupport.js
  20. 64 0
      desktop/core/src/desktop/js/spec/globalJsConstants.js
  21. 11 0
      desktop/core/src/desktop/js/spec/jasmine.json
  22. 40 0
      desktop/core/src/desktop/js/spec/jasmineSetup.js
  23. 18 0
      desktop/core/src/desktop/js/spec/jquery.plugins.js
  24. 22 0
      desktop/core/src/desktop/js/spec/jquery.test.js
  25. 9 8
      desktop/core/src/desktop/js/spec/karma.config.js
  26. 34 0
      desktop/core/src/desktop/js/spec/run.js
  27. 4 4
      desktop/core/src/desktop/js/sql/aceLocationHandler.js
  28. 2295 0
      desktop/core/src/desktop/js/sql/autocompleteResults.js
  29. 381 0
      desktop/core/src/desktop/js/sql/spec/autocompleteResultsSpec.js
  30. 79 0
      desktop/core/src/desktop/js/sql/spec/lotsOfParseResults.js
  31. 0 0
      desktop/core/src/desktop/js/sql/spec/parseResults.json
  32. 150 0
      desktop/core/src/desktop/js/sql/spec/sqlAutocompleterSpec_IGNORE.js
  33. 162 0
      desktop/core/src/desktop/js/sql/sqlAutocompleter.js
  34. 29 33
      desktop/core/src/desktop/js/utils/hdfsAutocompleter.js
  35. 360 0
      desktop/core/src/desktop/js/utils/hueColors.js
  36. 1 1
      desktop/core/src/desktop/js/utils/hueDebug.js
  37. 180 0
      desktop/core/src/desktop/js/utils/spec/hdfsAutocompleterSpec.js
  38. 0 177
      desktop/core/src/desktop/static/desktop/js/hue.colors.js
  39. 0 1748
      desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js
  40. 0 3956
      desktop/core/src/desktop/static/desktop/js/sqlFunctions.js
  41. 0 167
      desktop/core/src/desktop/static/desktop/spec/hdfsAutocompleterSpec.js
  42. 0 491
      desktop/core/src/desktop/static/desktop/spec/sqlAutocompleter3Spec.js
  43. 0 1
      desktop/core/src/desktop/templates/common_header.mako
  44. 0 1
      desktop/core/src/desktop/templates/common_header_m.mako
  45. 0 5
      desktop/core/src/desktop/templates/hue.mako
  46. 1 1
      desktop/core/src/desktop/templates/hue_ace_autocompleter.mako
  47. 4 4
      desktop/core/src/desktop/templates/ko_components/ko_simple_ace_editor.mako
  48. 5 9
      docs/sdk/sdk.md
  49. 11 1
      ext/thirdparty/README.md
  50. 98 106
      package-lock.json
  51. 7 4
      package.json

+ 3 - 3
.eslintrc.js

@@ -11,12 +11,12 @@ const hueGlobals = [
   'USER_HOME_DIR', 'WorkerGlobalScope',
 
   // other misc
-  'ace', 'Autocompleter', 'CodeMirror', 'impalaDagre', 'less', 'MediumEditor', 'moment', 'Plotly', 'Role',
+  'ace', 'Autocompleter', 'CodeMirror', 'd3v3', 'impalaDagre', 'less', 'MediumEditor', 'moment', 'Plotly', 'Role',
   'sqlStatementsParser', 'trackOnGA',
 
   // jasmine
-  'afterAll', 'afterEach', 'beforeAll', 'beforeEach', 'describe', 'expect', 'fail', 'fit', 'it', 'jasmine', 'xdescribe',
-  'xit'
+  'afterAll', 'afterEach', 'beforeAll', 'beforeEach', 'describe', 'expect', 'fail', 'fit', 'it', 'jasmine', 'spyOn',
+  'xdescribe', 'xit'
 ];
 
 const globals = normalGlobals.concat(hueGlobals).reduce((acc, key) => {

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

@@ -1186,7 +1186,7 @@ var snippet = {
   database: ko.observable()
 };
 
-var autocompleter = new Autocompleter({
+var autocompleter = new AceAutocompleteWrapper({
   snippet: snippet,
   user: HIVE_AUTOCOMPLETE_USER,
   oldEditor: true,

+ 1 - 1
desktop/core/src/desktop/js/api/apiHelper.js

@@ -234,7 +234,7 @@ class ApiHelper {
    * @returns {string}
    */
   getTotalStorageUserPrefix(sourceType) {
-    return sourceType + '_' + LOGGED_USERNAME + '_' + window.location.hostname;
+    return sourceType + '_' + window.LOGGED_USERNAME + '_' + window.location.hostname;
   }
 
   /**

+ 30 - 27
desktop/core/src/desktop/static/desktop/js/autocompleter.js → desktop/core/src/desktop/js/apps/notebook/aceAutocompleteWrapper.js

@@ -14,8 +14,9 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-var Autocompleter = (function () {
+import HdfsAutocompleter from 'utils/hdfsAutocompleter';
 
+class AceAutocompleteWrapper {
   /**
    * @param {Object} options {object}
    * @param options.snippet
@@ -24,62 +25,64 @@ var Autocompleter = (function () {
    * @param {Number} options.timeout
    * @constructor
    */
-  function Autocompleter(options) {
-    var self = this;
+  constructor(options) {
+    const self = this;
     self.snippet = options.snippet;
     self.timeout = options.timeout;
-    
+
     self.topTables = {};
 
-    var initializeAutocompleter = function () {
+    const initializeAutocompleter = function() {
       self.autocompleter = new HdfsAutocompleter({
         user: options.user,
         snippet: options.snippet,
         timeout: options.timeout
       });
     };
-    self.snippet.type.subscribe(function () {
+    self.snippet.type.subscribe(() => {
       initializeAutocompleter();
     });
     initializeAutocompleter();
   }
 
   // TODO: See why we need this one.
-  Autocompleter.prototype.initializeAutocompleter = function () {
-    var self = this;
-  };
+  initializeAutocompleter() {}
 
   // ACE Format for autocompleter
-  Autocompleter.prototype.getCompletions = function (editor, session, pos, prefix, callback) {
-    var self = this;
-    if (! self.autocompleter) {
+  getCompletions(editor, session, pos, prefix, callback) {
+    const self = this;
+    if (!self.autocompleter) {
       return;
     }
 
-    var before = editor.getTextBeforeCursor();
-    var after = editor.getTextAfterCursor(";");
+    const before = editor.getTextBeforeCursor();
+    const after = editor.getTextAfterCursor(';');
 
     try {
-      self.autocomplete(before, after, function(result) {
-        callback(null, result);
-      }, editor);
+      self.autocomplete(
+        before,
+        after,
+        result => {
+          callback(null, result);
+        },
+        editor
+      );
     } catch (err) {
       editor.hideSpinner();
     }
-  };
+  }
 
-  Autocompleter.prototype.getDocTooltip = function (item) {
-    var self = this;
+  getDocTooltip(item) {
+    const self = this;
     return self.autocompleter.getDocTooltip(item);
-  };
-
+  }
 
-  Autocompleter.prototype.autocomplete = function(beforeCursor, afterCursor, callback, editor) {
-    var self = this;
+  autocomplete(beforeCursor, afterCursor, callback, editor) {
+    const self = this;
     if (self.autocompleter) {
       self.autocompleter.autocomplete(beforeCursor, afterCursor, callback, editor);
     }
-  };
+  }
+}
 
-  return Autocompleter;
-})();
+export default AceAutocompleteWrapper;

+ 2 - 3
desktop/core/src/desktop/js/apps/notebook/notebook.ko.js

@@ -18,14 +18,13 @@ import $ from 'jquery';
 import ko from 'knockout';
 import komapping from 'knockout.mapping';
 
+import AceAutocompleteWrapper from 'apps/notebook/aceAutocompleteWrapper';
 import apiHelper from 'api/apiHelper';
 import dataCatalog from 'catalog/dataCatalog';
 import hueAnalytics from 'utils/hueAnalytics';
 import huePubSub from 'utils/huePubSub';
 import hueUtils from 'utils/hueUtils';
 
-// TODO: import Autocompleter
-
 const NOTEBOOK_MAPPING = {
   ignore: [
     'ace',
@@ -2882,7 +2881,7 @@ const Snippet = function(vm, notebook, snippet) {
     );
   };
 
-  self.autocompleter = new Autocompleter({
+  self.autocompleter = new AceAutocompleteWrapper({
     snippet: self,
     user: vm.user,
     optEnabled: false,

+ 39 - 30
desktop/core/src/desktop/static/desktop/spec/autocompleterSpec.js → desktop/core/src/desktop/js/apps/notebook/spec/aceAutocompleteWrapperSpec.js

@@ -13,47 +13,56 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
-(function() {
 
-  describe('autocompleter.js', function () {
+import AceAutocompleteWrapper from '../aceAutocompleteWrapper';
 
-    it('should not throw exceptions', function (done) {
-      var subject = new Autocompleter({
-        snippet: {
-          isSqlDialect: function () { return true },
-          type: ko.observable('hive'),
-          database: function() { return 'default'; },
-          getApiHelper: function () {
-            return {
-              loadDatabases: function (options) {
-                options.successCallback(['bla', undefined])
-              }
-            };
-          }
+describe('aceAutocompleteWrapper.js', () => {
+  it('should not throw exceptions', done => {
+    const subject = new AceAutocompleteWrapper({
+      snippet: {
+        isSqlDialect: function() {
+          return true;
+        },
+        type: ko.observable('hive'),
+        database: function() {
+          return 'default';
+        },
+        getApiHelper: function() {
+          return {
+            loadDatabases: function(options) {
+              options.successCallback(['bla', undefined]);
+            }
+          };
         }
-      });
+      }
+    });
 
-      try {
-        subject.getCompletions({
-          getTextBeforeCursor: function () {
+    try {
+      subject.getCompletions(
+        {
+          getTextBeforeCursor: function() {
             return 'SELECT * FROM (SELECT * FROM tbl) a JOIN (SELECT * FROM tbl) b ON a.c=';
           },
-          getTextAfterCursor: function () {
+          getTextAfterCursor: function() {
             return '';
           },
-          hideSpinner: function () {
+          hideSpinner: function() {
             expect(true).toBeTruthy(); // Prevent jasmine warning
             done();
           },
-          showSpinner: function () {}
-        }, undefined, undefined, undefined, function () {
+          showSpinner: function() {}
+        },
+        undefined,
+        undefined,
+        undefined,
+        () => {
           expect(true).toBeTruthy(); // Prevent jasmine warning
           done();
-        });
-      } catch (e) {
-        expect(false).toBeTruthy('Got unexpected exception');
-        done();
-      }
-    });
+        }
+      );
+    } catch (e) {
+      expect(false).toBeTruthy('Got unexpected exception');
+      done();
+    }
   });
-})();
+});

+ 1 - 1
desktop/core/src/desktop/js/catalog/contextCatalog.js

@@ -33,7 +33,7 @@ import huePubSub from 'utils/huePubSub';
  * @property {ContextCompute} computes
  */
 
-const STORAGE_POSTFIX = LOGGED_USERNAME;
+const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const CONTEXT_CATALOG_VERSION = 4;
 const NAMESPACES_CONTEXT_TYPE = 'namespaces';
 const DISABLE_CACHE = true;

+ 1 - 1
desktop/core/src/desktop/js/catalog/dataCatalog.js

@@ -24,7 +24,7 @@ import DataCatalogEntry from 'catalog/dataCatalogEntry';
 import GeneralDataCatalog from 'catalog/generalDataCatalog';
 import MultiTableEntry from 'catalog/multiTableEntry';
 
-const STORAGE_POSTFIX = LOGGED_USERNAME;
+const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const DATA_CATALOG_VERSION = 5;
 
 let cacheEnabled = true;

+ 2 - 0
desktop/core/src/desktop/js/catalog/dataCatalogEntry.js

@@ -14,6 +14,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+import $ from 'jquery';
+
 import apiHelper from 'api/apiHelper';
 import CancellablePromise from 'api/cancellablePromise';
 import catalogUtils from 'catalog/catalogUtils';

+ 1 - 1
desktop/core/src/desktop/js/catalog/generalDataCatalog.js

@@ -19,7 +19,7 @@ import localforage from 'localforage';
 
 import apiHelper from 'api/apiHelper';
 
-const STORAGE_POSTFIX = LOGGED_USERNAME;
+const STORAGE_POSTFIX = window.LOGGED_USERNAME;
 const DATA_CATALOG_VERSION = 5;
 
 class GeneralDataCatalog {

+ 1 - 1
desktop/core/src/desktop/js/ext/ko.selectize.custom.js

@@ -47,7 +47,7 @@ ko.bindingHandlers.browserAwareSelectize = {
 ko.bindingHandlers.selectize = {
   init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
     if (typeof allBindingsAccessor.get('optionsCaption') == 'undefined')
-      allBindingsAccessor = inject_binding(allBindingsAccessor, 'optionsCaption', HUE_I18n.selectize.choose);
+      allBindingsAccessor = inject_binding(allBindingsAccessor, 'optionsCaption', window.HUE_I18n.selectize.choose);
 
     ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
 

+ 12 - 6
desktop/core/src/desktop/js/hue.js

@@ -26,17 +26,18 @@ import sprintf from 'sprintf-js';
 
 import 'ko/ko.all';
 
+import 'utils/customIntervals';
+import 'utils/json.bigDataParse';
 import apiHelper from 'api/apiHelper';
 import CancellablePromise from 'api/cancellablePromise';
 import contextCatalog from 'catalog/contextCatalog';
-import 'utils/customIntervals';
 import dataCatalog from 'catalog/dataCatalog';
 import hueAnalytics from 'utils/hueAnalytics';
+import HueColors from 'utils/hueColors';
 import hueDebug from 'utils/hueDebug';
 import hueDrop from 'utils/hueDrop';
 import huePubSub from 'utils/huePubSub';
 import hueUtils from 'utils/hueUtils';
-import 'utils/json.bigDataParse';
 import MultiLineEllipsisHandler from 'utils/multiLineEllipsisHandler';
 
 import AceLocationHandler from 'sql/aceLocationHandler';
@@ -53,11 +54,13 @@ import TopNavViewModel from 'topNavViewModel';
 
 // TODO: Remove from global scope
 import EditorViewModel from 'apps/notebook/notebook.ko'; // In history, indexer, importer, editor etc.
-import sqlStatementsParser from 'parse/sqlStatementsParser'; // In search.ko and notebook.ko
-import sqlAutocompleteParser from 'parse/sqlAutocompleteParser'; // Notebook and used throughout via hue-simple-ace-editor ko component
 import globalSearchParser from 'parse/globalSearchParser'; // ko inline autocomp
-import solrQueryParser from 'parse/solrQueryParser'; // simple ace editor
+import HdfsAutocompleter from 'utils/hdfsAutocompleter';
 import solrFormulaParser from 'parse/solrFormulaParser'; // simple ace editor
+import solrQueryParser from 'parse/solrQueryParser'; // simple ace editor
+import SqlAutocompleter from 'sql/sqlAutocompleter';
+import sqlAutocompleteParser from 'parse/sqlAutocompleteParser'; // Notebook and used throughout via hue-simple-ace-editor ko component
+import sqlStatementsParser from 'parse/sqlStatementsParser'; // In search.ko and notebook.ko
 
 // TODO: Migrate away
 window._ = _;
@@ -70,7 +73,9 @@ window.Dropzone = Dropzone;
 window.EditorViewModel = EditorViewModel;
 window.filesize = filesize;
 window.globalSearchParser = globalSearchParser;
+window.HdfsAutocompleter = HdfsAutocompleter;
 window.hueAnalytics = hueAnalytics;
+window.HueColors = HueColors;
 window.hueDebug = hueDebug;
 window.hueDrop = hueDrop;
 window.huePubSub = huePubSub;
@@ -80,9 +85,10 @@ window.MultiLineEllipsisHandler = MultiLineEllipsisHandler;
 window.page = page;
 window.PigFunctions = PigFunctions;
 window.qq = qq;
-window.solrQueryParser = solrQueryParser;
 window.solrFormulaParser = solrFormulaParser;
+window.solrQueryParser = solrQueryParser;
 window.sprintf = sprintf;
+window.SqlAutocompleter = SqlAutocompleter;
 window.sqlAutocompleteParser = sqlAutocompleteParser;
 window.SqlFunctions = SqlFunctions;
 window.SqlParseSupport = SqlParseSupport;

+ 4 - 4
desktop/core/src/desktop/js/jquery/plugins/jquery.filechooser.js

@@ -120,11 +120,11 @@ function Plugin(element, options) {
   this.element = element;
   $(element).data('jHueFileChooser', this);
 
-  this.options = $.extend({}, defaults, { user: LOGGED_USERNAME }, options);
+  this.options = $.extend({}, defaults, { user: window.LOGGED_USERNAME }, options);
   this.options.labels = $.extend(
     {},
     defaults.labels,
-    HUE_I18n.jHueFileChooser,
+    window.HUE_I18n.jHueFileChooser,
     options ? options.labels : {}
   );
   this._defaults = defaults;
@@ -135,11 +135,11 @@ function Plugin(element, options) {
 
 Plugin.prototype.setOptions = function(options) {
   const self = this;
-  self.options = $.extend({}, defaults, { user: LOGGED_USERNAME }, options);
+  self.options = $.extend({}, defaults, { user: window.LOGGED_USERNAME }, options);
   self.options.labels = $.extend(
     {},
     defaults.labels,
-    HUE_I18n.jHueFileChooser,
+    window.HUE_I18n.jHueFileChooser,
     options ? options.labels : {}
   );
   const initialPath = $.trim(self.options.initialPath);

+ 1 - 1
desktop/core/src/desktop/js/jquery/plugins/jquery.hdfstree.js

@@ -57,7 +57,7 @@ function Plugin(element, options) {
   this.options.labels = $.extend(
     {},
     defaults.labels,
-    HUE_I18n.jHueHdfsTree,
+    window.HUE_I18n.jHueHdfsTree,
     options ? options.labels : {}
   );
   this._defaults = defaults;

+ 1 - 1
desktop/core/src/desktop/js/jquery/plugins/jquery.tableextender.js

@@ -57,7 +57,7 @@ Plugin.prototype.setOptions = function(options) {
   this.options.labels = $.extend(
     {},
     defaults.labels,
-    HUE_I18n.jHueTableExtender,
+    window.HUE_I18n.jHueTableExtender,
     options ? options.labels : {}
   );
   this._defaults = defaults;

+ 1 - 1
desktop/core/src/desktop/js/jquery/plugins/jquery.tableextender2.js

@@ -220,7 +220,7 @@ Plugin.prototype.setOptions = function(options) {
   this.options.labels = $.extend(
     {},
     DEFAULT_OPTIONS.labels,
-    HUE_I18n.jHueTableExtender,
+    window.HUE_I18n.jHueTableExtender,
     options ? options.labels : {}
   );
 };

+ 6 - 3
desktop/core/src/desktop/js/ko/bindings/ko.dropzone.js

@@ -36,7 +36,7 @@ ko.bindingHandlers.dropzone = {
         '<div class="pull-right">' +
         '<span class="muted" data-dz-size></span>&nbsp;&nbsp;' +
         '<span data-dz-remove><a href="javascript:undefined;" title="' +
-        HUE_I18n.dropzone.cancelUpload +
+        window.HUE_I18n.dropzone.cancelUpload +
         '"><i class="fa fa-fw fa-times"></i></a></span>' +
         '<span style="display: none" data-dz-uploaded><i class="fa fa-fw fa-check muted"></i></span>' +
         '</div>' +
@@ -73,7 +73,7 @@ ko.bindingHandlers.dropzone = {
         $('#progressStatusBar div').width(progress.toFixed() + '%');
       },
       canceled: function() {
-        $.jHueNotify.info(HUE_I18n.dropzone.uploadCanceled);
+        $.jHueNotify.info(window.HUE_I18n.dropzone.uploadCanceled);
       },
       complete: function(file) {
         if (file.xhr.response !== '') {
@@ -85,7 +85,10 @@ ko.bindingHandlers.dropzone = {
                 value.onError(file.name);
               }
             } else {
-              $(document).trigger('info', response.path + ' ' + HUE_I18n.dropzone.uploadSucceeded);
+              $(document).trigger(
+                'info',
+                response.path + ' ' + window.HUE_I18n.dropzone.uploadSucceeded
+              );
               if (value.onComplete) {
                 value.onComplete(response.path);
               }

+ 2 - 2
desktop/core/src/desktop/js/ko/bindings/ko.tagEditor.js

@@ -168,7 +168,7 @@ ko.bindingHandlers.tagEditor = {
       if (!options.readOnly && !options.hasErrors()) {
         $('<i>')
           .addClass('fa fa-pencil selectize-edit pointer')
-          .attr('title', HUE_I18n.selectize.editTags)
+          .attr('title', window.HUE_I18n.selectize.editTags)
           .appendTo($readOnlyInner);
         $readOnlyInner.click(() => {
           showEdit();
@@ -243,7 +243,7 @@ ko.bindingHandlers.tagEditor = {
         if (!options.readOnly && !options.hasErrors()) {
           $('<i>')
             .addClass('fa fa-pencil selectize-edit pointer')
-            .attr('title', HUE_I18n.selectize.editTags)
+            .attr('title', window.HUE_I18n.selectize.editTags)
             .appendTo($readOnlyInner);
           $readOnlyInner.click(() => {
             showEdit();

+ 1 - 1
desktop/core/src/desktop/js/parse/sqlParseSupport.js

@@ -1294,7 +1294,7 @@ const initSqlParser = function(parser) {
           if (!isColumnLocation && isColumnWrapper && aliasMatch) {
             // TODO: add alias on table in suggestColumns (needs support in sqlAutocomplete3.js)
             // the case is: SELECT cu.| FROM customers cu;
-            // This prevents alias from being added automatically in sqlAutocompleter3.js
+            // This prevents alias from being added automatically in sqlAutocompleter.js
             wrapper.tables = [{ identifierChain: foundPrimary.identifierChain }];
           } else {
             wrapper.tables = [

+ 64 - 0
desktop/core/src/desktop/js/spec/globalJsConstants.js

@@ -0,0 +1,64 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+const globalVars = {
+  LOGGED_USERNAME: 'foo',
+  CACHEABLE_TTL: 1,
+  HAS_OPTIMIZER: false,
+  AUTOCOMPLETE_TIMEOUT: 1,
+  HUE_I18n: {
+    autocomplete: {
+      category: {
+        all: 'all',
+        column: 'columns',
+        cte: 'cte',
+        database: 'database',
+        field: 'field',
+        function: 'function',
+        identifier: 'identifier',
+        keyword: 'keyword',
+        popular: 'popular',
+        sample: 'sample',
+        table: 'table',
+        udf: 'udf',
+        option: 'option',
+        variable: 'variable'
+      },
+      meta: {
+        aggregateFunction: 'aggregateFunction',
+        alias: 'alias',
+        commonTableExpression: 'commonTableExpression',
+        database: 'database',
+        filter: 'filter',
+        groupBy: 'groupBy',
+        join: 'join',
+        joinCondition: 'joinCondition',
+        keyword: 'keyword',
+        orderBy: 'orderBy',
+        table: 'table',
+        sample: 'sample',
+        variable: 'variable',
+        view: 'view',
+        virtual: 'virtual'
+      }
+    }
+  }
+};
+
+Object.keys(globalVars).forEach(key => {
+  global[key] = globalVars[key];
+  global.window[key] = globalVars[key];
+});

+ 11 - 0
desktop/core/src/desktop/js/spec/jasmine.json

@@ -0,0 +1,11 @@
+{
+  "spec_dir": "desktop/core/src/desktop/js",
+  "spec_files": [
+    "**/*[sS]pec.js"
+  ],
+  "helpers": [
+    "spec_helpers/**/*.js"
+  ],
+  "stopSpecOnExpectationFailure": false,
+  "random": false
+}

+ 40 - 0
desktop/core/src/desktop/js/spec/jasmineSetup.js

@@ -0,0 +1,40 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import JasmineCore from 'jasmine-core';
+import { JSDOM } from 'jsdom';
+
+const jsdom = new JSDOM('<!doctype html><html><body></body></html>', {
+  url: 'https://www.gethue.com/hue',
+  contentType: 'text/html',
+  includeNodeLocations: true,
+  storageQuota: 10000000
+});
+
+const { window } = jsdom;
+
+global.document = window.document;
+global.window = window;
+global.self = global;
+global.navigator = {
+  userAgent: 'node.js'
+};
+global.localStorage = window.localStorage;
+global.sessionStorage = window.sessionStorage;
+
+global.getJasmineRequireObj = function() {
+  return JasmineCore;
+};

+ 18 - 0
desktop/core/src/desktop/js/spec/jquery.plugins.js

@@ -0,0 +1,18 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import 'jquery.cookie';
+import 'ext/jquery.total-storage.1.1.3.min';

+ 22 - 0
desktop/core/src/desktop/js/spec/jquery.test.js

@@ -0,0 +1,22 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import $ from 'jquery';
+
+global.$ = $;
+global.jQuery = $;
+global.window.$ = $;
+global.window.jQuery = $;

+ 9 - 8
karma.config.js → desktop/core/src/desktop/js/spec/karma.config.js

@@ -1,12 +1,12 @@
 module.exports = function(config) {
   config.set({
-    basePath: 'desktop/core/src/desktop/js',
-    frameworks: ['jasmine'],
+    basePath: '../',
+    frameworks: ['jasmine-ajax', 'jasmine'],
     files: ['**/spec/*[sS]pec.js'],
     preprocessors: {
       '**/spec/*[sS]pec.js': ['webpack']
     },
-    reporters: ['progress'],
+    reporters: ['spec'],
     port: 9876,
     colors: true,
     logLevel: config.LOG_ERROR,
@@ -18,12 +18,13 @@ module.exports = function(config) {
         rules: [
           {
             test: /\.js$/i,
-            exclude:/(node_modules)/,
-            loader:'babel-loader',
+            exclude: /(node_modules)/,
+            loader: 'babel-loader',
             options: {
-              presets:['@babel/preset-env']
+              presets: ['@babel/preset-env']
             }
-          }
+          },
+          { type: 'javascript/auto', include: /\.json$/, loaders: ['json-loader'] }
         ]
       }
     },
@@ -31,5 +32,5 @@ module.exports = function(config) {
       noInfo: true,
       stats: 'errors-only'
     }
-  })
+  });
 };

+ 34 - 0
desktop/core/src/desktop/js/spec/run.js

@@ -0,0 +1,34 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import Jasmine from 'jasmine';
+import './jasmineSetup';
+import './globalJsConstants';
+import './jquery.test';
+import './jquery.plugins';
+
+import ko from 'knockout';
+import komapping from 'knockout.mapping';
+
+global.ko = ko;
+global.ko.mapping = komapping;
+
+const jasmine = new Jasmine();
+global.jasmine = jasmine;
+
+// modify this line to point to your jasmine.json
+jasmine.loadConfigFile('desktop/core/src/desktop/js/spec/jasmine.json');
+jasmine.execute();

+ 4 - 4
desktop/core/src/desktop/js/sql/aceLocationHandler.js

@@ -224,13 +224,13 @@ class AceLocationHandler {
                 let tooltipText;
                 if (token.syntaxError.expected.length > 0) {
                   tooltipText =
-                    HUE_I18n.syntaxChecker.didYouMean +
+                    window.HUE_I18n.syntaxChecker.didYouMean +
                     ' "' +
                     token.syntaxError.expected[0].text +
                     '"?';
                 } else {
                   tooltipText =
-                    HUE_I18n.syntaxChecker.couldNotFind +
+                    window.HUE_I18n.syntaxChecker.couldNotFind +
                     ' "' +
                     (token.qualifiedIdentifier || token.value) +
                     '"';
@@ -252,12 +252,12 @@ class AceLocationHandler {
                 let tooltipText;
                 if (token.syntaxError.expected.length > 0) {
                   tooltipText =
-                    HUE_I18n.syntaxChecker.didYouMean +
+                    window.HUE_I18n.syntaxChecker.didYouMean +
                     ' "' +
                     token.syntaxError.expected[0].text +
                     '"?';
                 } else if (token.syntaxError.expectedStatementEnd) {
-                  tooltipText = HUE_I18n.syntaxChecker.expectedStatementEnd;
+                  tooltipText = window.HUE_I18n.syntaxChecker.expectedStatementEnd;
                 }
                 if (tooltipText) {
                   const endCoordinates = self.editor.renderer.textToScreenCoordinates(

+ 2295 - 0
desktop/core/src/desktop/js/sql/autocompleteResults.js

@@ -0,0 +1,2295 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import $ from 'jquery';
+import ko from 'knockout';
+
+import apiHelper from 'api/apiHelper';
+import dataCatalog from 'catalog/dataCatalog';
+import HueColors from 'utils/hueColors';
+import hueUtils from 'utils/hueUtils';
+import huePubSub from 'utils/huePubSub';
+import sqlUtils from 'sql/sqlUtils';
+import { SqlSetOptions, SqlFunctions } from 'sql/sqlFunctions';
+
+const normalizedColors = HueColors.getNormalizedColors();
+
+const COLORS = {
+  POPULAR: normalizedColors['blue'][7],
+  KEYWORD: normalizedColors['blue'][4],
+  COLUMN: normalizedColors['green'][2],
+  TABLE: normalizedColors['pink'][3],
+  DATABASE: normalizedColors['teal'][5],
+  SAMPLE: normalizedColors['purple'][5],
+  IDENT_CTE_VAR: normalizedColors['orange'][3],
+  UDF: normalizedColors['purple-gray'][3],
+  HDFS: normalizedColors['red'][2]
+};
+
+const CATEGORIES = {
+  ALL: { id: 'all', color: HueColors.BLUE, label: window.HUE_I18n.autocomplete.category.all },
+  POPULAR: {
+    id: 'popular',
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular
+  },
+  POPULAR_AGGREGATE: {
+    id: 'popularAggregate',
+    weight: 1500,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'agg-udf'
+  },
+  POPULAR_GROUP_BY: {
+    id: 'popularGroupBy',
+    weight: 1300,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'group-by'
+  },
+  POPULAR_ORDER_BY: {
+    id: 'popularOrderBy',
+    weight: 1200,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'order-by'
+  },
+  POPULAR_FILTER: {
+    id: 'popularFilter',
+    weight: 1400,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'filter'
+  },
+  POPULAR_ACTIVE_JOIN: {
+    id: 'popularActiveJoin',
+    weight: 1500,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'join'
+  },
+  POPULAR_JOIN_CONDITION: {
+    id: 'popularJoinCondition',
+    weight: 1500,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'join-condition'
+  },
+  COLUMN: {
+    id: 'column',
+    weight: 1000,
+    color: COLORS.COLUMN,
+    label: window.HUE_I18n.autocomplete.category.column,
+    detailsTemplate: 'column'
+  },
+  SAMPLE: {
+    id: 'sample',
+    weight: 900,
+    color: COLORS.SAMPLE,
+    label: window.HUE_I18n.autocomplete.category.sample,
+    detailsTemplate: 'value'
+  },
+  IDENTIFIER: {
+    id: 'identifier',
+    weight: 800,
+    color: COLORS.IDENT_CTE_VAR,
+    label: window.HUE_I18n.autocomplete.category.identifier,
+    detailsTemplate: 'identifier'
+  },
+  CTE: {
+    id: 'cte',
+    weight: 700,
+    color: COLORS.IDENT_CTE_VAR,
+    label: window.HUE_I18n.autocomplete.category.cte,
+    detailsTemplate: 'cte'
+  },
+  TABLE: {
+    id: 'table',
+    weight: 600,
+    color: COLORS.TABLE,
+    label: window.HUE_I18n.autocomplete.category.table,
+    detailsTemplate: 'table'
+  },
+  DATABASE: {
+    id: 'database',
+    weight: 500,
+    color: COLORS.DATABASE,
+    label: window.HUE_I18n.autocomplete.category.database,
+    detailsTemplate: 'database'
+  },
+  UDF: {
+    id: 'udf',
+    weight: 400,
+    color: COLORS.UDF,
+    label: window.HUE_I18n.autocomplete.category.udf,
+    detailsTemplate: 'udf'
+  },
+  OPTION: {
+    id: 'option',
+    weight: 400,
+    color: COLORS.UDF,
+    label: window.HUE_I18n.autocomplete.category.option,
+    detailsTemplate: 'option'
+  },
+  HDFS: {
+    id: 'hdfs',
+    weight: 300,
+    color: COLORS.HDFS,
+    label: window.HUE_I18n.autocomplete.category.hdfs,
+    detailsTemplate: 'hdfs'
+  },
+  VIRTUAL_COLUMN: {
+    id: 'virtualColumn',
+    weight: 200,
+    color: COLORS.COLUMN,
+    label: window.HUE_I18n.autocomplete.category.column,
+    detailsTemplate: 'column'
+  },
+  COLREF_KEYWORD: {
+    id: 'colrefKeyword',
+    weight: 100,
+    color: COLORS.KEYWORD,
+    label: window.HUE_I18n.autocomplete.category.keyword,
+    detailsTemplate: 'keyword'
+  },
+  VARIABLE: {
+    id: 'variable',
+    weight: 50,
+    color: COLORS.IDENT_CTE_VAR,
+    label: window.HUE_I18n.autocomplete.category.variable,
+    detailsTemplate: 'variable'
+  },
+  KEYWORD: {
+    id: 'keyword',
+    weight: 0,
+    color: COLORS.KEYWORD,
+    label: window.HUE_I18n.autocomplete.category.keyword,
+    detailsTemplate: 'keyword'
+  },
+  POPULAR_JOIN: {
+    id: 'popularJoin',
+    weight: 1500,
+    color: COLORS.POPULAR,
+    label: window.HUE_I18n.autocomplete.category.popular,
+    detailsTemplate: 'join'
+  }
+};
+
+const POPULAR_CATEGORIES = [
+  CATEGORIES.POPULAR_AGGREGATE,
+  CATEGORIES.POPULAR_GROUP_BY,
+  CATEGORIES.POPULAR_ORDER_BY,
+  CATEGORIES.POPULAR_FILTER,
+  CATEGORIES.POPULAR_ACTIVE_JOIN,
+  CATEGORIES.POPULAR_JOIN_CONDITION,
+  CATEGORIES.POPULAR_JOIN
+];
+
+const initLoading = function(loadingObservable, deferred) {
+  loadingObservable(true);
+  deferred.always(() => {
+    loadingObservable(false);
+  });
+};
+
+const locateSubQuery = function(subQueries, subQueryName) {
+  if (typeof subQueries === 'undefined') {
+    return null;
+  }
+  const foundSubQueries = subQueries.filter(knownSubQuery => {
+    return hueUtils.equalIgnoreCase(knownSubQuery.alias, subQueryName);
+  });
+  if (foundSubQueries.length > 0) {
+    return foundSubQueries[0];
+  }
+  return null;
+};
+
+/**
+ * Merges popular group by and order by columns with the column suggestions
+ *
+ * @param sourceDeferred
+ * @param columnsDeferred
+ * @param suggestions
+ */
+const mergeWithColumns = function(sourceDeferred, columnsDeferred, suggestions) {
+  columnsDeferred.done(columns => {
+    const suggestionIndex = {};
+    suggestions.forEach(suggestion => {
+      suggestionIndex[suggestion.value] = suggestion;
+    });
+    columns.forEach(col => {
+      if (suggestionIndex[col.details.name]) {
+        col.category = suggestionIndex[col.details.name].category;
+      }
+    });
+    sourceDeferred.resolve([]);
+  });
+};
+
+class AutocompleteResults {
+  /**
+   *
+   * @param options
+   * @constructor
+   */
+  constructor(options) {
+    const self = this;
+    self.snippet = options.snippet;
+    self.editor = options.editor;
+    self.temporaryOnly =
+      options.snippet.autocompleteSettings && options.snippet.autocompleteSettings.temporaryOnly;
+
+    self.sortOverride = null;
+
+    huePubSub.subscribe('editor.autocomplete.temporary.sort.override', sortOverride => {
+      self.sortOverride = sortOverride;
+    });
+
+    self.entries = ko.observableArray();
+
+    self.lastKnownRequests = [];
+    self.cancellablePromises = [];
+    self.activeDeferrals = [];
+
+    self.loadingKeywords = ko.observable(false);
+    self.loadingFunctions = ko.observable(false);
+    self.loadingDatabases = ko.observable(false);
+    self.loadingTables = ko.observable(false);
+    self.loadingColumns = ko.observable(false);
+    self.loadingValues = ko.observable(false);
+    self.loadingPaths = ko.observable(false);
+    self.loadingJoins = ko.observable(false);
+    self.loadingJoinConditions = ko.observable(false);
+    self.loadingAggregateFunctions = ko.observable(false);
+    self.loadingGroupBys = ko.observable(false);
+    self.loadingOrderBys = ko.observable(false);
+    self.loadingFilters = ko.observable(false);
+    self.loadingPopularTables = ko.observable(false);
+    self.loadingPopularColumns = ko.observable(false);
+
+    self.appendEntries = function(entries) {
+      self.entries(self.entries().concat(entries));
+    };
+
+    self.loading = ko
+      .pureComputed(() => {
+        return (
+          self.loadingKeywords() ||
+          self.loadingFunctions() ||
+          self.loadingDatabases() ||
+          self.loadingTables() ||
+          self.loadingColumns() ||
+          self.loadingValues() ||
+          self.loadingPaths() ||
+          self.loadingJoins() ||
+          self.loadingJoinConditions() ||
+          self.loadingAggregateFunctions() ||
+          self.loadingGroupBys() ||
+          self.loadingOrderBys() ||
+          self.loadingFilters() ||
+          self.loadingPopularTables() ||
+          self.loadingPopularColumns()
+        );
+      })
+      .extend({ rateLimit: 200 });
+
+    self.filter = ko.observable();
+
+    self.availableCategories = ko.observableArray([CATEGORIES.ALL]);
+
+    self.availableCategories.subscribe(newCategories => {
+      if (newCategories.indexOf(self.activeCategory()) === -1) {
+        self.activeCategory(CATEGORIES.ALL);
+      }
+    });
+
+    self.activeCategory = ko.observable(CATEGORIES.ALL);
+
+    const updateCategories = function(suggestions) {
+      const newCategories = {};
+      suggestions.forEach(suggestion => {
+        if (suggestion.popular() && !newCategories[CATEGORIES.POPULAR.label]) {
+          newCategories[CATEGORIES.POPULAR.label] = CATEGORIES.POPULAR;
+        } else if (
+          suggestion.category === CATEGORIES.TABLE ||
+          suggestion.category === CATEGORIES.COLUMN ||
+          suggestion.category === CATEGORIES.UDF
+        ) {
+          if (!newCategories[suggestion.category.label]) {
+            newCategories[suggestion.category.label] = suggestion.category;
+          }
+        }
+      });
+      const result = [];
+      Object.keys(newCategories).forEach(key => {
+        result.push(newCategories[key]);
+      });
+      result.sort((a, b) => {
+        return a.label.localeCompare(b.label);
+      });
+      result.unshift(CATEGORIES.ALL);
+      self.availableCategories(result);
+    };
+
+    self.filtered = ko
+      .pureComputed(() => {
+        let result = self.entries();
+
+        if (self.filter()) {
+          result = sqlUtils.autocompleteFilter(self.filter(), result);
+          huePubSub.publish('hue.ace.autocompleter.match.updated');
+        }
+
+        updateCategories(result);
+
+        const activeCategory = self.activeCategory();
+
+        const categoriesCount = {};
+
+        result = result.filter(suggestion => {
+          if (typeof categoriesCount[suggestion.category.id] === 'undefined') {
+            categoriesCount[suggestion.category.id] = 0;
+          } else {
+            categoriesCount[suggestion.category.id]++;
+          }
+          if (
+            activeCategory !== CATEGORIES.POPULAR &&
+            categoriesCount[suggestion.category.id] >= 10 &&
+            POPULAR_CATEGORIES.indexOf(suggestion.category) !== -1
+          ) {
+            return false;
+          }
+          return (
+            activeCategory === CATEGORIES.ALL ||
+            activeCategory === suggestion.category ||
+            (activeCategory === CATEGORIES.POPULAR && suggestion.popular())
+          );
+        });
+
+        sqlUtils.sortSuggestions(result, self.filter(), self.sortOverride);
+        self.sortOverride = null;
+        return result;
+      })
+      .extend({ rateLimit: 200 });
+  }
+
+  cancelRequests() {
+    const self = this;
+
+    while (self.lastKnownRequests.length) {
+      apiHelper.cancelActiveRequest(self.lastKnownRequests.pop());
+    }
+
+    while (self.cancellablePromises.length) {
+      const promise = self.cancellablePromises.pop();
+      if (promise.cancel) {
+        promise.cancel();
+      }
+    }
+  }
+
+  update(parseResult) {
+    const self = this;
+
+    while (self.activeDeferrals.length > 0) {
+      self.activeDeferrals.pop().reject();
+    }
+
+    self.activeDatabase = parseResult.useDatabase || self.snippet.database();
+    self.parseResult = parseResult;
+
+    self.entries([]);
+
+    self.loadingKeywords(false);
+    self.loadingFunctions(false);
+    self.loadingDatabases(false);
+    self.loadingTables(false);
+    self.loadingColumns(false);
+    self.loadingValues(false);
+    self.loadingPaths(false);
+    self.loadingJoins(false);
+    self.loadingJoinConditions(false);
+    self.loadingAggregateFunctions(false);
+    self.loadingGroupBys(false);
+    self.loadingOrderBys(false);
+    self.loadingFilters(false);
+    self.loadingPopularTables(false);
+    self.loadingPopularColumns(false);
+
+    self.filter('');
+
+    const colRefDeferred = self.handleColumnReference();
+    self.activeDeferrals.push(colRefDeferred);
+    const databasesDeferred = self.loadDatabases();
+    self.activeDeferrals.push(databasesDeferred);
+
+    self.handleKeywords(colRefDeferred);
+    self.handleIdentifiers();
+    self.handleColumnAliases();
+    self.handleCommonTableExpressions();
+    self.handleOptions();
+    self.handleFunctions(colRefDeferred);
+    self.handleDatabases(databasesDeferred);
+    const tablesDeferred = self.handleTables(databasesDeferred);
+    self.activeDeferrals.push(tablesDeferred);
+    const columnsDeferred = self.handleColumns(colRefDeferred, tablesDeferred);
+    self.activeDeferrals.push(columnsDeferred);
+    self.handleValues(colRefDeferred);
+    self.activeDeferrals.push(self.handlePaths());
+
+    if (!self.temporaryOnly) {
+      self.activeDeferrals.push(self.handleJoins());
+      self.activeDeferrals.push(self.handleJoinConditions());
+      self.activeDeferrals.push(self.handleAggregateFunctions());
+      self.activeDeferrals.push(self.handleGroupBys(columnsDeferred));
+      self.activeDeferrals.push(self.handleOrderBys(columnsDeferred));
+      self.activeDeferrals.push(self.handleFilters());
+      self.activeDeferrals.push(self.handlePopularTables(tablesDeferred));
+      self.activeDeferrals.push(self.handlePopularColumns(columnsDeferred));
+    }
+
+    $.when.apply($, self.activeDeferrals).always(() => {
+      huePubSub.publish('hue.ace.autocompleter.done');
+    });
+  }
+
+  /**
+   * For some suggestions the column type is needed, for instance with functions we should only suggest
+   * columns that matches the argument type, cos(|) etc.
+   *
+   * The deferred will always resolve, and the default values is { type: 'T' }
+   *
+   * @returns {object} - jQuery Deferred
+   */
+  handleColumnReference() {
+    const self = this;
+    const colRefDeferred = $.Deferred();
+    if (self.parseResult.colRef) {
+      const colRefCallback = function(catalogEntry) {
+        self.cancellablePromises.push(
+          catalogEntry
+            .getSourceMeta({ silenceErrors: true, cancellable: true })
+            .done(sourceMeta => {
+              if (typeof sourceMeta.type !== 'undefined') {
+                colRefDeferred.resolve(sourceMeta);
+              } else {
+                colRefDeferred.resolve({ type: 'T' });
+              }
+            })
+            .fail(() => {
+              colRefDeferred.resolve({ type: 'T' });
+            })
+        );
+      };
+
+      const foundVarRef = self.parseResult.colRef.identifierChain.some(identifier => {
+        return typeof identifier.name !== 'undefined' && identifier.name.indexOf('${') === 0;
+      });
+
+      if (foundVarRef) {
+        colRefDeferred.resolve({ type: 'T' });
+      } else {
+        self
+          .fetchFieldsForIdentifiers(self.parseResult.colRef.identifierChain)
+          .done(colRefCallback)
+          .fail(() => {
+            colRefDeferred.resolve({ type: 'T' });
+          });
+      }
+    } else {
+      colRefDeferred.resolve({ type: 'T' });
+    }
+    return colRefDeferred;
+  }
+
+  loadDatabases() {
+    const self = this;
+    const databasesDeferred = $.Deferred();
+    dataCatalog
+      .getEntry({
+        sourceType: self.snippet.type(),
+        namespace: self.snippet.namespace(),
+        compute: self.snippet.compute(),
+        path: [],
+        temporaryOnly: self.temporaryOnly
+      })
+      .done(entry => {
+        self.cancellablePromises.push(
+          entry
+            .getChildren({ silenceErrors: true, cancellable: true })
+            .done(databases => {
+              databasesDeferred.resolve(databases);
+            })
+            .fail(databasesDeferred.reject)
+        );
+      })
+      .fail(databasesDeferred.reject);
+    return databasesDeferred;
+  }
+
+  handleKeywords(colRefDeferred) {
+    const self = this;
+    if (self.parseResult.suggestKeywords) {
+      const keywordSuggestions = $.map(self.parseResult.suggestKeywords, keyword => {
+        return {
+          value: self.parseResult.lowerCase ? keyword.value.toLowerCase() : keyword.value,
+          meta: window.HUE_I18n.autocomplete.meta.keyword,
+          category: CATEGORIES.KEYWORD,
+          weightAdjust: keyword.weight,
+          popular: ko.observable(false),
+          details: null
+        };
+      });
+      self.appendEntries(keywordSuggestions);
+    }
+
+    if (self.parseResult.suggestColRefKeywords) {
+      initLoading(self.loadingKeywords, colRefDeferred);
+      // Wait for the column reference type to be resolved to pick the right keywords
+      colRefDeferred.done(colRef => {
+        const colRefKeywordSuggestions = [];
+        Object.keys(self.parseResult.suggestColRefKeywords).forEach(typeForKeywords => {
+          if (
+            SqlFunctions.matchesType(
+              self.snippet.type(),
+              [typeForKeywords],
+              [colRef.type.toUpperCase()]
+            )
+          ) {
+            self.parseResult.suggestColRefKeywords[typeForKeywords].forEach(keyword => {
+              colRefKeywordSuggestions.push({
+                value: self.parseResult.lowerCase ? keyword.toLowerCase() : keyword,
+                meta: window.HUE_I18n.autocomplete.meta.keyword,
+                category: CATEGORIES.COLREF_KEYWORD,
+                popular: ko.observable(false),
+                details: {
+                  type: colRef.type
+                }
+              });
+            });
+          }
+        });
+        self.appendEntries(colRefKeywordSuggestions);
+      });
+    }
+  }
+
+  handleIdentifiers() {
+    const self = this;
+    if (self.parseResult.suggestIdentifiers) {
+      const identifierSuggestions = [];
+      self.parseResult.suggestIdentifiers.forEach(identifier => {
+        identifierSuggestions.push({
+          value: identifier.name,
+          meta: identifier.type,
+          category: CATEGORIES.IDENTIFIER,
+          popular: ko.observable(false),
+          details: null
+        });
+      });
+      self.appendEntries(identifierSuggestions);
+    }
+  }
+
+  handleColumnAliases() {
+    const self = this;
+    if (self.parseResult.suggestColumnAliases) {
+      const columnAliasSuggestions = [];
+      self.parseResult.suggestColumnAliases.forEach(columnAlias => {
+        const type =
+          columnAlias.types && columnAlias.types.length === 1 ? columnAlias.types[0] : 'T';
+        if (type === 'COLREF') {
+          columnAliasSuggestions.push({
+            value: columnAlias.name,
+            meta: window.HUE_I18n.autocomplete.meta.alias,
+            category: CATEGORIES.COLUMN,
+            popular: ko.observable(false),
+            details: columnAlias
+          });
+        } else {
+          columnAliasSuggestions.push({
+            value: columnAlias.name,
+            meta: type,
+            category: CATEGORIES.COLUMN,
+            popular: ko.observable(false),
+            details: columnAlias
+          });
+        }
+      });
+      self.appendEntries(columnAliasSuggestions);
+    }
+  }
+
+  handleCommonTableExpressions() {
+    const self = this;
+    if (self.parseResult.suggestCommonTableExpressions) {
+      const commonTableExpressionSuggestions = [];
+      self.parseResult.suggestCommonTableExpressions.forEach(expression => {
+        let prefix = expression.prependQuestionMark ? '? ' : '';
+        if (expression.prependFrom) {
+          prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
+        }
+        commonTableExpressionSuggestions.push({
+          value: prefix + expression.name,
+          filterValue: expression.name,
+          meta: window.HUE_I18n.autocomplete.meta.commonTableExpression,
+          category: CATEGORIES.CTE,
+          popular: ko.observable(false),
+          details: null
+        });
+      });
+      self.appendEntries(commonTableExpressionSuggestions);
+    }
+  }
+
+  handleOptions() {
+    const self = this;
+    if (self.parseResult.suggestSetOptions) {
+      const suggestions = [];
+      SqlSetOptions.suggestOptions(self.snippet.type(), suggestions, CATEGORIES.OPTION);
+      self.appendEntries(suggestions);
+    }
+  }
+
+  handleFunctions(colRefDeferred) {
+    const self = this;
+    if (self.parseResult.suggestFunctions) {
+      const functionSuggestions = [];
+      if (
+        self.parseResult.suggestFunctions.types &&
+        self.parseResult.suggestFunctions.types[0] === 'COLREF'
+      ) {
+        initLoading(self.loadingFunctions, colRefDeferred);
+
+        colRefDeferred.done(colRef => {
+          const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
+            self.snippet.type(),
+            [colRef.type.toUpperCase()],
+            self.parseResult.suggestAggregateFunctions || false,
+            self.parseResult.suggestAnalyticFunctions || false
+          );
+
+          Object.keys(functionsToSuggest).forEach(name => {
+            functionSuggestions.push({
+              category: CATEGORIES.UDF,
+              value: name + '()',
+              meta: functionsToSuggest[name].returnTypes.join('|'),
+              weightAdjust:
+                colRef.type.toUpperCase() !== 'T' &&
+                functionsToSuggest[name].returnTypes.some(otherType => {
+                  return otherType === colRef.type.toUpperCase();
+                })
+                  ? 1
+                  : 0,
+              popular: ko.observable(false),
+              details: functionsToSuggest[name]
+            });
+          });
+
+          self.appendEntries(functionSuggestions);
+        });
+      } else {
+        const types = self.parseResult.suggestFunctions.types || ['T'];
+        const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
+          self.snippet.type(),
+          types,
+          self.parseResult.suggestAggregateFunctions || false,
+          self.parseResult.suggestAnalyticFunctions || false
+        );
+
+        Object.keys(functionsToSuggest).forEach(name => {
+          functionSuggestions.push({
+            category: CATEGORIES.UDF,
+            value: name + '()',
+            meta: functionsToSuggest[name].returnTypes.join('|'),
+            weightAdjust:
+              types[0].toUpperCase() !== 'T' &&
+              functionsToSuggest[name].returnTypes.some(otherType => {
+                return otherType === types[0].toUpperCase();
+              })
+                ? 1
+                : 0,
+            popular: ko.observable(false),
+            details: functionsToSuggest[name]
+          });
+        });
+        self.appendEntries(functionSuggestions);
+      }
+    }
+  }
+
+  handleDatabases(databasesDeferred) {
+    const self = this;
+    const suggestDatabases = self.parseResult.suggestDatabases;
+    if (suggestDatabases) {
+      initLoading(self.loadingDatabases, databasesDeferred);
+
+      let prefix = suggestDatabases.prependQuestionMark ? '? ' : '';
+      if (suggestDatabases.prependFrom) {
+        prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
+      }
+      const databaseSuggestions = [];
+
+      databasesDeferred.done(catalogEntries => {
+        catalogEntries.forEach(dbEntry => {
+          databaseSuggestions.push({
+            value:
+              prefix +
+              sqlUtils.backTickIfNeeded(self.snippet.type(), dbEntry.name) +
+              (suggestDatabases.appendDot ? '.' : ''),
+            filterValue: dbEntry.name,
+            meta: window.HUE_I18n.autocomplete.meta.database,
+            category: CATEGORIES.DATABASE,
+            popular: ko.observable(false),
+            hasCatalogEntry: true,
+            details: dbEntry
+          });
+        });
+        self.appendEntries(databaseSuggestions);
+      });
+    }
+  }
+
+  handleTables(databasesDeferred) {
+    const self = this;
+    const tablesDeferred = $.Deferred();
+
+    if (self.parseResult.suggestTables) {
+      const suggestTables = self.parseResult.suggestTables;
+      const fetchTables = function() {
+        initLoading(self.loadingTables, tablesDeferred);
+        tablesDeferred.done(self.appendEntries);
+
+        let prefix = suggestTables.prependQuestionMark ? '? ' : '';
+        if (suggestTables.prependFrom) {
+          prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
+        }
+
+        const database =
+          suggestTables.identifierChain && suggestTables.identifierChain.length === 1
+            ? suggestTables.identifierChain[0].name
+            : self.activeDatabase;
+
+        dataCatalog
+          .getEntry({
+            sourceType: self.snippet.type(),
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            path: [database],
+            temporaryOnly: self.temporaryOnly
+          })
+          .done(dbEntry => {
+            self.cancellablePromises.push(
+              dbEntry
+                .getChildren({ silenceErrors: true, cancellable: true })
+                .done(tableEntries => {
+                  const tableSuggestions = [];
+
+                  tableEntries.forEach(tableEntry => {
+                    if (
+                      (suggestTables.onlyTables && !tableEntry.isTable()) ||
+                      (suggestTables.onlyViews && !tableEntry.isView())
+                    ) {
+                      return;
+                    }
+                    tableSuggestions.push({
+                      value:
+                        prefix + sqlUtils.backTickIfNeeded(self.snippet.type(), tableEntry.name),
+                      filterValue: tableEntry.name,
+                      tableName: tableEntry.name,
+                      meta: window.HUE_I18n.autocomplete.meta[tableEntry.getType().toLowerCase()],
+                      category: CATEGORIES.TABLE,
+                      popular: ko.observable(false),
+                      hasCatalogEntry: true,
+                      details: tableEntry
+                    });
+                  });
+                  tablesDeferred.resolve(tableSuggestions);
+                })
+                .fail(tablesDeferred.reject)
+            );
+          })
+          .fail(tablesDeferred.reject);
+      };
+
+      if (
+        self.snippet.type() === 'impala' &&
+        self.parseResult.suggestTables.identifierChain &&
+        self.parseResult.suggestTables.identifierChain.length === 1
+      ) {
+        databasesDeferred.done(databases => {
+          const foundDb = databases.some(dbEntry => {
+            return hueUtils.equalIgnoreCase(
+              dbEntry.name,
+              self.parseResult.suggestTables.identifierChain[0].name
+            );
+          });
+          if (foundDb) {
+            fetchTables();
+          } else {
+            self.parseResult.suggestColumns = {
+              tables: [{ identifierChain: self.parseResult.suggestTables.identifierChain }]
+            };
+            tablesDeferred.reject();
+          }
+        });
+      } else if (
+        self.snippet.type() === 'impala' &&
+        self.parseResult.suggestTables.identifierChain &&
+        self.parseResult.suggestTables.identifierChain.length > 1
+      ) {
+        self.parseResult.suggestColumns = {
+          tables: [{ identifierChain: self.parseResult.suggestTables.identifierChain }]
+        };
+        tablesDeferred.reject();
+      } else {
+        fetchTables();
+      }
+    } else {
+      tablesDeferred.reject();
+    }
+
+    return tablesDeferred;
+  }
+
+  handleColumns(colRefDeferred, tablesDeferred) {
+    const self = this;
+    const columnsDeferred = $.Deferred();
+
+    tablesDeferred.always(() => {
+      if (self.parseResult.suggestColumns) {
+        initLoading(self.loadingColumns, columnsDeferred);
+        columnsDeferred.done(self.appendEntries);
+
+        const suggestColumns = self.parseResult.suggestColumns;
+        const columnSuggestions = [];
+        // For multiple tables we need to merge and make sure identifiers are unique
+        const columnDeferrals = [];
+
+        const waitForCols = function() {
+          $.when.apply($, columnDeferrals).always(() => {
+            AutocompleteResults.mergeColumns(columnSuggestions);
+            if (
+              self.snippet.type() === 'hive' &&
+              /[^.]$/.test(self.editor().getTextBeforeCursor())
+            ) {
+              columnSuggestions.push({
+                value: 'BLOCK__OFFSET__INSIDE__FILE',
+                meta: window.HUE_I18n.autocomplete.meta.virtual,
+                category: CATEGORIES.VIRTUAL_COLUMN,
+                popular: ko.observable(false),
+                details: { name: 'BLOCK__OFFSET__INSIDE__FILE' }
+              });
+              columnSuggestions.push({
+                value: 'INPUT__FILE__NAME',
+                meta: window.HUE_I18n.autocomplete.meta.virtual,
+                category: CATEGORIES.VIRTUAL_COLUMN,
+                popular: ko.observable(false),
+                details: { name: 'INPUT__FILE__NAME' }
+              });
+            }
+            columnsDeferred.resolve(columnSuggestions);
+          });
+        };
+
+        if (suggestColumns.types && suggestColumns.types[0] === 'COLREF') {
+          colRefDeferred.done(colRef => {
+            suggestColumns.tables.forEach(table => {
+              columnDeferrals.push(
+                self.addColumns(table, [colRef.type.toUpperCase()], columnSuggestions)
+              );
+            });
+            waitForCols();
+          });
+        } else {
+          suggestColumns.tables.forEach(table => {
+            columnDeferrals.push(
+              self.addColumns(table, suggestColumns.types || ['T'], columnSuggestions)
+            );
+          });
+          waitForCols();
+        }
+      } else {
+        columnsDeferred.reject();
+      }
+    });
+
+    return columnsDeferred;
+  }
+
+  addColumns(table, types, columnSuggestions) {
+    const self = this;
+    const addColumnsDeferred = $.Deferred();
+
+    if (
+      typeof table.identifierChain !== 'undefined' &&
+      table.identifierChain.length === 1 &&
+      typeof table.identifierChain[0].cte !== 'undefined'
+    ) {
+      if (
+        typeof self.parseResult.commonTableExpressions !== 'undefined' &&
+        self.parseResult.commonTableExpressions.length > 0
+      ) {
+        self.parseResult.commonTableExpressions.every(cte => {
+          if (hueUtils.equalIgnoreCase(cte.alias, table.identifierChain[0].cte)) {
+            cte.columns.forEach(column => {
+              const type =
+                typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
+              if (typeof column.alias !== 'undefined') {
+                columnSuggestions.push({
+                  value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
+                  filterValue: column.alias,
+                  meta: type,
+                  category: CATEGORIES.COLUMN,
+                  table: table,
+                  popular: ko.observable(false),
+                  details: column
+                });
+              } else if (
+                typeof column.identifierChain !== 'undefined' &&
+                column.identifierChain.length > 0 &&
+                typeof column.identifierChain[column.identifierChain.length - 1].name !==
+                  'undefined'
+              ) {
+                columnSuggestions.push({
+                  value: sqlUtils.backTickIfNeeded(
+                    self.snippet.type(),
+                    column.identifierChain[column.identifierChain.length - 1].name
+                  ),
+                  filterValue: column.identifierChain[column.identifierChain.length - 1].name,
+                  meta: type,
+                  category: CATEGORIES.COLUMN,
+                  table: table,
+                  popular: ko.observable(false),
+                  details: column
+                });
+              }
+            });
+            return false;
+          }
+          return true;
+        });
+      }
+      addColumnsDeferred.resolve();
+    } else if (
+      typeof table.identifierChain !== 'undefined' &&
+      table.identifierChain.length === 1 &&
+      typeof table.identifierChain[0].subQuery !== 'undefined'
+    ) {
+      const foundSubQuery = locateSubQuery(
+        self.parseResult.subQueries,
+        table.identifierChain[0].subQuery
+      );
+
+      const addSubQueryColumns = function(subQueryColumns) {
+        subQueryColumns.forEach(column => {
+          if (column.alias || column.identifierChain) {
+            // TODO: Potentially fetch column types for sub-queries, possible performance hit.
+            const type =
+              typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
+            if (column.alias) {
+              columnSuggestions.push({
+                value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
+                filterValue: column.alias,
+                meta: type,
+                category: CATEGORIES.COLUMN,
+                table: table,
+                popular: ko.observable(false),
+                details: column
+              });
+            } else if (column.identifierChain && column.identifierChain.length > 0) {
+              columnSuggestions.push({
+                value: sqlUtils.backTickIfNeeded(
+                  self.snippet.type(),
+                  column.identifierChain[column.identifierChain.length - 1].name
+                ),
+                filterValue: column.identifierChain[column.identifierChain.length - 1].name,
+                meta: type,
+                category: CATEGORIES.COLUMN,
+                table: table,
+                popular: ko.observable(false),
+                details: column
+              });
+            }
+          } else if (column.subQuery && foundSubQuery.subQueries) {
+            const foundNestedSubQuery = locateSubQuery(foundSubQuery.subQueries, column.subQuery);
+            if (foundNestedSubQuery !== null) {
+              addSubQueryColumns(foundNestedSubQuery.columns);
+            }
+          }
+        });
+      };
+      if (foundSubQuery !== null && foundSubQuery.columns.length > 0) {
+        addSubQueryColumns(foundSubQuery.columns);
+      }
+      addColumnsDeferred.resolve();
+    } else if (typeof table.identifierChain !== 'undefined') {
+      const addColumnsFromEntry = function(dataCatalogEntry) {
+        self.cancellablePromises.push(
+          dataCatalogEntry
+            .getSourceMeta({ silenceErrors: true, cancellable: true })
+            .done(sourceMeta => {
+              self.cancellablePromises.push(
+                dataCatalogEntry
+                  .getChildren({ silenceErrors: true, cancellable: true })
+                  .done(childEntries => {
+                    childEntries.forEach(childEntry => {
+                      let name = sqlUtils.backTickIfNeeded(self.snippet.type(), childEntry.name);
+                      if (
+                        self.snippet.type() === 'hive' &&
+                        (childEntry.isArray() || childEntry.isMap())
+                      ) {
+                        name += '[]';
+                      }
+                      if (
+                        SqlFunctions.matchesType(self.snippet.type(), types, [
+                          childEntry.getType().toUpperCase()
+                        ]) ||
+                        SqlFunctions.matchesType(
+                          self.snippet.type(),
+                          [childEntry.getType().toUpperCase()],
+                          types
+                        ) ||
+                        childEntry.getType === 'column' ||
+                        childEntry.isComplex()
+                      ) {
+                        columnSuggestions.push({
+                          value: name,
+                          meta: childEntry.getType(),
+                          table: table,
+                          category: CATEGORIES.COLUMN,
+                          popular: ko.observable(false),
+                          weightAdjust:
+                            types[0].toUpperCase() !== 'T' &&
+                            types.some(type => {
+                              return hueUtils.equalIgnoreCase(type, childEntry.getType());
+                            })
+                              ? 1
+                              : 0,
+                          hasCatalogEntry: true,
+                          details: childEntry
+                        });
+                      }
+                    });
+                    if (
+                      self.snippet.type() === 'hive' &&
+                      (dataCatalogEntry.isArray() || dataCatalogEntry.isMap())
+                    ) {
+                      // Remove 'item' or 'value' and 'key' for Hive
+                      columnSuggestions.pop();
+                      if (dataCatalogEntry.isMap()) {
+                        columnSuggestions.pop();
+                      }
+                    }
+
+                    const complexExtras =
+                      (sourceMeta.value && sourceMeta.value.fields) ||
+                      (sourceMeta.item && sourceMeta.item.fields);
+                    if (
+                      (self.snippet.type() === 'impala' || self.snippet.type() === 'hive') &&
+                      complexExtras
+                    ) {
+                      complexExtras.forEach(field => {
+                        const fieldType =
+                          field.type.indexOf('<') !== -1
+                            ? field.type.substring(0, field.type.indexOf('<'))
+                            : field.type;
+                        columnSuggestions.push({
+                          value: field.name,
+                          meta: fieldType,
+                          table: table,
+                          category: CATEGORIES.COLUMN,
+                          popular: ko.observable(false),
+                          weightAdjust:
+                            types[0].toUpperCase() !== 'T' &&
+                            types.some(type => {
+                              return hueUtils.equalIgnoreCase(type, fieldType);
+                            })
+                              ? 1
+                              : 0,
+                          hasCatalogEntry: false,
+                          details: field
+                        });
+                      });
+                    }
+                    addColumnsDeferred.resolve();
+                  })
+                  .fail(addColumnsDeferred.reject)
+              );
+            })
+            .fail(addColumnsDeferred.reject)
+        );
+      };
+
+      if (self.parseResult.suggestColumns && self.parseResult.suggestColumns.identifierChain) {
+        self
+          .fetchFieldsForIdentifiers(
+            table.identifierChain.concat(self.parseResult.suggestColumns.identifierChain)
+          )
+          .done(addColumnsFromEntry)
+          .fail(addColumnsDeferred.reject);
+      } else {
+        self
+          .fetchFieldsForIdentifiers(table.identifierChain)
+          .done(addColumnsFromEntry)
+          .fail(addColumnsDeferred.reject);
+      }
+    } else {
+      addColumnsDeferred.resolve();
+    }
+    return addColumnsDeferred;
+  }
+
+  static mergeColumns(columnSuggestions) {
+    columnSuggestions.sort((a, b) => {
+      return a.value.localeCompare(b.value);
+    });
+
+    for (let i = 0; i < columnSuggestions.length; i++) {
+      const suggestion = columnSuggestions[i];
+      suggestion.isColumn = true;
+      let hasDuplicates = false;
+      for (
+        i;
+        i + 1 < columnSuggestions.length && columnSuggestions[i + 1].value === suggestion.value;
+        i++
+      ) {
+        const nextTable = columnSuggestions[i + 1].table;
+        if (typeof nextTable.alias !== 'undefined') {
+          columnSuggestions[i + 1].value = nextTable.alias + '.' + columnSuggestions[i + 1].value;
+        } else if (
+          typeof nextTable.identifierChain !== 'undefined' &&
+          nextTable.identifierChain.length > 0
+        ) {
+          const previousIdentifier =
+            nextTable.identifierChain[nextTable.identifierChain.length - 1];
+          if (typeof previousIdentifier.name !== 'undefined') {
+            columnSuggestions[i + 1].value =
+              previousIdentifier.name + '.' + columnSuggestions[i + 1].value;
+          } else if (typeof previousIdentifier.subQuery !== 'undefined') {
+            columnSuggestions[i + 1].value =
+              previousIdentifier.subQuery + '.' + columnSuggestions[i + 1].value;
+          }
+        }
+        hasDuplicates = true;
+      }
+      if (typeof suggestion.table.alias !== 'undefined') {
+        suggestion.value = suggestion.table.alias + '.' + suggestion.value;
+      } else if (
+        hasDuplicates &&
+        typeof suggestion.table.identifierChain !== 'undefined' &&
+        suggestion.table.identifierChain.length > 0
+      ) {
+        const lastIdentifier =
+          suggestion.table.identifierChain[suggestion.table.identifierChain.length - 1];
+        if (typeof lastIdentifier.name !== 'undefined') {
+          suggestion.value = lastIdentifier.name + '.' + suggestion.value;
+        } else if (typeof lastIdentifier.subQuery !== 'undefined') {
+          suggestion.value = lastIdentifier.subQuery + '.' + suggestion.value;
+        }
+      }
+    }
+  }
+
+  handleValues(colRefDeferred) {
+    const self = this;
+    const suggestValues = self.parseResult.suggestValues;
+    if (suggestValues) {
+      const valueSuggestions = [];
+      if (self.parseResult.colRef && self.parseResult.colRef.identifierChain) {
+        valueSuggestions.push({
+          value:
+            '${' +
+            self.parseResult.colRef.identifierChain[
+              self.parseResult.colRef.identifierChain.length - 1
+            ].name +
+            '}',
+          meta: window.HUE_I18n.autocomplete.meta.variable,
+          category: CATEGORIES.VARIABLE,
+          popular: ko.observable(false),
+          details: null
+        });
+      }
+      colRefDeferred.done(colRef => {
+        if (colRef.sample) {
+          const isString = colRef.type === 'string';
+          const startQuote = suggestValues.partialQuote ? '' : "'";
+          const endQuote =
+            typeof suggestValues.missingEndQuote !== 'undefined' &&
+            suggestValues.missingEndQuote === false
+              ? ''
+              : suggestValues.partialQuote || "'";
+          colRef.sample.forEach(sample => {
+            valueSuggestions.push({
+              value: isString ? startQuote + sample + endQuote : new String(sample),
+              meta: window.HUE_I18n.autocomplete.meta.sample,
+              category: CATEGORIES.SAMPLE,
+              popular: ko.observable(false),
+              details: null
+            });
+          });
+        }
+        self.appendEntries(valueSuggestions);
+      });
+    }
+  }
+
+  handlePaths() {
+    const self = this;
+    const suggestHdfs = self.parseResult.suggestHdfs;
+    const pathsDeferred = $.Deferred();
+
+    if (suggestHdfs) {
+      initLoading(self.loadingPaths, pathsDeferred);
+      pathsDeferred.done(self.appendEntries);
+
+      let path = suggestHdfs.path;
+      if (path === '') {
+        self.appendEntries([
+          {
+            value: 'adl://',
+            meta: window.HUE_I18n.autocomplete.meta.keyword,
+            category: CATEGORIES.KEYWORD,
+            weightAdjust: 0,
+            popular: ko.observable(false),
+            details: null
+          },
+          {
+            value: 's3a://',
+            meta: window.HUE_I18n.autocomplete.meta.keyword,
+            category: CATEGORIES.KEYWORD,
+            weightAdjust: 0,
+            popular: ko.observable(false),
+            details: null
+          },
+          {
+            value: 'hdfs://',
+            meta: window.HUE_I18n.autocomplete.meta.keyword,
+            category: CATEGORIES.KEYWORD,
+            weightAdjust: 0,
+            popular: ko.observable(false),
+            details: null
+          },
+          {
+            value: '/',
+            meta: 'dir',
+            category: CATEGORIES.HDFS,
+            popular: ko.observable(false),
+            details: null
+          }
+        ]);
+      }
+
+      let fetchFunction = 'fetchHdfsPath';
+
+      if (/^s3a:\/\//i.test(path)) {
+        fetchFunction = 'fetchS3Path';
+        path = path.substring(5);
+      } else if (/^adl:\/\//i.test(path)) {
+        fetchFunction = 'fetchAdlsPath';
+        path = path.substring(5);
+      } else if (/^hdfs:\/\//i.test(path)) {
+        path = path.substring(6);
+      }
+
+      const parts = path.split('/');
+      // Drop the first " or '
+      parts.shift();
+      // Last one is either partial name or empty
+      parts.pop();
+
+      self.lastKnownRequests.push(
+        apiHelper[fetchFunction]({
+          pathParts: parts,
+          successCallback: function(data) {
+            if (!data.error) {
+              const pathSuggestions = [];
+              data.files.forEach(file => {
+                if (file.name !== '..' && file.name !== '.') {
+                  pathSuggestions.push({
+                    value: path === '' ? '/' + file.name : file.name,
+                    meta: file.type,
+                    category: CATEGORIES.HDFS,
+                    popular: ko.observable(false),
+                    details: file
+                  });
+                }
+              });
+              pathsDeferred.resolve(pathSuggestions);
+            }
+            pathsDeferred.reject();
+          },
+          silenceErrors: true,
+          errorCallback: pathsDeferred.reject,
+          timeout: AUTOCOMPLETE_TIMEOUT
+        })
+      );
+    } else {
+      pathsDeferred.reject();
+    }
+    return pathsDeferred;
+  }
+
+  tableIdentifierChainsToPaths(tables) {
+    const self = this;
+    const paths = [];
+    tables.forEach(table => {
+      // Could be subquery
+      const isTable = table.identifierChain.every(identifier => {
+        return typeof identifier.name !== 'undefined';
+      });
+      if (isTable) {
+        const path = $.map(table.identifierChain, identifier => {
+          return identifier.name;
+        });
+        if (path.length === 1) {
+          path.unshift(self.activeDatabase);
+        }
+        paths.push(path);
+      }
+    });
+    return paths;
+  }
+
+  handleJoins() {
+    const self = this;
+    const joinsDeferred = $.Deferred();
+    const suggestJoins = self.parseResult.suggestJoins;
+    if (window.HAS_OPTIMIZER && suggestJoins) {
+      initLoading(self.loadingJoins, joinsDeferred);
+      joinsDeferred.done(self.appendEntries);
+
+      const paths = self.tableIdentifierChainsToPaths(suggestJoins.tables);
+      if (paths.length) {
+        dataCatalog
+          .getMultiTableEntry({
+            sourceType: self.snippet.type(),
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            paths: paths
+          })
+          .done(multiTableEntry => {
+            self.cancellablePromises.push(
+              multiTableEntry
+                .getTopJoins({ silenceErrors: true, cancellable: true })
+                .done(topJoins => {
+                  const joinSuggestions = [];
+                  let totalCount = 0;
+                  if (topJoins.values) {
+                    topJoins.values.forEach(value => {
+                      let joinType = value.joinType || 'join';
+                      joinType += ' ';
+                      let suggestionString = suggestJoins.prependJoin
+                        ? self.parseResult.lowerCase
+                          ? joinType.toLowerCase()
+                          : joinType.toUpperCase()
+                        : '';
+                      let first = true;
+
+                      const existingTables = {};
+                      suggestJoins.tables.forEach(table => {
+                        existingTables[
+                          table.identifierChain[table.identifierChain.length - 1].name
+                        ] = true;
+                      });
+
+                      let joinRequired = false;
+                      let tablesAdded = false;
+                      value.tables.forEach(table => {
+                        const tableParts = table.split('.');
+                        if (!existingTables[tableParts[tableParts.length - 1]]) {
+                          tablesAdded = true;
+                          const identifier = self.convertNavOptQualifiedIdentifier(
+                            table,
+                            suggestJoins.tables
+                          );
+                          suggestionString += joinRequired
+                            ? (self.parseResult.lowerCase ? ' join ' : ' JOIN ') + identifier
+                            : identifier;
+                          joinRequired = true;
+                        }
+                      });
+
+                      if (value.joinCols.length > 0) {
+                        if (!tablesAdded && suggestJoins.prependJoin) {
+                          suggestionString = '';
+                          tablesAdded = true;
+                        }
+                        suggestionString += self.parseResult.lowerCase ? ' on ' : ' ON ';
+                      }
+                      if (tablesAdded) {
+                        value.joinCols.forEach(joinColPair => {
+                          if (!first) {
+                            suggestionString += self.parseResult.lowerCase ? ' and ' : ' AND ';
+                          }
+                          suggestionString +=
+                            self.convertNavOptQualifiedIdentifier(
+                              joinColPair.columns[0],
+                              suggestJoins.tables,
+                              self.snippet.type()
+                            ) +
+                            ' = ' +
+                            self.convertNavOptQualifiedIdentifier(
+                              joinColPair.columns[1],
+                              suggestJoins.tables,
+                              self.snippet.type()
+                            );
+                          first = false;
+                        });
+                        totalCount += value.totalQueryCount;
+                        joinSuggestions.push({
+                          value: suggestionString,
+                          meta: window.HUE_I18n.autocomplete.meta.join,
+                          category: suggestJoins.prependJoin
+                            ? CATEGORIES.POPULAR_JOIN
+                            : CATEGORIES.POPULAR_ACTIVE_JOIN,
+                          popular: ko.observable(true),
+                          details: value
+                        });
+                      }
+                    });
+                    joinSuggestions.forEach(suggestion => {
+                      suggestion.details.relativePopularity =
+                        totalCount === 0
+                          ? suggestion.details.totalQueryCount
+                          : Math.round((100 * suggestion.details.totalQueryCount) / totalCount);
+                      suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
+                    });
+                  }
+                  joinsDeferred.resolve(joinSuggestions);
+                })
+                .fail(joinsDeferred.reject)
+            );
+          })
+          .fail(joinsDeferred.reject);
+      } else {
+        joinsDeferred.reject();
+      }
+    } else {
+      joinsDeferred.reject();
+    }
+    return joinsDeferred;
+  }
+
+  handleJoinConditions() {
+    const self = this;
+    const joinConditionsDeferred = $.Deferred();
+    const suggestJoinConditions = self.parseResult.suggestJoinConditions;
+    if (window.HAS_OPTIMIZER && suggestJoinConditions) {
+      initLoading(self.loadingJoinConditions, joinConditionsDeferred);
+      joinConditionsDeferred.done(self.appendEntries);
+
+      const paths = self.tableIdentifierChainsToPaths(suggestJoinConditions.tables);
+      if (paths.length) {
+        dataCatalog
+          .getMultiTableEntry({
+            sourceType: self.snippet.type(),
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            paths: paths
+          })
+          .done(multiTableEntry => {
+            self.cancellablePromises.push(
+              multiTableEntry
+                .getTopJoins({ silenceErrors: true, cancellable: true })
+                .done(topJoins => {
+                  const joinConditionSuggestions = [];
+                  let totalCount = 0;
+                  if (topJoins.values) {
+                    topJoins.values.forEach(value => {
+                      if (value.joinCols.length > 0) {
+                        let suggestionString = suggestJoinConditions.prependOn
+                          ? self.parseResult.lowerCase
+                            ? 'on '
+                            : 'ON '
+                          : '';
+                        let first = true;
+                        value.joinCols.forEach(joinColPair => {
+                          if (!first) {
+                            suggestionString += self.parseResult.lowerCase ? ' and ' : ' AND ';
+                          }
+                          suggestionString +=
+                            self.convertNavOptQualifiedIdentifier(
+                              joinColPair.columns[0],
+                              suggestJoinConditions.tables
+                            ) +
+                            ' = ' +
+                            self.convertNavOptQualifiedIdentifier(
+                              joinColPair.columns[1],
+                              suggestJoinConditions.tables
+                            );
+                          first = false;
+                        });
+                        totalCount += value.totalQueryCount;
+                        joinConditionSuggestions.push({
+                          value: suggestionString,
+                          meta: window.HUE_I18n.autocomplete.meta.joinCondition,
+                          category: CATEGORIES.POPULAR_JOIN_CONDITION,
+                          popular: ko.observable(true),
+                          details: value
+                        });
+                      }
+                    });
+                    joinConditionSuggestions.forEach(suggestion => {
+                      suggestion.details.relativePopularity =
+                        totalCount === 0
+                          ? suggestion.details.totalQueryCount
+                          : Math.round((100 * suggestion.details.totalQueryCount) / totalCount);
+                      suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
+                    });
+                  }
+
+                  joinConditionsDeferred.resolve(joinConditionSuggestions);
+                })
+                .fail(joinConditionsDeferred.reject)
+            );
+          })
+          .fail(joinConditionsDeferred.reject);
+      } else {
+        joinConditionsDeferred.reject();
+      }
+    } else {
+      joinConditionsDeferred.reject();
+    }
+
+    return joinConditionsDeferred;
+  }
+
+  handleAggregateFunctions() {
+    const self = this;
+    const aggregateFunctionsDeferred = $.Deferred();
+
+    const suggestAggregateFunctions = self.parseResult.suggestAggregateFunctions;
+    if (
+      window.HAS_OPTIMIZER &&
+      suggestAggregateFunctions &&
+      suggestAggregateFunctions.tables.length > 0
+    ) {
+      initLoading(self.loadingAggregateFunctions, aggregateFunctionsDeferred);
+      aggregateFunctionsDeferred.done(self.appendEntries);
+
+      const paths = self.tableIdentifierChainsToPaths(suggestAggregateFunctions.tables);
+      if (paths.length) {
+        dataCatalog
+          .getMultiTableEntry({
+            sourceType: self.snippet.type(),
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            paths: paths
+          })
+          .done(multiTableEntry => {
+            self.cancellablePromises.push(
+              multiTableEntry
+                .getTopAggs({ silenceErrors: true, cancellable: true })
+                .done(topAggs => {
+                  const aggregateFunctionsSuggestions = [];
+                  if (topAggs.values && topAggs.values.length > 0) {
+                    // Expand all column names to the fully qualified name including db and table.
+                    topAggs.values.forEach(value => {
+                      value.aggregateInfo.forEach(info => {
+                        value.aggregateClause = value.aggregateClause.replace(
+                          new RegExp('([^.])' + info.columnName, 'gi'),
+                          '$1' + info.databaseName + '.' + info.tableName + '.' + info.columnName
+                        );
+                      });
+                    });
+
+                    // Substitute qualified table identifiers with either alias or table when multiple tables are present or just empty string
+                    const substitutions = [];
+                    suggestAggregateFunctions.tables.forEach(table => {
+                      const replaceWith = table.alias
+                        ? table.alias + '.'
+                        : suggestAggregateFunctions.tables.length > 1
+                        ? table.identifierChain[table.identifierChain.length - 1].name + '.'
+                        : '';
+                      if (table.identifierChain.length > 1) {
+                        substitutions.push({
+                          replace: new RegExp(
+                            $.map(table.identifierChain, identifier => {
+                              return identifier.name;
+                            }).join('.') + '.',
+                            'gi'
+                          ),
+                          with: replaceWith
+                        });
+                      } else if (table.identifierChain.length === 1) {
+                        substitutions.push({
+                          replace: new RegExp(
+                            self.activeDatabase + '.' + table.identifierChain[0].name + '.',
+                            'gi'
+                          ),
+                          with: replaceWith
+                        });
+                        substitutions.push({
+                          replace: new RegExp(table.identifierChain[0].name + '.', 'gi'),
+                          with: replaceWith
+                        });
+                      }
+                    });
+
+                    let totalCount = 0;
+                    topAggs.values.forEach(value => {
+                      let clean = value.aggregateClause;
+                      substitutions.forEach(substitution => {
+                        clean = clean.replace(substitution.replace, substitution.with);
+                      });
+                      totalCount += value.totalQueryCount;
+                      value.function = SqlFunctions.findFunction(
+                        self.snippet.type(),
+                        value.aggregateFunction
+                      );
+                      aggregateFunctionsSuggestions.push({
+                        value: clean,
+                        meta: value.function.returnTypes.join('|'),
+                        category: CATEGORIES.POPULAR_AGGREGATE,
+                        weightAdjust: Math.min(value.totalQueryCount, 99),
+                        popular: ko.observable(true),
+                        details: value
+                      });
+                    });
+
+                    aggregateFunctionsSuggestions.forEach(suggestion => {
+                      suggestion.details.relativePopularity =
+                        totalCount === 0
+                          ? suggestion.details.totalQueryCount
+                          : Math.round((100 * suggestion.details.totalQueryCount) / totalCount);
+                      suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
+                    });
+                  }
+                  aggregateFunctionsDeferred.resolve(aggregateFunctionsSuggestions);
+                })
+                .fail(aggregateFunctionsDeferred.reject)
+            );
+          })
+          .fail(aggregateFunctionsDeferred.reject);
+      } else {
+        aggregateFunctionsDeferred.reject();
+      }
+    } else {
+      aggregateFunctionsDeferred.reject();
+    }
+    return aggregateFunctionsDeferred;
+  }
+
+  handlePopularGroupByOrOrderBy(navOptAttribute, suggestSpec, deferred, columnsDeferred) {
+    const self = this;
+    const paths = [];
+    suggestSpec.tables.forEach(table => {
+      if (table.identifierChain) {
+        if (table.identifierChain.length === 1 && table.identifierChain[0].name) {
+          paths.push([self.activeDatabase, table.identifierChain[0].name]);
+        } else if (
+          table.identifierChain.length === 2 &&
+          table.identifierChain[0].name &&
+          table.identifierChain[1].name
+        ) {
+          paths.push([table.identifierChain[0].name, table.identifierChain[1].name]);
+        }
+      }
+    });
+
+    self.cancellablePromises.push(
+      dataCatalog
+        .getCatalog(self.snippet.type())
+        .loadNavOptPopularityForTables({
+          namespace: self.snippet.namespace(),
+          compute: self.snippet.compute(),
+          paths: paths,
+          silenceErrors: true,
+          cancellable: true
+        })
+        .done(entries => {
+          let totalColumnCount = 0;
+          const matchedEntries = [];
+          const prefix = suggestSpec.prefix
+            ? (self.parseResult.lowerCase ? suggestSpec.prefix.toLowerCase() : suggestSpec.prefix) +
+              ' '
+            : '';
+
+          entries.forEach(entry => {
+            if (entry.navOptPopularity[navOptAttribute]) {
+              totalColumnCount += entry.navOptPopularity[navOptAttribute].columnCount;
+              matchedEntries.push(entry);
+            }
+          });
+          if (totalColumnCount > 0) {
+            const suggestions = [];
+            matchedEntries.forEach(entry => {
+              const filterValue = self.createNavOptIdentifierForColumn(
+                entry.navOptPopularity[navOptAttribute],
+                suggestSpec.tables
+              );
+              suggestions.push({
+                value: prefix + filterValue,
+                filterValue: filterValue,
+                meta:
+                  navOptAttribute === 'groupByColumn'
+                    ? window.HUE_I18n.autocomplete.meta.groupBy
+                    : window.HUE_I18n.autocomplete.meta.orderBy,
+                category:
+                  navOptAttribute === 'groupByColumn'
+                    ? CATEGORIES.POPULAR_GROUP_BY
+                    : CATEGORIES.POPULAR_ORDER_BY,
+                weightAdjust: Math.round(
+                  (100 * entry.navOptPopularity[navOptAttribute].columnCount) / totalColumnCount
+                ),
+                popular: ko.observable(true),
+                hasCatalogEntry: false,
+                details: entry
+              });
+            });
+            if (prefix === '' && suggestions.length) {
+              mergeWithColumns(deferred, columnsDeferred, suggestions);
+            } else {
+              deferred.resolve(suggestions);
+            }
+          } else {
+            deferred.reject();
+          }
+        })
+        .fail(deferred.reject)
+    );
+  }
+
+  handleGroupBys(columnsDeferred) {
+    const self = this;
+    const groupBysDeferred = $.Deferred();
+    const suggestGroupBys = self.parseResult.suggestGroupBys;
+    if (window.HAS_OPTIMIZER && suggestGroupBys) {
+      initLoading(self.loadingGroupBys, groupBysDeferred);
+      groupBysDeferred.done(self.appendEntries);
+      self.handlePopularGroupByOrOrderBy(
+        'groupByColumn',
+        suggestGroupBys,
+        groupBysDeferred,
+        columnsDeferred
+      );
+    } else {
+      groupBysDeferred.reject();
+    }
+
+    return groupBysDeferred;
+  }
+
+  handleOrderBys(columnsDeferred) {
+    const self = this;
+    const orderBysDeferred = $.Deferred();
+    const suggestOrderBys = self.parseResult.suggestOrderBys;
+    if (window.HAS_OPTIMIZER && suggestOrderBys) {
+      initLoading(self.loadingOrderBys, orderBysDeferred);
+      orderBysDeferred.done(self.appendEntries);
+      self.handlePopularGroupByOrOrderBy(
+        'orderByColumn',
+        suggestOrderBys,
+        orderBysDeferred,
+        columnsDeferred
+      );
+    } else {
+      orderBysDeferred.reject();
+    }
+    return orderBysDeferred;
+  }
+
+  handleFilters() {
+    const self = this;
+    const filtersDeferred = $.Deferred();
+    const suggestFilters = self.parseResult.suggestFilters;
+    if (window.HAS_OPTIMIZER && suggestFilters) {
+      initLoading(self.loadingFilters, filtersDeferred);
+      filtersDeferred.done(self.appendEntries);
+
+      const paths = self.tableIdentifierChainsToPaths(suggestFilters.tables);
+      if (paths.length) {
+        dataCatalog
+          .getMultiTableEntry({
+            sourceType: self.snippet.type(),
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            paths: paths
+          })
+          .done(multiTableEntry => {
+            self.cancellablePromises.push(
+              multiTableEntry
+                .getTopFilters({ silenceErrors: true, cancellable: true })
+                .done(topFilters => {
+                  const filterSuggestions = [];
+                  let totalCount = 0;
+                  if (topFilters.values) {
+                    topFilters.values.forEach(value => {
+                      if (
+                        typeof value.popularValues !== 'undefined' &&
+                        value.popularValues.length > 0
+                      ) {
+                        value.popularValues.forEach(popularValue => {
+                          if (typeof popularValue.group !== 'undefined') {
+                            popularValue.group.forEach(grp => {
+                              let compVal = suggestFilters.prefix
+                                ? (self.parseResult.lowerCase
+                                    ? suggestFilters.prefix.toLowerCase()
+                                    : suggestFilters.prefix) + ' '
+                                : '';
+                              compVal += self.createNavOptIdentifier(
+                                value.tableName,
+                                grp.columnName,
+                                suggestFilters.tables
+                              );
+                              if (!/^ /.test(grp.op)) {
+                                compVal += ' ';
+                              }
+                              compVal += self.parseResult.lowerCase ? grp.op.toLowerCase() : grp.op;
+                              if (!/ $/.test(grp.op)) {
+                                compVal += ' ';
+                              }
+                              compVal += grp.literal;
+                              totalCount += popularValue.count;
+                              filterSuggestions.push({
+                                value: compVal,
+                                meta: window.HUE_I18n.autocomplete.meta.filter,
+                                category: CATEGORIES.POPULAR_FILTER,
+                                popular: ko.observable(true),
+                                details: popularValue
+                              });
+                            });
+                          }
+                        });
+                      }
+                    });
+                  }
+                  filterSuggestions.forEach(suggestion => {
+                    suggestion.details.relativePopularity =
+                      totalCount === 0
+                        ? suggestion.details.count
+                        : Math.round((100 * suggestion.details.count) / totalCount);
+                    suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
+                  });
+
+                  filtersDeferred.resolve(filterSuggestions);
+                })
+                .fail(filtersDeferred.reject)
+            );
+          })
+          .fail(filtersDeferred.reject);
+      } else {
+        filtersDeferred.reject();
+      }
+    } else {
+      filtersDeferred.reject();
+    }
+    return filtersDeferred;
+  }
+
+  handlePopularTables(tablesDeferred) {
+    const self = this;
+    const popularTablesDeferred = $.Deferred();
+    if (window.HAS_OPTIMIZER && self.parseResult.suggestTables) {
+      initLoading(self.loadingPopularTables, popularTablesDeferred);
+
+      const db =
+        self.parseResult.suggestTables.identifierChain &&
+        self.parseResult.suggestTables.identifierChain.length === 1 &&
+        self.parseResult.suggestTables.identifierChain[0].name
+          ? self.parseResult.suggestTables.identifierChain[0].name
+          : self.activeDatabase;
+
+      dataCatalog
+        .getEntry({
+          sourceType: self.snippet.type(),
+          namespace: self.snippet.namespace(),
+          compute: self.snippet.compute(),
+          path: [db],
+          temporaryOnly: self.temporaryOnly
+        })
+        .done(entry => {
+          self.cancellablePromises.push(
+            entry
+              .loadNavOptPopularityForChildren({ silenceErrors: true, cancellable: true })
+              .done(childEntries => {
+                let totalPopularity = 0;
+                const popularityIndex = {};
+                childEntries.forEach(childEntry => {
+                  if (childEntry.navOptPopularity && childEntry.navOptPopularity.popularity) {
+                    popularityIndex[childEntry.name] = true;
+                    totalPopularity += childEntry.navOptPopularity.popularity;
+                  }
+                });
+                if (totalPopularity > 0 && Object.keys(popularityIndex).length) {
+                  tablesDeferred
+                    .done(tableSuggestions => {
+                      tableSuggestions.forEach(suggestion => {
+                        if (popularityIndex[suggestion.details.name]) {
+                          suggestion.relativePopularity = Math.round(
+                            (100 * suggestion.details.navOptPopularity.popularity) / totalPopularity
+                          );
+                          if (suggestion.relativePopularity >= 5) {
+                            suggestion.popular(true);
+                          }
+                          suggestion.weightAdjust = suggestion.relativePopularity;
+                        }
+                      });
+                      popularTablesDeferred.resolve();
+                    })
+                    .fail(popularTablesDeferred.reject);
+                } else {
+                  popularTablesDeferred.resolve();
+                }
+              })
+              .fail(popularTablesDeferred.reject)
+          );
+        })
+        .fail(popularTablesDeferred.reject);
+    } else {
+      popularTablesDeferred.reject();
+    }
+    return popularTablesDeferred;
+  }
+
+  handlePopularColumns(columnsDeferred) {
+    const self = this;
+    const popularColumnsDeferred = $.Deferred();
+    const suggestColumns = self.parseResult.suggestColumns;
+
+    // The columnsDeferred gets resolved synchronously when the data is cached, if not, assume there are some suggestions.
+    let hasColumnSuggestions = true;
+    columnsDeferred.done(columns => {
+      hasColumnSuggestions = columns.length > 0;
+    });
+
+    if (
+      hasColumnSuggestions &&
+      window.HAS_OPTIMIZER &&
+      suggestColumns &&
+      suggestColumns.source !== 'undefined'
+    ) {
+      initLoading(self.loadingPopularColumns, popularColumnsDeferred);
+
+      const paths = [];
+      suggestColumns.tables.forEach(table => {
+        if (table.identifierChain && table.identifierChain.length > 0) {
+          if (table.identifierChain.length === 1 && table.identifierChain[0].name) {
+            paths.push([self.activeDatabase, table.identifierChain[0].name]);
+          } else if (
+            table.identifierChain.length === 2 &&
+            table.identifierChain[0].name &&
+            table.identifierChain[1].name
+          ) {
+            paths.push([table.identifierChain[0].name, table.identifierChain[1].name]);
+          }
+        }
+      });
+
+      self.cancellablePromises.push(
+        dataCatalog
+          .getCatalog(self.snippet.type())
+          .loadNavOptPopularityForTables({
+            namespace: self.snippet.namespace(),
+            compute: self.snippet.compute(),
+            paths: paths,
+            silenceErrors: true,
+            cancellable: true
+          })
+          .done(popularEntries => {
+            let valueAttribute = '';
+            switch (suggestColumns.source) {
+              case 'select':
+                valueAttribute = 'selectColumn';
+                break;
+              case 'group by':
+                valueAttribute = 'groupByColumn';
+                break;
+              case 'order by':
+                valueAttribute = 'orderByColumn';
+            }
+
+            const popularityIndex = {};
+
+            popularEntries.forEach(popularEntry => {
+              if (popularEntry.navOptPopularity && popularEntry.navOptPopularity[valueAttribute]) {
+                popularityIndex[popularEntry.getQualifiedPath()] = true;
+              }
+            });
+
+            if (!valueAttribute || Object.keys(popularityIndex).length === 0) {
+              popularColumnsDeferred.reject();
+              return;
+            }
+
+            columnsDeferred
+              .done(columns => {
+                let totalColumnCount = 0;
+                const matchedSuggestions = [];
+                columns.forEach(suggestion => {
+                  if (
+                    suggestion.hasCatalogEntry &&
+                    popularityIndex[suggestion.details.getQualifiedPath()]
+                  ) {
+                    matchedSuggestions.push(suggestion);
+                    totalColumnCount +=
+                      suggestion.details.navOptPopularity[valueAttribute].columnCount;
+                  }
+                });
+                if (totalColumnCount > 0) {
+                  matchedSuggestions.forEach(matchedSuggestion => {
+                    matchedSuggestion.relativePopularity = Math.round(
+                      (100 *
+                        matchedSuggestion.details.navOptPopularity[valueAttribute].columnCount) /
+                        totalColumnCount
+                    );
+                    if (matchedSuggestion.relativePopularity >= 5) {
+                      matchedSuggestion.popular(true);
+                    }
+                    matchedSuggestion.weightAdjust = matchedSuggestion.relativePopularity;
+                  });
+                }
+                popularColumnsDeferred.resolve();
+              })
+              .fail(popularColumnsDeferred.reject);
+          })
+      );
+    } else {
+      popularColumnsDeferred.reject();
+    }
+    return popularColumnsDeferred;
+  }
+
+  createNavOptIdentifier(navOptTableName, navOptColumnName, tables) {
+    const self = this;
+    let path = navOptTableName + '.' + navOptColumnName.split('.').pop();
+    for (let i = 0; i < tables.length; i++) {
+      let tablePath = '';
+      if (tables[i].identifierChain.length === 2) {
+        tablePath = $.map(tables[i].identifierChain, identifier => {
+          return identifier.name;
+        }).join('.');
+      } else if (tables[i].identifierChain.length === 1) {
+        tablePath = self.activeDatabase + '.' + tables[i].identifierChain[0].name;
+      }
+      if (path.indexOf(tablePath) === 0) {
+        path = path.substring(tablePath.length + 1);
+        if (tables[i].alias) {
+          path = tables[i].alias + '.' + path;
+        } else if (tables.length > 0) {
+          path = tables[i].identifierChain[tables[i].identifierChain.length - 1].name + '.' + path;
+        }
+        break;
+      }
+    }
+    return path;
+  }
+
+  createNavOptIdentifierForColumn(navOptColumn, tables) {
+    const self = this;
+    for (let i = 0; i < tables.length; i++) {
+      if (
+        navOptColumn.dbName &&
+        (navOptColumn.dbName !== self.activeDatabase ||
+          navOptColumn.dbName !== tables[i].identifierChain[0].name)
+      ) {
+        continue;
+      }
+      if (
+        navOptColumn.tableName &&
+        hueUtils.equalIgnoreCase(
+          navOptColumn.tableName,
+          tables[i].identifierChain[tables[i].identifierChain.length - 1].name
+        ) &&
+        tables[i].alias
+      ) {
+        return tables[i].alias + '.' + navOptColumn.columnName;
+      }
+    }
+
+    if (navOptColumn.dbName && navOptColumn.dbName !== self.activeDatabase) {
+      return navOptColumn.dbName + '.' + navOptColumn.tableName + '.' + navOptColumn.columnName;
+    }
+    if (tables.length > 1) {
+      return navOptColumn.tableName + '.' + navOptColumn.columnName;
+    }
+    return navOptColumn.columnName;
+  }
+
+  convertNavOptQualifiedIdentifier(qualifiedIdentifier, tables, type) {
+    const self = this;
+    const aliases = [];
+    let tablesHasDefaultDatabase = false;
+    tables.forEach(table => {
+      tablesHasDefaultDatabase =
+        tablesHasDefaultDatabase ||
+        hueUtils.equalIgnoreCase(
+          table.identifierChain[0].name.toLowerCase(),
+          self.activeDatabase.toLowerCase()
+        );
+      if (table.alias) {
+        aliases.push({
+          qualifiedName: $.map(table.identifierChain, identifier => {
+            return identifier.name;
+          })
+            .join('.')
+            .toLowerCase(),
+          alias: table.alias
+        });
+      }
+    });
+
+    for (let i = 0; i < aliases.length; i++) {
+      if (qualifiedIdentifier.toLowerCase().indexOf(aliases[i].qualifiedName) === 0) {
+        return aliases[i].alias + qualifiedIdentifier.substring(aliases[i].qualifiedName.length);
+      } else if (
+        qualifiedIdentifier
+          .toLowerCase()
+          .indexOf(self.activeDatabase.toLowerCase() + '.' + aliases[i].qualifiedName) === 0
+      ) {
+        return (
+          aliases[i].alias +
+          qualifiedIdentifier.substring(
+            (self.activeDatabase + '.' + aliases[i].qualifiedName).length
+          )
+        );
+      }
+    }
+
+    if (
+      qualifiedIdentifier.toLowerCase().indexOf(self.activeDatabase.toLowerCase()) === 0 &&
+      !tablesHasDefaultDatabase
+    ) {
+      return qualifiedIdentifier.substring(self.activeDatabase.length + 1);
+    }
+    if (type === 'hive') {
+      // Remove DB reference if given for Hive
+      const parts = qualifiedIdentifier.split('.');
+      if (parts.length > 2) {
+        return parts.slice(1).join('.');
+      }
+    }
+    return qualifiedIdentifier;
+  }
+
+  /**
+   * Helper function to fetch columns/fields given an identifierChain, this also takes care of expanding arrays
+   * and maps to match the required format for the API.
+   *
+   * @param originalIdentifierChain
+   */
+  fetchFieldsForIdentifiers(originalIdentifierChain) {
+    const self = this;
+    const deferred = $.Deferred();
+    const path = [];
+    for (let i = 0; i < originalIdentifierChain.length; i++) {
+      if (originalIdentifierChain[i].name && !originalIdentifierChain[i].subQuery) {
+        path.push(originalIdentifierChain[i].name);
+      } else {
+        return deferred.reject().promise();
+      }
+    }
+
+    const fetchFieldsInternal = function(remainingPath, fetchedPath) {
+      if (!fetchedPath) {
+        fetchedPath = [];
+      }
+      if (remainingPath.length > 0) {
+        fetchedPath.push(remainingPath.shift());
+        // Parser sometimes knows if it's a map or array.
+        if (
+          remainingPath.length > 0 &&
+          (remainingPath[0] === 'item' || remainingPath[0].name === 'value')
+        ) {
+          fetchedPath.push(remainingPath.shift());
+        }
+      }
+
+      dataCatalog
+        .getEntry({
+          sourceType: self.snippet.type(),
+          namespace: self.snippet.namespace(),
+          compute: self.snippet.compute(),
+          path: fetchedPath,
+          temporaryOnly: self.temporaryOnly
+        })
+        .done(catalogEntry => {
+          self.cancellablePromises.push(
+            catalogEntry
+              .getSourceMeta({ silenceErrors: true, cancellable: true })
+              .done(sourceMeta => {
+                if (
+                  self.snippet.type() === 'hive' &&
+                  typeof sourceMeta.extended_columns !== 'undefined' &&
+                  sourceMeta.extended_columns.length === 1 &&
+                  /^(?:map|array|struct)/i.test(sourceMeta.extended_columns[0].type)
+                ) {
+                  remainingPath.unshift(sourceMeta.extended_columns[0].name);
+                }
+                if (remainingPath.length) {
+                  if (/value|item|key/i.test(remainingPath[0])) {
+                    fetchedPath.push(remainingPath.shift());
+                  } else if (sourceMeta.type === 'array') {
+                    fetchedPath.push('item');
+                  } else if (sourceMeta.type === 'map') {
+                    fetchedPath.push('value');
+                  }
+                  fetchFieldsInternal(remainingPath, fetchedPath);
+                } else {
+                  deferred.resolve(catalogEntry);
+                }
+              })
+              .fail(deferred.reject)
+          );
+        })
+        .fail(deferred.reject);
+    };
+
+    // For Impala the first parts of the identifier chain could be either database or table, either:
+    // SELECT | FROM database.table -or- SELECT | FROM table.column
+
+    // For Hive it could be either:
+    // SELECT col.struct FROM db.tbl -or- SELECT col.struct FROM tbl
+    if (path.length > 1 && (self.snippet.type() === 'impala' || self.snippet.type() === 'hive')) {
+      dataCatalog
+        .getEntry({
+          sourceType: self.snippet.type(),
+          namespace: self.snippet.namespace(),
+          compute: self.snippet.compute(),
+          path: [],
+          temporaryOnly: self.temporaryOnly
+        })
+        .done(catalogEntry => {
+          self.cancellablePromises.push(
+            catalogEntry
+              .getChildren({ silenceErrors: true, cancellable: true })
+              .done(databaseEntries => {
+                const firstIsDb = databaseEntries.some(dbEntry => {
+                  return hueUtils.equalIgnoreCase(dbEntry.name, path[0]);
+                });
+                if (!firstIsDb) {
+                  path.unshift(self.activeDatabase);
+                }
+                fetchFieldsInternal(path);
+              })
+              .fail(deferred.reject)
+          );
+        })
+        .fail(deferred.reject);
+    } else if (path.length > 1) {
+      fetchFieldsInternal(path);
+    } else {
+      path.unshift(self.activeDatabase);
+      fetchFieldsInternal(path);
+    }
+
+    return deferred.promise();
+  }
+}
+
+export default AutocompleteResults;

+ 381 - 0
desktop/core/src/desktop/js/sql/spec/autocompleteResultsSpec.js

@@ -0,0 +1,381 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import $ from 'jquery';
+import 'jasmine-ajax';
+
+import AutocompleteResults from '../autocompleteResults';
+import dataCatalog from 'catalog/dataCatalog';
+import huePubSub from 'utils/huePubSub';
+import LOTS_OF_PARSE_RESULTS from './lotsOfParseResults';
+
+describe('AutocompleteResults.js', () => {
+  const subject = new AutocompleteResults({
+    snippet: {
+      autocompleteSettings: {
+        temporaryOnly: false
+      },
+      type: function() {
+        return 'hive';
+      },
+      database: function() {
+        return 'default';
+      },
+      namespace: function() {
+        return { id: 'defaultNamespace' };
+      },
+      compute: function() {
+        return { id: 'defaultCompute' };
+      },
+      whenContextSet: function() {
+        return $.Deferred().resolve();
+      }
+    },
+    editor: function() {
+      return {
+        getTextBeforeCursor: function() {
+          return 'foo';
+        },
+        getTextAfterCursor: function() {
+          return 'bar';
+        }
+      };
+    }
+  });
+
+  describe('Test a whole lot of different parse results', () => {
+    beforeEach(() => {
+      dataCatalog.disableCache();
+      window.AUTOCOMPLETE_TIMEOUT = 1;
+      global.AUTOCOMPLETE_TIMEOUT = 1;
+      jasmine.Ajax.install();
+
+      const failResponse = {
+        status: 500
+      };
+
+      jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/$/).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'application/json',
+              responseText: '{"status": 0, "databases": ["default"]}'
+            }
+      );
+
+      jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/[^/]+$/).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'application/json',
+              responseText:
+                '{"status": 0, "tables_meta": [' +
+                '{"comment": "comment", "type": "Table", "name": "foo"}, ' +
+                '{"comment": null, "type": "View", "name": "bar_view"}, ' +
+                '{"comment": null, "type": "Table", "name": "bar"}]}'
+            }
+      );
+
+      jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+$/).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'application/json',
+              responseText:
+                '{"status": 0, "support_updates": false, "hdfs_link": "/filebrowser/view=/user/hive/warehouse/customers", "extended_columns": [{"comment": "", "type": "int", "name": "id"}, {"comment": "", "type": "string", "name": "name"}, {"comment": "", "type": "struct<email_format:string,frequency:string,categories:struct<promos:boolean,surveys:boolean>>", "name": "email_preferences"}, {"comment": "", "type": "map<string,struct<street_1:string,street_2:string,city:string,state:string,zip_code:string>>", "name": "addresses"}, {"comment": "", "type": "array<struct<order_id:string,order_date:string,items:array<struct<product_id:int,sku:string,name:string,price:double,qty:int>>>>", "name": "orders"}], "columns": ["id", "name", "email_preferences", "addresses", "orders"], "partition_keys": []}'
+            }
+      );
+
+      jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+\/[^/]+$/).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'application/json',
+              responseText:
+                '{"status": 0, "comment": "", "type": "struct", "name": "email_preferences", "fields": [{"type": "string", "name": "email_format"}, {"type": "string", "name": "frequency"}, {"fields": [{"type": "boolean", "name": "promos"}, {"type": "boolean", "name": "surveys"}], "type": "struct", "name": "categories"}]}'
+            }
+      );
+
+      jasmine.Ajax.stubRequest(
+        /.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+\/[^/]+\/.*$/
+      ).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'application/json',
+              responseText:
+                '{"status": 0, "fields": [{"type": "boolean", "name": "promos"}, {"type": "boolean", "name": "surveys"}], "type": "struct", "name": "categories"}'
+            }
+      );
+
+      jasmine.Ajax.stubRequest(/.*\/filebrowser\/view.*/).andReturn(
+        Math.random() < 0.5
+          ? failResponse
+          : {
+              status: 200,
+              statusText: 'HTTP/1.1 200 OK',
+              contentType: 'text/javascript',
+              response: {
+                superuser: 'hdfs',
+                current_request_path: '/filebrowser/view=///var',
+                current_dir_path: '///var',
+                show_download_button: true,
+                cwd_set: true,
+                breadcrumbs: [
+                  {
+                    url: '/',
+                    label: '/'
+                  },
+                  {
+                    url: '/var',
+                    label: 'var'
+                  }
+                ],
+                apps: [
+                  'help',
+                  'sqoop',
+                  'pig',
+                  'hbase',
+                  'rdbms',
+                  'indexer',
+                  'metastore',
+                  'beeswax',
+                  'jobsub',
+                  'metadata',
+                  'zookeeper',
+                  'search',
+                  'useradmin',
+                  'notebook',
+                  'proxy',
+                  'oozie',
+                  'spark',
+                  'filebrowser',
+                  'about',
+                  'jobbrowser',
+                  'dashboard',
+                  'security',
+                  'impala'
+                ],
+                show_upload_button: true,
+                files: [
+                  {
+                    humansize: '0\u00a0bytes',
+                    url: '/filebrowser/view=/',
+                    stats: {
+                      size: 0,
+                      group: 'supergroup',
+                      blockSize: 0,
+                      replication: 0,
+                      user: 'hdfs',
+                      mtime: 1476970119,
+                      path: '///var/..',
+                      atime: 0,
+                      mode: 16877
+                    },
+                    name: '..',
+                    mtime: 'October 20, 2016 06:28 AM',
+                    rwx: 'drwxr-xr-x',
+                    path: '/',
+                    is_sentry_managed: false,
+                    type: 'dir',
+                    mode: '40755'
+                  },
+                  {
+                    humansize: '0\u00a0bytes',
+                    url: '/filebrowser/view=/var',
+                    stats: {
+                      size: 0,
+                      group: 'supergroup',
+                      blockSize: 0,
+                      replication: 0,
+                      user: 'hdfs',
+                      mtime: 1470887321,
+                      path: '///var',
+                      atime: 0,
+                      mode: 16877
+                    },
+                    name: '.',
+                    mtime: 'August 10, 2016 08:48 PM',
+                    rwx: 'drwxr-xr-x',
+                    path: '/var',
+                    is_sentry_managed: false,
+                    type: 'dir',
+                    mode: '40755'
+                  },
+                  {
+                    humansize: '0\u00a0bytes',
+                    url: '/filebrowser/view=/var/lib',
+                    stats: {
+                      size: 0,
+                      group: 'supergroup',
+                      blockSize: 0,
+                      replication: 0,
+                      user: 'hdfs',
+                      mtime: 1470887321,
+                      path: '/var/lib',
+                      atime: 0,
+                      mode: 16877
+                    },
+                    name: 'lib',
+                    mtime: 'August 10, 2016 08:48 PM',
+                    rwx: 'drwxr-xr-x',
+                    path: '/var/lib',
+                    is_sentry_managed: false,
+                    type: 'dir',
+                    mode: '40755'
+                  },
+                  {
+                    humansize: '0\u00a0bytes',
+                    url: '/filebrowser/view=/var/log',
+                    stats: {
+                      size: 0,
+                      group: 'mapred',
+                      blockSize: 0,
+                      replication: 0,
+                      user: 'yarn',
+                      mtime: 1470887196,
+                      path: '/var/log',
+                      atime: 0,
+                      mode: 17405
+                    },
+                    name: 'log',
+                    mtime: 'August 10, 2016 08:46 PM',
+                    rwx: 'drwxrwxr-xt',
+                    path: '/var/log',
+                    is_sentry_managed: false,
+                    type: 'dir',
+                    mode: '41775'
+                  }
+                ],
+                users: [],
+                is_embeddable: false,
+                supergroup: 'supergroup',
+                descending: 'false',
+                groups: [],
+                is_trash_enabled: true,
+                pagesize: 50,
+                file_filter: 'any',
+                is_fs_superuser: false,
+                is_sentry_managed: false,
+                home_directory: '/user/admin',
+                path: '///var',
+                page: {
+                  num_pages: 1,
+                  total_count: 2,
+                  next_page_number: 1,
+                  end_index: 2,
+                  number: 1,
+                  previous_page_number: 1,
+                  start_index: 1
+                }
+              }
+            }
+      );
+
+      huePubSub.publish('assist.clear.all.caches');
+    });
+
+    afterEach(() => {
+      AUTOCOMPLETE_TIMEOUT = 0;
+      dataCatalog.enableCache();
+      jasmine.Ajax.uninstall();
+    });
+
+    LOTS_OF_PARSE_RESULTS.forEach(parseResult => {
+      // if (parseResult.index < 9) {
+      it('should handle parse result no. ' + parseResult.index, () => {
+        if (parseResult.suggestKeywords) {
+          const cleanedKeywords = [];
+          parseResult.suggestKeywords.forEach(keyword => {
+            if (!keyword.value) {
+              cleanedKeywords.push({ value: keyword });
+            } else {
+              cleanedKeywords.push(keyword);
+            }
+          });
+          parseResult.suggestKeywords = cleanedKeywords;
+        }
+        try {
+          subject.update(parseResult);
+        } catch (e) {
+          fail('Got exception');
+          console.error(e);
+        }
+        if (subject.loading()) {
+          for (let i = 0; i < jasmine.Ajax.requests.count(); i++) {
+            console.log(jasmine.Ajax.requests.at(i));
+          }
+          fail('Still loading, missing ajax spec?');
+        }
+        expect(subject.loading()).toBeFalsy();
+      });
+      // }
+    });
+  });
+
+  it('should handle parse results with keywords', () => {
+    subject.entries([]);
+    expect(subject.filtered().length).toBe(0);
+    subject.update({
+      lowerCase: true,
+      suggestKeywords: [{ value: 'BAR', weight: 1 }, { value: 'FOO', weight: 2 }]
+    });
+    expect(subject.filtered().length).toBe(2);
+    // Sorted by weight, case adjusted
+    expect(subject.filtered()[0].meta).toBe(window.HUE_I18n.autocomplete.meta.keyword);
+    expect(subject.filtered()[0].value).toBe('foo');
+    expect(subject.filtered()[1].meta).toBe(window.HUE_I18n.autocomplete.meta.keyword);
+    expect(subject.filtered()[1].value).toBe('bar');
+  });
+
+  it('should handle parse results with identifiers', () => {
+    subject.entries([]);
+    expect(subject.filtered().length).toBe(0);
+    subject.update({
+      lowerCase: false,
+      suggestIdentifiers: [{ name: 'foo', type: 'alias' }, { name: 'bar', type: 'table' }]
+    });
+    expect(subject.filtered().length).toBe(2);
+    // Sorted by name, no case adjust
+    expect(subject.filtered()[0].meta).toBe('table');
+    expect(subject.filtered()[0].value).toBe('bar');
+    expect(subject.filtered()[1].meta).toBe('alias');
+    expect(subject.filtered()[1].value).toBe('foo');
+  });
+
+  it('should handle parse results with functions', () => {
+    subject.entries([]);
+    expect(subject.filtered().length).toBe(0);
+    subject.update({
+      lowerCase: false,
+      suggestFunctions: {}
+    });
+    expect(subject.filtered().length).toBeGreaterThan(0);
+    expect(subject.filtered()[0].details.arguments).toBeDefined();
+    expect(subject.filtered()[0].details.signature).toBeDefined();
+    expect(subject.filtered()[0].details.description).toBeDefined();
+  });
+});

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 79 - 0
desktop/core/src/desktop/js/sql/spec/lotsOfParseResults.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
desktop/core/src/desktop/js/sql/spec/parseResults.json


+ 150 - 0
desktop/core/src/desktop/js/sql/spec/sqlAutocompleterSpec_IGNORE.js

@@ -0,0 +1,150 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import dataCatalog from 'catalog/dataCatalog';
+import SqlAutocompleter from '../sqlAutocompleter';
+
+// TODO: Ignore until ace is in webpack
+
+describe('sqlAutocomplete.js', () => {
+  let subject;
+
+  beforeEach(() => {
+    dataCatalog.disableCache();
+    window.AUTOCOMPLETE_TIMEOUT = 1;
+    jasmine.Ajax.install();
+
+    jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/$/).andReturn({
+      status: 200,
+      statusText: 'HTTP/1.1 200 OK',
+      contentType: 'application/json',
+      responseText: '{"status": 0, "databases": ["default"]}'
+    });
+
+    jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/[^/]+$/).andReturn({
+      status: 200,
+      statusText: 'HTTP/1.1 200 OK',
+      contentType: 'application/json',
+      responseText:
+        '{"status": 0, "tables_meta": [' +
+        '{"comment": "comment", "type": "Table", "name": "foo"}, ' +
+        '{"comment": null, "type": "View", "name": "bar_view"}, ' +
+        '{"comment": null, "type": "Table", "name": "bar"}]}'
+    });
+
+    jasmine.Ajax.stubRequest(/.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+$/).andReturn({
+      status: 200,
+      statusText: 'HTTP/1.1 200 OK',
+      contentType: 'application/json',
+      responseText:
+        '{"status": 0, "support_updates": false, "hdfs_link": "/filebrowser/view=/user/hive/warehouse/customers", "extended_columns": [{"comment": "", "type": "int", "name": "id"}, {"comment": "", "type": "string", "name": "name"}, {"comment": "", "type": "struct<email_format:string,frequency:string,categories:struct<promos:boolean,surveys:boolean>>", "name": "email_preferences"}, {"comment": "", "type": "map<string,struct<street_1:string,street_2:string,city:string,state:string,zip_code:string>>", "name": "addresses"}, {"comment": "", "type": "array<struct<order_id:string,order_date:string,items:array<struct<product_id:int,sku:string,name:string,price:double,qty:int>>>>", "name": "orders"}], "columns": ["id", "name", "email_preferences", "addresses", "orders"], "partition_keys": []}'
+    });
+  });
+
+  afterEach(() => {
+    if (subject.suggestions.loading()) {
+      for (let i = 0; i < jasmine.Ajax.requests.count(); i++) {
+        console.log(jasmine.Ajax.requests.at(i));
+      }
+      fail('Still loading, missing ajax spec?');
+    }
+    AUTOCOMPLETE_TIMEOUT = 0;
+    dataCatalog.enableCache();
+    jasmine.Ajax.uninstall();
+  });
+
+  const createSubject = function(dialect, textBeforeCursor, textAfterCursor, positionStatement) {
+    const editor = ace.edit();
+    editor.setValue(textBeforeCursor);
+    const actualCursorPosition = editor.getCursorPosition();
+    editor.setValue(textBeforeCursor + textAfterCursor);
+    editor.moveCursorToPosition(actualCursorPosition);
+
+    return new SqlAutocompleter({
+      snippet: {
+        autocompleteSettings: {
+          temporaryOnly: false
+        },
+        type: function() {
+          return dialect;
+        },
+        database: function() {
+          return 'default';
+        },
+        namespace: function() {
+          return { id: 'defaultNamespace' };
+        },
+        compute: function() {
+          return { id: 'defaultCompute' };
+        },
+        whenContextSet: function() {
+          return $.Deferred().resolve();
+        },
+        positionStatement: ko.observable(positionStatement)
+      },
+      editor: function() {
+        return {};
+      }
+    });
+  };
+
+  it('should create suggestions for Hive', () => {
+    subject = createSubject('hive', '', '');
+    expect(subject.suggestions.filtered().length).toBe(0);
+    subject.autocomplete();
+    expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
+  });
+
+  it('should create suggestions for Impala', () => {
+    subject = createSubject('impala', '', '');
+    expect(subject.suggestions.filtered().length).toBe(0);
+    subject.autocomplete();
+    expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
+  });
+
+  it('should fallback to the active query when there are surrounding errors', () => {
+    subject = createSubject('hive', 'SELECT FROMzzz bla LIMIT 1; SELECT ', ' FROM bla', {
+      location: { first_line: 1, last_line: 1, first_column: 27, last_column: 52 }
+    });
+    expect(subject.suggestions.filtered().length).toBe(0);
+    subject.autocomplete();
+    expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
+  });
+
+  it("should only fallback to the active query when there are surrounding errors if there's an active query", () => {
+    subject = createSubject('hive', 'SELECT FROMzzz bla LIMIT 1; SELECT ', ' FROM bla');
+    expect(subject.suggestions.filtered().length).toBe(0);
+    subject.autocomplete();
+    expect(subject.suggestions.filtered().length).toBe(0);
+  });
+
+  it('should suggest columns from subqueries', () => {
+    subject = createSubject(
+      'hive',
+      'SELECT ',
+      ' FROM customers, (SELECT app FROM web_logs) AS subQ;'
+    );
+    expect(subject.suggestions.filtered().length).toBe(0);
+    subject.autocomplete();
+    expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
+
+    const appFound = subject.suggestions.filtered().some(suggestion => {
+      return suggestion.category.id === 'column' && suggestion.value === 'app';
+    });
+
+    expect(appFound).toBeTruthy();
+  });
+});

+ 162 - 0
desktop/core/src/desktop/js/sql/sqlAutocompleter.js

@@ -0,0 +1,162 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import AutocompleteResults from 'sql/autocompleteResults';
+import hueDebug from 'utils/hueDebug';
+import huePubSub from 'utils/huePubSub';
+import sqlAutocompleteParser from 'parse/sqlAutocompleteParser';
+
+class SqlAutocompleter {
+  /**
+   * @param {Object} options
+   * @param {Snippet} options.snippet
+   * @param {string} [options.fixedPrefix] - Optional prefix to always use on parse
+   * @param {string} [options.fixedPostfix] - Optional postfix to always use on parse
+   * @constructor
+   */
+  constructor(options) {
+    const self = this;
+    self.snippet = options.snippet;
+    self.editor = options.editor;
+    self.fixedPrefix =
+      options.fixedPrefix ||
+      function() {
+        return '';
+      };
+    self.fixedPostfix =
+      options.fixedPostfix ||
+      function() {
+        return '';
+      };
+    self.suggestions = new AutocompleteResults(options);
+  }
+
+  parseActiveStatement() {
+    const self = this;
+    if (self.snippet.positionStatement() && self.snippet.positionStatement().location) {
+      const activeStatementLocation = self.snippet.positionStatement().location;
+      const cursorPosition = self.editor().getCursorPosition();
+
+      if (
+        (activeStatementLocation.first_line - 1 < cursorPosition.row ||
+          (activeStatementLocation.first_line - 1 === cursorPosition.row &&
+            activeStatementLocation.first_column <= cursorPosition.column)) &&
+        (activeStatementLocation.last_line - 1 > cursorPosition.row ||
+          (activeStatementLocation.last_line - 1 === cursorPosition.row &&
+            activeStatementLocation.last_column >= cursorPosition.column))
+      ) {
+        const beforeCursor =
+          self.fixedPrefix() +
+          self.editor().session.getTextRange({
+            start: {
+              row: activeStatementLocation.first_line - 1,
+              column: activeStatementLocation.first_column
+            },
+            end: cursorPosition
+          });
+        const afterCursor =
+          self.editor().session.getTextRange({
+            start: cursorPosition,
+            end: {
+              row: activeStatementLocation.last_line - 1,
+              column: activeStatementLocation.last_column
+            }
+          }) + self.fixedPostfix();
+        return sqlAutocompleteParser.parseSql(
+          beforeCursor,
+          afterCursor,
+          self.snippet.type(),
+          false
+        );
+      }
+    }
+  }
+
+  autocomplete() {
+    const self = this;
+    let parseResult;
+    try {
+      huePubSub.publish(
+        'get.active.editor.locations',
+        locations => {
+          // This could happen in case the user is editing at the borders of the statement and the locations haven't
+          // been updated yet, in that case we have to force a location update before parsing
+          if (
+            self.snippet.ace &&
+            self.snippet.ace() &&
+            locations &&
+            self.snippet.ace().lastChangeTime !== locations.editorChangeTime
+          ) {
+            huePubSub.publish('editor.refresh.statement.locations', self.snippet);
+          }
+        },
+        self.snippet
+      );
+
+      parseResult = self.parseActiveStatement();
+
+      if (typeof hueDebug !== 'undefined' && hueDebug.showParseResult) {
+        console.log(parseResult);
+      }
+    } catch (e) {
+      if (typeof console.warn !== 'undefined') {
+        console.warn(e);
+      }
+    }
+
+    // In the unlikely case the statement parser fails we fall back to parsing all of it
+    if (!parseResult) {
+      try {
+        parseResult = sqlAutocompleteParser.parseSql(
+          self.editor().getTextBeforeCursor(),
+          self.editor().getTextAfterCursor(),
+          self.snippet.type(),
+          false
+        );
+      } catch (e) {
+        if (typeof console.warn !== 'undefined') {
+          console.warn(e);
+        }
+      }
+    }
+
+    if (!parseResult) {
+      // This prevents Ace from inserting garbled text in case of exception
+      huePubSub.publish('hue.ace.autocompleter.done');
+    } else {
+      try {
+        if (self.lastContextRequest) {
+          self.lastContextRequest.dispose();
+        }
+        self.lastContextRequest = self.snippet
+          .whenContextSet()
+          .done(() => {
+            self.suggestions.update(parseResult);
+          })
+          .fail(() => {
+            huePubSub.publish('hue.ace.autocompleter.done');
+          });
+      } catch (e) {
+        if (typeof console.warn !== 'undefined') {
+          console.warn(e);
+        }
+        huePubSub.publish('hue.ace.autocompleter.done');
+      }
+    }
+  }
+}
+
+export default SqlAutocompleter;

+ 29 - 33
desktop/core/src/desktop/static/desktop/js/hdfsAutocompleter.js → desktop/core/src/desktop/js/utils/hdfsAutocompleter.js

@@ -14,12 +14,11 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-var HdfsAutocompleter = (function () {
+import apiHelper from 'api/apiHelper';
 
-  var TIME_TO_LIVE_IN_MILLIS = 60000; // 1 minute
-  var BASE_PATH = "/filebrowser/view=";
-  var PARAMETERS = "?pagesize=100&format=json";
+const TIME_TO_LIVE_IN_MILLIS = 60000; // 1 minute
 
+class HdfsAutocompleter {
   /**
    * @param {object} options
    * @param {string} options.user
@@ -28,36 +27,34 @@ var HdfsAutocompleter = (function () {
    *
    * @constructor
    */
-  function HdfsAutocompleter(options) {
-    var self = this;
+  constructor(options) {
+    const self = this;
     self.user = options.user;
     self.snippet = options.snippet;
-    self.timeout = options.timeout
+    self.timeout = options.timeout;
   }
 
-  HdfsAutocompleter.prototype.getTotalStorageUserPrefix = function () {
-    var self = this;
+  getTotalStorageUserPrefix() {
+    const self = this;
     return self.user;
-  };
+  }
 
-  HdfsAutocompleter.prototype.hasExpired = function (timestamp) {
-    return (new Date()).getTime() - timestamp > TIME_TO_LIVE_IN_MILLIS;
-  };
+  hasExpired(timestamp) {
+    return new Date().getTime() - timestamp > TIME_TO_LIVE_IN_MILLIS;
+  }
 
-  HdfsAutocompleter.prototype.extractFields = function (data) {
-    var files = $.map(data.files, function (file) {
+  extractFields(data) {
+    const files = data.files.map(file => {
       return {
         name: file.name,
         type: file.type
-      }
+      };
     });
 
-    files.sort(function (a, b) {
-      return a.name.localeCompare(b.name);
-    });
+    files.sort((a, b) => a.name.localeCompare(b.name));
 
-    var result = [];
-    files.forEach(function(field, idx) {
+    const result = [];
+    files.forEach((field, idx) => {
       if (field.name !== '..' && field.name !== '.') {
         result.push({
           value: field.name,
@@ -67,23 +64,23 @@ var HdfsAutocompleter = (function () {
       }
     });
     return result;
-  };
+  }
 
-  HdfsAutocompleter.prototype.autocomplete = function (beforeCursor, afterCursor, callback, editor) {
-    var self = this;
+  autocomplete(beforeCursor, afterCursor, callback, editor) {
+    const self = this;
 
-    var onFailure = function () {
+    const onFailure = function() {
       callback([]);
     };
 
     if (beforeCursor.match(/["'](?:\/[^\/]*)+/)) {
-      var parts = beforeCursor.split('/');
+      const parts = beforeCursor.split('/');
       // Drop the first " or '
       parts.shift();
       // Last one is either partial name or empty
       parts.pop();
 
-      var successCallback = function (data) {
+      const successCallback = function(data) {
         if (!data.error) {
           callback(self.extractFields(data));
         } else {
@@ -91,7 +88,7 @@ var HdfsAutocompleter = (function () {
         }
       };
 
-      self.snippet.getApiHelper().fetchHdfsPath({
+      apiHelper.fetchHdfsPath({
         pathParts: parts,
         successCallback: successCallback,
         silenceErrors: true,
@@ -102,10 +99,9 @@ var HdfsAutocompleter = (function () {
     } else {
       onFailure();
     }
-  };
+  }
 
-  HdfsAutocompleter.prototype.getDocTooltip = function (item) {
-  };
+  getDocTooltip(item) {}
+}
 
-  return HdfsAutocompleter;
-})();
+export default HdfsAutocompleter;

+ 360 - 0
desktop/core/src/desktop/js/utils/hueColors.js

@@ -0,0 +1,360 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+const HueColors = {
+  CUIScaleColors: [
+    {
+      name: 'gray',
+      colors: [
+        '#F8F8F8',
+        '#E7E7E7',
+        '#E0E0E0',
+        '#DCDCDC',
+        '#C8C8C8',
+        '#B4B4B4',
+        '#A0A0A0',
+        '#787878',
+        '#424242',
+        '#212121'
+      ]
+    },
+    {
+      name: 'blue-gray',
+      colors: [
+        '#ECEFF1',
+        '#CFD8DC',
+        '#B0BEC5',
+        '#90A4AE',
+        '#78909C',
+        '#607D8B',
+        '#546E7A',
+        '#455A64',
+        '#36454F',
+        '#232C34'
+      ]
+    },
+    {
+      name: 'blue',
+      colors: [
+        '#E9F6FB',
+        '#BEE4F5',
+        '#A9DBF1',
+        '#7ECAEB',
+        '#53B8E4',
+        '#29A7DE',
+        '#2496C7',
+        '#0B7FAD',
+        '#1C749B',
+        '#186485'
+      ]
+    },
+    {
+      name: 'steel',
+      colors: [
+        '#E8EEEE',
+        '#C6D6D6',
+        '#A0BABA',
+        '#7A9F9F',
+        '#5D8A8A',
+        '#417575',
+        '#3C6C6C',
+        '#345E5E',
+        '#2D5252',
+        '#274646'
+      ]
+    },
+    {
+      name: 'teal',
+      colors: [
+        '#E0F6F5',
+        '#B3EAE6',
+        '#80DCD5',
+        '#4DCEC4',
+        '#26C3B7',
+        '#00B9AA',
+        '#00AA9D',
+        '#009488',
+        '#008177',
+        '#006F66'
+      ]
+    },
+    {
+      name: 'green',
+      colors: [
+        '#E2F3EA',
+        '#B7E2CD',
+        '#87CEAB',
+        '#57BB89',
+        '#33AC6F',
+        '#0F9D56',
+        '#0E914F',
+        '#0C7E45',
+        '#0A6E3C',
+        '#095E34'
+      ]
+    },
+    {
+      name: 'lime',
+      colors: [
+        '#EDF5E2',
+        '#D2E6B9',
+        '#B4D689',
+        '#96C55A',
+        '#7FB836',
+        '#69AC13',
+        '#619F12',
+        '#548A0F',
+        '#49780D',
+        '#3F670B'
+      ]
+    },
+    {
+      name: 'yellow',
+      colors: [
+        '#FFFCE6',
+        '#FFFACC',
+        '#FFF599',
+        '#FFF066',
+        '#FFEB3B',
+        '#FFE600',
+        '#E6CF00',
+        '#B3A100',
+        '#807300',
+        '#4D4500'
+      ]
+    },
+    {
+      name: 'orange',
+      colors: [
+        '#FBF1E1',
+        '#FFE8AF',
+        '#FFD466',
+        '#EDB233',
+        '#EBA81A',
+        '#E99F01',
+        '#D18F00',
+        '#BA7F00',
+        '#A36F00',
+        '#8B572A'
+      ]
+    },
+    {
+      name: 'red',
+      colors: [
+        '#FFE5E5',
+        '#FFCCCC',
+        '#FFB2B2',
+        '#E7808D',
+        '#DE4D5F',
+        '#D0021B',
+        '#BB0118',
+        '#A60115',
+        '#910112',
+        '#7C0110'
+      ]
+    },
+    {
+      name: 'pink',
+      colors: [
+        '#F2DEDE',
+        '#F3BFD4',
+        '#EC93B7',
+        '#E4689A',
+        '#DE4784',
+        '#D8276F',
+        '#C72466',
+        '#AD1F59',
+        '#971B4D',
+        '#821743'
+      ]
+    },
+    {
+      name: 'purple',
+      colors: [
+        '#EFE9F5',
+        '#D8C8E7',
+        '#BDA3D6',
+        '#A37EC6',
+        '#8F62B9',
+        '#7B46AD',
+        '#71419F',
+        '#62388A',
+        '#563179',
+        '#4A2A68'
+      ]
+    },
+    {
+      name: 'purple-gray',
+      colors: [
+        '#F1EFEF',
+        '#D5CFD1',
+        '#BAB0B3',
+        '#ACA0A4',
+        '#9F9095',
+        '#977F86',
+        '#837077',
+        '#766168',
+        '#6A575D',
+        '#5E4D53'
+      ]
+    },
+    {
+      name: 'green-gray',
+      colors: [
+        '#E9E8E3',
+        '#C8C6BA',
+        '#B2AF9F',
+        '#A7A391',
+        '#9C9883',
+        '#918D76',
+        '#827E6A',
+        '#74705E',
+        '#656252',
+        '#575446'
+      ]
+    }
+  ],
+
+  hexToR: function(h) {
+    return parseInt(this.cutHex(h).substring(0, 2), 16);
+  },
+
+  hexToG: function(h) {
+    return parseInt(this.cutHex(h).substring(2, 4), 16);
+  },
+
+  hexToB: function(h) {
+    return parseInt(this.cutHex(h).substring(4, 6), 16);
+  },
+
+  cutHex: function(h) {
+    return h.charAt(0) === '#' ? h.substring(1, 7) : h;
+  },
+
+  decToHex: function(i) {
+    return (i + 0x100)
+      .toString(16)
+      .substr(-2)
+      .toUpperCase();
+  },
+
+  scale: function(from, to, bands) {
+    const fromRGB = [this.hexToR(from), this.hexToG(from), this.hexToB(from)];
+    const toRGB = [this.hexToR(to), this.hexToG(to), this.hexToB(to)];
+    let i;
+    const delta = [];
+    const result = [];
+
+    for (i = 0; i < 4; i++) {
+      delta[i] = (fromRGB[i] - toRGB[i]) / (bands + 1);
+    }
+
+    for (i = 0; i < bands; i++) {
+      const r = Math.round(fromRGB[0] - delta[0] * i);
+      const g = Math.round(fromRGB[1] - delta[1] * i);
+      const b = Math.round(fromRGB[2] - delta[2] * i);
+      result.push('#' + this.decToHex(r) + this.decToHex(g) + this.decToHex(b));
+    }
+    return result;
+  },
+
+  getNormalizedColors: function() {
+    const normalizedColors = {};
+    this.CUIScaleColors.forEach(scaleDef => {
+      normalizedColors[scaleDef.name] = scaleDef.colors;
+    });
+    return normalizedColors;
+  },
+
+  getCUIChartColors: function() {
+    let i;
+
+    const normalizedColors = this.getNormalizedColors();
+
+    // optimal visual sequence by contrasting colors
+    const sequence = [
+        'blue',
+        'lime',
+        'blue-gray',
+        'pink',
+        'steel',
+        'purple',
+        'teal',
+        'red',
+        'orange',
+        'green'
+      ],
+      wholeSpectrum = [],
+      sequenceHalfLength = sequence.length / 2;
+
+    function addMain(mainSwatch) {
+      wholeSpectrum.push({ color: normalizedColors[mainSwatch][sequenceHalfLength] });
+    }
+
+    function addPlus(mainSwatch) {
+      wholeSpectrum.push({ color: normalizedColors[mainSwatch][sequenceHalfLength + i] });
+    }
+
+    function addMinus(mainSwatch) {
+      wholeSpectrum.push({ color: normalizedColors[mainSwatch][sequenceHalfLength - i] });
+    }
+
+    for (i = 1; i < sequenceHalfLength; i++) {
+      if (i === 1) {
+        sequence.forEach(addMain);
+      }
+
+      sequence.forEach(addPlus);
+      sequence.forEach(addMinus);
+    }
+    return wholeSpectrum;
+  },
+
+  d3Scale: function() {
+    return d3v3.scale
+      .category20()
+      .range()
+      .concat(
+        d3v3.scale
+          .category20b()
+          .range()
+          .concat(d3v3.scale.category20c().range())
+      );
+  },
+  cuiD3Scale: function(swatch) {
+    let colors = this.getCUIChartColors().map(c => {
+      return c.color;
+    });
+    if (swatch) {
+      this.CUIScaleColors.forEach(s => {
+        if (s.name === swatch) {
+          colors = s.colors;
+        }
+      });
+    }
+    return colors;
+  },
+  LIGHT_BLUE: '#DBE8F1',
+  BLUE: '#87BAD5',
+  DARK_BLUE: '#0B7FAD',
+  DARKER_BLUE: '#205875',
+  PURPLE: '#C0B1E9',
+  GRAY: '#666666',
+  WHITE: '#FFFFFF',
+  ORANGE: '#FF7F0E'
+};
+
+export default HueColors;

+ 1 - 1
desktop/core/src/desktop/js/utils/hueDebug.js

@@ -20,7 +20,7 @@ const hueDebug = {
   clearCaches: function() {
     const promises = [];
     const clearInstance = function(prefix) {
-      promises.push(localforage.createInstance({ name: prefix + LOGGED_USERNAME }).clear());
+      promises.push(localforage.createInstance({ name: prefix + window.LOGGED_USERNAME }).clear());
     };
     clearInstance('HueContextCatalog_');
     clearInstance('HueDataCatalog_');

+ 180 - 0
desktop/core/src/desktop/js/utils/spec/hdfsAutocompleterSpec.js

@@ -0,0 +1,180 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import ko from 'knockout';
+
+import apiHelper from 'api/apiHelper';
+import HdfsAutocompleter from '../hdfsAutocompleter';
+import SqlTestUtils from 'parse/spec/sqlTestUtils';
+
+describe('hdfsAutocompleter.js', () => {
+  let subject;
+
+  const ajaxHelper = {
+    responseForUrls: {}
+  };
+
+  const snippet = {
+    type: ko.observable(),
+    database: ko.observable('database_one'),
+    isSqlDialect: function() {
+      return true;
+    },
+    getContext: function() {
+      return ko.mapping.fromJS(null);
+    },
+    getApiHelper: function() {
+      return apiHelper;
+    }
+  };
+
+  beforeAll(() => {
+    jasmine.addMatchers(SqlTestUtils.autocompleteMatcher);
+    $.totalStorage = function(key, value) {
+      return null;
+    };
+
+    spyOn($, 'ajax').and.callFake(options => {
+      const firstUrlPart = options.url.split('?')[0];
+
+      expect(ajaxHelper.responseForUrls[firstUrlPart]).toBeDefined(
+        'fake response for url ' + firstUrlPart + ' not found'
+      );
+      const response = ajaxHelper.responseForUrls[firstUrlPart];
+      response.called = true;
+      response.status = 0;
+      options.success(response);
+      return {
+        fail: function() {
+          return {
+            always: $.noop
+          };
+        }
+      };
+    });
+  });
+
+  afterEach(() => {
+    $.each(ajaxHelper.responseForUrls, (key, value) => {
+      expect(value.called).toEqual(true, key + ' was never called');
+    });
+  });
+
+  beforeEach(() => {
+    subject = new HdfsAutocompleter({
+      user: 'testUser',
+      snippet: snippet
+    });
+    ajaxHelper.responseForUrls = {};
+  });
+
+  const createCallbackSpyForValues = function(values) {
+    const spy = {
+      cb: value => {
+        expect(value).toEqualAutocompleteValues(values);
+      }
+    };
+    return spyOn(spy, 'cb').and.callThrough();
+  };
+
+  const assertAutoComplete = function(testDefinition) {
+    ajaxHelper.responseForUrls = testDefinition.serverResponses;
+    const callback = createCallbackSpyForValues(testDefinition.expectedSuggestions);
+    subject.autocomplete(testDefinition.beforeCursor, testDefinition.afterCursor, callback);
+    expect(callback).toHaveBeenCalled();
+  };
+
+  it('should return empty suggestions for empty statement', () => {
+    assertAutoComplete({
+      serverResponses: {},
+      beforeCursor: '',
+      afterCursor: '',
+      expectedSuggestions: []
+    });
+  });
+
+  it('should return empty suggestions for bogus statements', () => {
+    assertAutoComplete({
+      serverResponses: {},
+      beforeCursor: "qwerqwer'asdf/",
+      afterCursor: '',
+      expectedSuggestions: []
+    });
+  });
+
+  it('should return empty suggestions for URIs with schemes ', () => {
+    assertAutoComplete({
+      serverResponses: {},
+      beforeCursor: '://blabla',
+      afterCursor: '',
+      expectedSuggestions: []
+    });
+  });
+
+  it("should return suggestions for root with '", () => {
+    assertAutoComplete({
+      serverResponses: {
+        '/filebrowser/view=/': {
+          files: [
+            { name: '.', type: 'dir' },
+            { name: '..', type: 'dir' },
+            { name: 'var', type: 'dir' },
+            { name: 'tmp_file', type: 'file' }
+          ]
+        }
+      },
+      beforeCursor: "'/",
+      afterCursor: '',
+      expectedSuggestions: ['tmp_file', 'var']
+    });
+  });
+
+  it('should return suggestions for root with "', () => {
+    assertAutoComplete({
+      serverResponses: {
+        '/filebrowser/view=/': {
+          files: [
+            { name: '.', type: 'dir' },
+            { name: '..', type: 'dir' },
+            { name: 'var', type: 'dir' },
+            { name: 'tmp_file', type: 'file' }
+          ]
+        }
+      },
+      beforeCursor: '"/',
+      afterCursor: '',
+      expectedSuggestions: ['tmp_file', 'var']
+    });
+  });
+
+  it('should return suggestions for non-root', () => {
+    assertAutoComplete({
+      serverResponses: {
+        '/filebrowser/view=/foo/bar': {
+          files: [
+            { name: '.', type: 'dir' },
+            { name: '..', type: 'dir' },
+            { name: 'var', type: 'dir' },
+            { name: 'tmp_file', type: 'file' }
+          ]
+        }
+      },
+      beforeCursor: "'/foo/bar/",
+      afterCursor: '',
+      expectedSuggestions: ['tmp_file', 'var']
+    });
+  });
+});

+ 0 - 177
desktop/core/src/desktop/static/desktop/js/hue.colors.js

@@ -1,177 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-var HueColors = {
-
-  CUIScaleColors: [
-    {
-      name: 'gray', colors: ['#F8F8F8', '#E7E7E7', '#E0E0E0', '#DCDCDC', '#C8C8C8', '#B4B4B4', '#A0A0A0', '#787878',
-      '#424242', '#212121']
-    },
-    {
-      name: 'blue-gray', colors: ['#ECEFF1', '#CFD8DC', '#B0BEC5', '#90A4AE', '#78909C', '#607D8B', '#546E7A',
-      '#455A64', '#36454F', '#232C34']
-    },
-    {
-      name: 'blue', colors: ['#E9F6FB', '#BEE4F5', '#A9DBF1', '#7ECAEB', '#53B8E4', '#29A7DE', '#2496C7', '#0B7FAD',
-      '#1C749B', '#186485']
-    },
-    {
-      name: 'steel', colors: ['#E8EEEE', '#C6D6D6', '#A0BABA', '#7A9F9F', '#5D8A8A', '#417575', '#3C6C6C', '#345E5E',
-      '#2D5252', '#274646']
-    },
-    {
-      name: 'teal', colors: ['#E0F6F5', '#B3EAE6', '#80DCD5', '#4DCEC4', '#26C3B7', '#00B9AA', '#00AA9D', '#009488',
-      '#008177', '#006F66']
-    },
-    {
-      name: 'green', colors: ['#E2F3EA', '#B7E2CD', '#87CEAB', '#57BB89', '#33AC6F', '#0F9D56', '#0E914F', '#0C7E45',
-      '#0A6E3C', '#095E34']
-    },
-    {
-      name: 'lime', colors: ['#EDF5E2', '#D2E6B9', '#B4D689', '#96C55A', '#7FB836', '#69AC13', '#619F12', '#548A0F',
-      '#49780D', '#3F670B']
-    },
-    {
-      name: 'yellow', colors: ['#FFFCE6', '#FFFACC', '#FFF599', '#FFF066', '#FFEB3B', '#FFE600', '#E6CF00', '#B3A100',
-      '#807300', '#4D4500']
-    },
-    {
-      name: 'orange', colors: ['#FBF1E1', '#FFE8AF', '#FFD466', '#EDB233', '#EBA81A', '#E99F01', '#D18F00', '#BA7F00',
-      '#A36F00', '#8B572A']
-    },
-    {
-      name: 'red', colors: ['#FFE5E5', '#FFCCCC', '#FFB2B2', '#E7808D', '#DE4D5F', '#D0021B', '#BB0118', '#A60115',
-      '#910112', '#7C0110']
-    },
-    {
-      name: 'pink', colors: ['#F2DEDE', '#F3BFD4', '#EC93B7', '#E4689A', '#DE4784', '#D8276F', '#C72466', '#AD1F59',
-      '#971B4D', '#821743']
-    },
-    {
-      name: 'purple', colors: ['#EFE9F5', '#D8C8E7', '#BDA3D6', '#A37EC6', '#8F62B9', '#7B46AD', '#71419F', '#62388A',
-      '#563179', '#4A2A68']
-    },
-    {
-      name: 'purple-gray', colors: ['#F1EFEF', '#D5CFD1', '#BAB0B3', '#ACA0A4', '#9F9095', '#977F86', '#837077',
-      '#766168', '#6A575D', '#5E4D53']
-    },
-    {
-      name: 'green-gray', colors: ['#E9E8E3', '#C8C6BA', '#B2AF9F', '#A7A391', '#9C9883', '#918D76', '#827E6A',
-      '#74705E', '#656252', '#575446']
-    }],
-
-  hexToR: function (h) {
-    return parseInt((this.cutHex(h)).substring(0, 2), 16)
-  },
-  hexToG: function (h) {
-    return parseInt((this.cutHex(h)).substring(2, 4), 16)
-  },
-  hexToB: function (h) {
-    return parseInt((this.cutHex(h)).substring(4, 6), 16)
-  },
-  cutHex: function (h) {
-    return (h.charAt(0) == "#") ? h.substring(1, 7) : h
-  },
-  decToHex: function (i) {
-    return (i + 0x100).toString(16).substr(-2).toUpperCase();
-  },
-  scale: function (from, to, bands) {
-    var _fromRGB = [this.hexToR(from), this.hexToG(from), this.hexToB(from)],
-      _toRGB = [this.hexToR(to), this.hexToG(to), this.hexToB(to)],
-      _i,
-      _delta = [],
-      _bands = [];
-
-    for (_i = 0; _i < 4; _i++) {
-      _delta[_i] = (_fromRGB[_i] - _toRGB[_i]) / (bands + 1);
-    }
-
-    for (_i = 0; _i < bands; _i++) {
-      var r = Math.round(_fromRGB[0] - _delta[0] * _i);
-      var g = Math.round(_fromRGB[1] - _delta[1] * _i);
-      var b = Math.round(_fromRGB[2] - _delta[2] * _i);
-      _bands.push("#" + this.decToHex(r) + this.decToHex(g) + this.decToHex(b));
-    }
-    return _bands;
-  },
-
-  getNormalizedColors: function () {
-    var normalizedColors = {};
-    this.CUIScaleColors.forEach(function (scaleDef) {
-      normalizedColors[scaleDef.name] = scaleDef.colors;
-    });
-    return normalizedColors;
-  },
-
-  getCUIChartColors: function () {
-    var i;
-
-    var normalizedColors = this.getNormalizedColors();
-
-    // optimal visual sequence by contrasting colors
-    var sequence = ['blue', 'lime', 'blue-gray', 'pink', 'steel', 'purple', 'teal', 'red', 'orange', 'green'],
-      wholeSpectrum = [],
-      sequenceHalfLength = sequence.length / 2;
-
-    function addMain(mainSwatch) {
-      wholeSpectrum.push({color: normalizedColors[mainSwatch][sequenceHalfLength]});
-    }
-
-    function addPlus(mainSwatch) {
-      wholeSpectrum.push({color: normalizedColors[mainSwatch][sequenceHalfLength + i]});
-    }
-
-    function addMinus(mainSwatch) {
-      wholeSpectrum.push({color: normalizedColors[mainSwatch][sequenceHalfLength - i]});
-    }
-
-    for (i = 1; i < sequenceHalfLength; i++) {
-      if (i === 1) {
-        sequence.forEach(addMain);
-      }
-
-      sequence.forEach(addPlus);
-      sequence.forEach(addMinus);
-    }
-    return wholeSpectrum;
-  },
-
-  d3Scale: function () {
-    return d3v3.scale.category20().range().concat(d3v3.scale.category20b().range().concat(d3v3.scale.category20c().range()));
-  },
-  cuiD3Scale: function (swatch) {
-    var colors = this.getCUIChartColors().map(function (c) {
-      return c.color;
-    });
-    if (swatch) {
-      this.CUIScaleColors.forEach(function (s) {
-        if (s.name === swatch) {
-          colors = s.colors;
-        }
-      });
-    }
-    return colors;
-  },
-  LIGHT_BLUE: "#DBE8F1",
-  BLUE: "#87BAD5",
-  DARK_BLUE: "#0B7FAD",
-  DARKER_BLUE: "#205875",
-  PURPLE: "#C0B1E9",
-  GRAY: "#666666",
-  WHITE: "#FFFFFF",
-  ORANGE: "#FF7F0E"
-};

+ 0 - 1748
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -1,1748 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-var AutocompleteResults = (function () {
-
-  var normalizedColors = HueColors.getNormalizedColors();
-
-  var COLORS = {
-    POPULAR: normalizedColors['blue'][7],
-    KEYWORD: normalizedColors['blue'][4],
-    COLUMN: normalizedColors['green'][2],
-    TABLE: normalizedColors['pink'][3],
-    DATABASE: normalizedColors['teal'][5],
-    SAMPLE: normalizedColors['purple'][5],
-    IDENT_CTE_VAR: normalizedColors['orange'][3],
-    UDF: normalizedColors['purple-gray'][3],
-    HDFS: normalizedColors['red'][2]
-  };
-
-  var CATEGORIES = {
-    ALL: { id: 'all', color: HueColors.BLUE, label: HUE_I18n.autocomplete.category.all },
-    POPULAR: { id: 'popular', color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular },
-    POPULAR_AGGREGATE: { id: 'popularAggregate', weight: 1500, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'agg-udf' },
-    POPULAR_GROUP_BY: { id: 'popularGroupBy', weight: 1300, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'group-by' },
-    POPULAR_ORDER_BY: { id: 'popularOrderBy', weight: 1200, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'order-by' },
-    POPULAR_FILTER: { id: 'popularFilter', weight: 1400, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'filter' },
-    POPULAR_ACTIVE_JOIN: { id: 'popularActiveJoin', weight: 1500, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'join' },
-    POPULAR_JOIN_CONDITION: { id: 'popularJoinCondition', weight: 1500, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'join-condition' },
-    COLUMN: { id: 'column', weight: 1000, color: COLORS.COLUMN, label: HUE_I18n.autocomplete.category.column, detailsTemplate: 'column' },
-    SAMPLE: { id: 'sample',weight: 900, color: COLORS.SAMPLE, label: HUE_I18n.autocomplete.category.sample, detailsTemplate: 'value' },
-    IDENTIFIER: { id: 'identifier', weight: 800, color: COLORS.IDENT_CTE_VAR, label: HUE_I18n.autocomplete.category.identifier, detailsTemplate: 'identifier' },
-    CTE: { id: 'cte', weight: 700, color: COLORS.IDENT_CTE_VAR, label: HUE_I18n.autocomplete.category.cte, detailsTemplate: 'cte' },
-    TABLE: { id: 'table', weight: 600, color: COLORS.TABLE, label: HUE_I18n.autocomplete.category.table, detailsTemplate: 'table' },
-    DATABASE: { id: 'database', weight: 500, color: COLORS.DATABASE, label: HUE_I18n.autocomplete.category.database, detailsTemplate: 'database' },
-    UDF: { id: 'udf', weight: 400, color: COLORS.UDF, label: HUE_I18n.autocomplete.category.udf, detailsTemplate: 'udf' },
-    OPTION: { id: 'option', weight: 400, color: COLORS.UDF, label: HUE_I18n.autocomplete.category.option, detailsTemplate: 'option' },
-    HDFS: { id: 'hdfs', weight: 300, color: COLORS.HDFS, label: HUE_I18n.autocomplete.category.hdfs, detailsTemplate: 'hdfs' },
-    VIRTUAL_COLUMN: { id: 'virtualColumn', weight: 200, color: COLORS.COLUMN, label: HUE_I18n.autocomplete.category.column, detailsTemplate: 'column' },
-    COLREF_KEYWORD: { id: 'colrefKeyword', weight: 100, color: COLORS.KEYWORD, label: HUE_I18n.autocomplete.category.keyword, detailsTemplate: 'keyword' },
-    VARIABLE: { id: 'variable', weight: 50, color: COLORS.IDENT_CTE_VAR, label: HUE_I18n.autocomplete.category.variable, detailsTemplate: 'variable' },
-    KEYWORD: { id: 'keyword', weight: 0, color: COLORS.KEYWORD, label: HUE_I18n.autocomplete.category.keyword, detailsTemplate: 'keyword' },
-    POPULAR_JOIN: { id: 'popularJoin', weight: 1500, color: COLORS.POPULAR, label: HUE_I18n.autocomplete.category.popular, detailsTemplate: 'join' }
-  };
-
-  var POPULAR_CATEGORIES = [CATEGORIES.POPULAR_AGGREGATE, CATEGORIES.POPULAR_GROUP_BY, CATEGORIES.POPULAR_ORDER_BY, CATEGORIES.POPULAR_FILTER, CATEGORIES.POPULAR_ACTIVE_JOIN, CATEGORIES.POPULAR_JOIN_CONDITION, CATEGORIES.POPULAR_JOIN];
-
-  var adjustWeightsBasedOnPopularity = function(suggestions, totalPopularity) {
-    suggestions.forEach(function (suggestion) {
-      var relativePopularity = Math.round(100 * suggestion.details.popularity.popularity / totalPopularity);
-      if (relativePopularity < 5) {
-        suggestion.popular(false);
-      } else {
-        suggestion.details.popularity.relativePopularity = Math.round(100 * suggestion.details.popularity.popularity / totalPopularity);
-        suggestion.weightAdjust = suggestion.details.popularity.relativePopularity;
-      }
-    });
-  };
-
-  var initLoading = function (loadingObservable, deferred) {
-    loadingObservable(true);
-    deferred.always(function () {
-      loadingObservable(false);
-    })
-  };
-
-  var locateSubQuery = function (subQueries, subQueryName) {
-    if (typeof subQueries === 'undefined') {
-      return null;
-    }
-    var foundSubQueries = subQueries.filter(function (knownSubQuery) {
-      return hueUtils.equalIgnoreCase(knownSubQuery.alias, subQueryName)
-    });
-    if (foundSubQueries.length > 0) {
-      return foundSubQueries[0];
-    }
-    return null;
-  };
-
-  /**
-   *
-   * @param options
-   * @constructor
-   */
-  function AutocompleteResults (options) {
-    var self = this;
-    self.apiHelper = window.apiHelper;
-    self.snippet = options.snippet;
-    self.editor = options.editor;
-    self.temporaryOnly = options.snippet.autocompleteSettings && options.snippet.autocompleteSettings.temporaryOnly;
-
-    self.sortOverride = null;
-
-    huePubSub.subscribe('editor.autocomplete.temporary.sort.override', function (sortOverride) {
-      self.sortOverride = sortOverride;
-    });
-
-    self.entries = ko.observableArray();
-
-    self.lastKnownRequests = [];
-    self.cancellablePromises = [];
-    self.activeDeferrals = [];
-
-    self.loadingKeywords = ko.observable(false);
-    self.loadingFunctions = ko.observable(false);
-    self.loadingDatabases = ko.observable(false);
-    self.loadingTables = ko.observable(false);
-    self.loadingColumns = ko.observable(false);
-    self.loadingValues = ko.observable(false);
-    self.loadingPaths = ko.observable(false);
-    self.loadingJoins = ko.observable(false);
-    self.loadingJoinConditions = ko.observable(false);
-    self.loadingAggregateFunctions = ko.observable(false);
-    self.loadingGroupBys = ko.observable(false);
-    self.loadingOrderBys = ko.observable(false);
-    self.loadingFilters = ko.observable(false);
-    self.loadingPopularTables = ko.observable(false);
-    self.loadingPopularColumns = ko.observable(false);
-
-    self.appendEntries = function (entries) {
-      self.entries(self.entries().concat(entries));
-    };
-
-    self.loading = ko.pureComputed(function () {
-      return self.loadingKeywords() || self.loadingFunctions() || self.loadingDatabases() || self.loadingTables() ||
-              self.loadingColumns() || self.loadingValues() || self.loadingPaths() || self.loadingJoins() ||
-              self.loadingJoinConditions() || self.loadingAggregateFunctions() || self.loadingGroupBys() ||
-              self.loadingOrderBys() || self.loadingFilters() || self.loadingPopularTables() ||
-              self.loadingPopularColumns();
-    }).extend({ rateLimit: 200 });
-
-    self.filter = ko.observable();
-
-    self.availableCategories = ko.observableArray([CATEGORIES.ALL]);
-
-    self.availableCategories.subscribe(function (newCategories) {
-      if (newCategories.indexOf(self.activeCategory()) === -1) {
-        self.activeCategory(CATEGORIES.ALL)
-      }
-    });
-
-    self.activeCategory = ko.observable(CATEGORIES.ALL);
-
-    var updateCategories = function (suggestions) {
-      var newCategories =  {};
-      suggestions.forEach(function (suggestion) {
-        if (suggestion.popular() && ! newCategories[CATEGORIES.POPULAR.label]) {
-          newCategories[CATEGORIES.POPULAR.label] = CATEGORIES.POPULAR;
-        } else if (suggestion.category === CATEGORIES.TABLE || suggestion.category === CATEGORIES.COLUMN || suggestion.category === CATEGORIES.UDF) {
-          if (!newCategories[suggestion.category.label]) {
-            newCategories[suggestion.category.label] = suggestion.category;
-          }
-        }
-      });
-      var result = [];
-      Object.keys(newCategories).forEach(function (key) {
-        result.push(newCategories[key]);
-      });
-      result.sort(function (a, b) { return a.label.localeCompare(b.label)});
-      result.unshift(CATEGORIES.ALL);
-      self.availableCategories(result);
-    };
-
-    self.filtered = ko.pureComputed(function () {
-      var result = self.entries();
-
-      if (self.filter()) {
-        result = sqlUtils.autocompleteFilter(self.filter(), result);
-        huePubSub.publish('hue.ace.autocompleter.match.updated');
-      }
-
-      updateCategories(result);
-
-      var activeCategory = self.activeCategory();
-
-      var categoriesCount = {};
-
-      result = result.filter(function (suggestion) {
-        if (typeof categoriesCount[suggestion.category.id] === 'undefined') {
-          categoriesCount[suggestion.category.id] = 0;
-        } else {
-          categoriesCount[suggestion.category.id]++;
-        }
-        if (activeCategory !== CATEGORIES.POPULAR && categoriesCount[suggestion.category.id] >= 10 && POPULAR_CATEGORIES.indexOf(suggestion.category) !== -1) {
-          return false;
-        }
-        return activeCategory === CATEGORIES.ALL || activeCategory === suggestion.category || (activeCategory === CATEGORIES.POPULAR && suggestion.popular());
-      });
-
-      sqlUtils.sortSuggestions(result, self.filter(), self.sortOverride);
-      self.sortOverride = null;
-      return result;
-    }).extend({ rateLimit: 200 });
-  }
-
-  AutocompleteResults.prototype.cancelRequests = function () {
-    var self = this;
-
-    while (self.lastKnownRequests.length) {
-      self.apiHelper.cancelActiveRequest(self.lastKnownRequests.pop());
-    }
-
-    while (self.cancellablePromises.length) {
-      var promise = self.cancellablePromises.pop();
-      if (promise.cancel) {
-        promise.cancel();
-      }
-    }
-  };
-
-  AutocompleteResults.prototype.update = function (parseResult) {
-    var self = this;
-
-    while (self.activeDeferrals.length > 0) {
-      self.activeDeferrals.pop().reject();
-    }
-
-    self.activeDatabase = parseResult.useDatabase || self.snippet.database();
-    self.parseResult = parseResult;
-
-    self.entries([]);
-
-    self.loadingKeywords(false);
-    self.loadingFunctions(false);
-    self.loadingDatabases(false);
-    self.loadingTables(false);
-    self.loadingColumns(false);
-    self.loadingValues(false);
-    self.loadingPaths(false);
-    self.loadingJoins(false);
-    self.loadingJoinConditions(false);
-    self.loadingAggregateFunctions(false);
-    self.loadingGroupBys(false);
-    self.loadingOrderBys(false);
-    self.loadingFilters(false);
-    self.loadingPopularTables(false);
-    self.loadingPopularColumns(false);
-
-    self.filter('');
-
-    var colRefDeferred = self.handleColumnReference();
-    self.activeDeferrals.push(colRefDeferred);
-    var databasesDeferred = self.loadDatabases();
-    self.activeDeferrals.push(databasesDeferred);
-
-    self.handleKeywords(colRefDeferred);
-    self.handleIdentifiers();
-    self.handleColumnAliases();
-    self.handleCommonTableExpressions();
-    self.handleOptions();
-    self.handleFunctions(colRefDeferred);
-    self.handleDatabases(databasesDeferred);
-    var tablesDeferred = self.handleTables(databasesDeferred);
-    self.activeDeferrals.push(tablesDeferred);
-    var columnsDeferred = self.handleColumns(colRefDeferred, tablesDeferred);
-    self.activeDeferrals.push(columnsDeferred);
-    self.handleValues(colRefDeferred);
-    self.activeDeferrals.push(self.handlePaths());
-
-    if (!self.temporaryOnly) {
-      self.activeDeferrals.push(self.handleJoins());
-      self.activeDeferrals.push(self.handleJoinConditions());
-      self.activeDeferrals.push(self.handleAggregateFunctions());
-      self.activeDeferrals.push(self.handleGroupBys(columnsDeferred));
-      self.activeDeferrals.push(self.handleOrderBys(columnsDeferred));
-      self.activeDeferrals.push(self.handleFilters());
-      self.activeDeferrals.push(self.handlePopularTables(tablesDeferred));
-      self.activeDeferrals.push(self.handlePopularColumns(columnsDeferred));
-    }
-
-    $.when.apply($, self.activeDeferrals).always(function () {
-      huePubSub.publish('hue.ace.autocompleter.done');
-    });
-  };
-
-  /**
-   * For some suggestions the column type is needed, for instance with functions we should only suggest
-   * columns that matches the argument type, cos(|) etc.
-   *
-   * The deferred will always resolve, and the default values is { type: 'T' }
-   *
-   * @returns {object} - jQuery Deferred
-   */
-  AutocompleteResults.prototype.handleColumnReference = function () {
-    var self = this;
-    var colRefDeferred = $.Deferred();
-    if (self.parseResult.colRef) {
-      var colRefCallback = function (catalogEntry) {
-        self.cancellablePromises.push(catalogEntry.getSourceMeta({ silenceErrors: true, cancellable: true }).done(function (sourceMeta) {
-          if (typeof sourceMeta.type !== 'undefined') {
-            colRefDeferred.resolve(sourceMeta);
-          } else {
-            colRefDeferred.resolve({ type: 'T' })
-          }
-        }).fail(function () {
-          colRefDeferred.resolve({ type: 'T' })
-        }));
-      };
-
-      var foundVarRef = self.parseResult.colRef.identifierChain.some(function (identifier) {
-        return typeof identifier.name !== 'undefined' && identifier.name.indexOf('${') === 0;
-      });
-
-      if (foundVarRef) {
-        colRefDeferred.resolve({ type: 'T' });
-      } else {
-        self.fetchFieldsForIdentifiers(self.parseResult.colRef.identifierChain).done(colRefCallback).fail(function () {
-          colRefDeferred.resolve({ type: 'T' });
-        });
-      }
-    } else {
-      colRefDeferred.resolve({ type: 'T' });
-    }
-    return colRefDeferred;
-  };
-
-  AutocompleteResults.prototype.loadDatabases = function () {
-    var self = this;
-    var databasesDeferred = $.Deferred();
-    dataCatalog.getEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), path: [], temporaryOnly: self.temporaryOnly }).done(function (entry) {
-      self.cancellablePromises.push(entry.getChildren({ silenceErrors: true, cancellable: true }).done(function (databases) {
-        databasesDeferred.resolve(databases);
-      }).fail(databasesDeferred.reject));
-    }).fail(databasesDeferred.reject);
-    return databasesDeferred;
-  };
-
-  AutocompleteResults.prototype.handleKeywords = function (colRefDeferred) {
-    var self = this;
-    if (self.parseResult.suggestKeywords) {
-      var keywordSuggestions = $.map(self.parseResult.suggestKeywords, function (keyword) {
-        return {
-          value: self.parseResult.lowerCase ? keyword.value.toLowerCase() : keyword.value,
-          meta: HUE_I18n.autocomplete.meta.keyword,
-          category: CATEGORIES.KEYWORD,
-          weightAdjust: keyword.weight,
-          popular: ko.observable(false),
-          details: null
-        };
-      });
-      self.appendEntries(keywordSuggestions);
-    }
-
-    if (self.parseResult.suggestColRefKeywords) {
-      initLoading(self.loadingKeywords, colRefDeferred);
-      // Wait for the column reference type to be resolved to pick the right keywords
-      colRefDeferred.done(function (colRef) {
-        var colRefKeywordSuggestions = [];
-        Object.keys(self.parseResult.suggestColRefKeywords).forEach(function (typeForKeywords) {
-          if (SqlFunctions.matchesType(self.snippet.type(), [typeForKeywords], [colRef.type.toUpperCase()])) {
-            self.parseResult.suggestColRefKeywords[typeForKeywords].forEach(function (keyword) {
-              colRefKeywordSuggestions.push({
-                value: self.parseResult.lowerCase ? keyword.toLowerCase() : keyword,
-                meta: HUE_I18n.autocomplete.meta.keyword,
-                category: CATEGORIES.COLREF_KEYWORD,
-                popular: ko.observable(false),
-                details: {
-                  type: colRef.type
-                }
-              });
-            })
-          }
-        });
-        self.appendEntries(colRefKeywordSuggestions);
-      });
-    }
-  };
-
-  AutocompleteResults.prototype.handleIdentifiers = function () {
-    var self = this;
-    if (self.parseResult.suggestIdentifiers) {
-      var identifierSuggestions = [];
-      self.parseResult.suggestIdentifiers.forEach(function (identifier) {
-        identifierSuggestions.push({
-          value: identifier.name,
-          meta: identifier.type,
-          category: CATEGORIES.IDENTIFIER,
-          popular: ko.observable(false),
-          details: null
-        });
-      });
-      self.appendEntries(identifierSuggestions);
-    }
-  };
-
-  AutocompleteResults.prototype.handleColumnAliases = function () {
-    var self = this;
-    if (self.parseResult.suggestColumnAliases) {
-      var columnAliasSuggestions = [];
-      self.parseResult.suggestColumnAliases.forEach(function (columnAlias) {
-        var type = columnAlias.types && columnAlias.types.length == 1 ? columnAlias.types[0] : 'T';
-        if (type === 'COLREF') {
-          columnAliasSuggestions.push({
-            value: columnAlias.name,
-            meta: HUE_I18n.autocomplete.meta.alias,
-            category: CATEGORIES.COLUMN,
-            popular: ko.observable(false),
-            details: columnAlias
-          });
-        } else {
-          columnAliasSuggestions.push({
-            value: columnAlias.name,
-            meta: type,
-            category: CATEGORIES.COLUMN,
-            popular: ko.observable(false),
-            details: columnAlias
-          });
-        }
-      });
-      self.appendEntries(columnAliasSuggestions);
-    }
-  };
-
-  AutocompleteResults.prototype.handleCommonTableExpressions = function () {
-    var self = this;
-    if (self.parseResult.suggestCommonTableExpressions) {
-      var commonTableExpressionSuggestions = [];
-      self.parseResult.suggestCommonTableExpressions.forEach(function (expression) {
-        var prefix = expression.prependQuestionMark ? '? ' : '';
-        if (expression.prependFrom) {
-          prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
-        }
-        commonTableExpressionSuggestions.push({
-          value: prefix + expression.name,
-          filterValue: expression.name,
-          meta: HUE_I18n.autocomplete.meta.commonTableExpression,
-          category: CATEGORIES.CTE,
-          popular: ko.observable(false),
-          details: null
-        });
-      });
-      self.appendEntries(commonTableExpressionSuggestions);
-    }
-  };
-
-  AutocompleteResults.prototype.handleOptions = function () {
-    var self = this;
-    if (self.parseResult.suggestSetOptions) {
-      var suggestions = [];
-      SqlSetOptions.suggestOptions(self.snippet.type(), suggestions, CATEGORIES.OPTION);
-      self.appendEntries(suggestions);
-    }
-  };
-
-  AutocompleteResults.prototype.handleFunctions = function (colRefDeferred) {
-    var self = this;
-    if (self.parseResult.suggestFunctions) {
-      var functionSuggestions = [];
-      if (self.parseResult.suggestFunctions.types && self.parseResult.suggestFunctions.types[0] === 'COLREF') {
-        initLoading(self.loadingFunctions, colRefDeferred);
-
-        colRefDeferred.done(function (colRef) {
-          var functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(self.snippet.type(), [colRef.type.toUpperCase()], self.parseResult.suggestAggregateFunctions || false, self.parseResult.suggestAnalyticFunctions || false);
-
-          Object.keys(functionsToSuggest).forEach(function (name) {
-            functionSuggestions.push({
-              category: CATEGORIES.UDF,
-              value: name + '()',
-              meta: functionsToSuggest[name].returnTypes.join('|'),
-              weightAdjust: colRef.type.toUpperCase() !== 'T' && functionsToSuggest[name].returnTypes.some(function (otherType) {
-                  return otherType === colRef.type.toUpperCase();
-              }) ? 1 : 0,
-              popular: ko.observable(false),
-              details: functionsToSuggest[name]
-            })
-          });
-
-          self.appendEntries(functionSuggestions);
-        });
-      } else {
-        var types = self.parseResult.suggestFunctions.types || ['T'];
-        var functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(self.snippet.type(), types, self.parseResult.suggestAggregateFunctions || false, self.parseResult.suggestAnalyticFunctions || false);
-
-        Object.keys(functionsToSuggest).forEach(function (name) {
-          functionSuggestions.push({
-            category: CATEGORIES.UDF,
-            value: name + '()',
-            meta: functionsToSuggest[name].returnTypes.join('|'),
-            weightAdjust: types[0].toUpperCase() !== 'T' && functionsToSuggest[name].returnTypes.some(function (otherType) {
-              return otherType === types[0].toUpperCase();
-            }) ? 1 : 0,
-            popular: ko.observable(false),
-            details: functionsToSuggest[name]
-          })
-        });
-        self.appendEntries(functionSuggestions);
-      }
-    }
-  };
-
-  AutocompleteResults.prototype.handleDatabases = function (databasesDeferred) {
-    var self = this;
-    var suggestDatabases = self.parseResult.suggestDatabases;
-    if (suggestDatabases) {
-      initLoading(self.loadingDatabases, databasesDeferred);
-
-      var prefix = suggestDatabases.prependQuestionMark ? '? ' : '';
-      if (suggestDatabases.prependFrom) {
-        prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
-      }
-      var databaseSuggestions = [];
-
-      databasesDeferred.done(function (catalogEntries) {
-        catalogEntries.forEach(function (dbEntry) {
-          databaseSuggestions.push({
-            value: prefix + sqlUtils.backTickIfNeeded(self.snippet.type(), dbEntry.name) + (suggestDatabases.appendDot ? '.' : ''),
-            filterValue: dbEntry.name,
-            meta: HUE_I18n.autocomplete.meta.database,
-            category: CATEGORIES.DATABASE,
-            popular: ko.observable(false),
-            hasCatalogEntry: true,
-            details: dbEntry
-          })
-        });
-        self.appendEntries(databaseSuggestions);
-      });
-    }
-  };
-
-  AutocompleteResults.prototype.handleTables = function (databasesDeferred) {
-    var self = this;
-    var tablesDeferred = $.Deferred();
-
-    if (self.parseResult.suggestTables) {
-      var suggestTables = self.parseResult.suggestTables;
-      var fetchTables = function () {
-        initLoading(self.loadingTables, tablesDeferred);
-        tablesDeferred.done(self.appendEntries);
-
-        var prefix = suggestTables.prependQuestionMark ? '? ' : '';
-        if (suggestTables.prependFrom) {
-          prefix += self.parseResult.lowerCase ? 'from ' : 'FROM ';
-        }
-
-
-        var database = suggestTables.identifierChain && suggestTables.identifierChain.length === 1 ? suggestTables.identifierChain[0].name : self.activeDatabase;
-
-        dataCatalog.getEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), path: [ database ], temporaryOnly: self.temporaryOnly }).done(function (dbEntry) {
-          self.cancellablePromises.push(dbEntry.getChildren({ silenceErrors: true, cancellable: true }).done(function (tableEntries) {
-            var tableSuggestions = [];
-
-            tableEntries.forEach(function (tableEntry) {
-              if (suggestTables.onlyTables && !tableEntry.isTable() || suggestTables.onlyViews && !tableEntry.isView()) {
-                return;
-              }
-              tableSuggestions.push({
-                value: prefix + sqlUtils.backTickIfNeeded(self.snippet.type(), tableEntry.name),
-                filterValue: tableEntry.name,
-                tableName: tableEntry.name,
-                meta: HUE_I18n.autocomplete.meta[tableEntry.getType().toLowerCase()],
-                category: CATEGORIES.TABLE,
-                popular: ko.observable(false),
-                hasCatalogEntry: true,
-                details: tableEntry
-              });
-            });
-            tablesDeferred.resolve(tableSuggestions);
-          }).fail(tablesDeferred.reject));
-        }).fail(tablesDeferred.reject);
-      };
-
-      if (self.snippet.type() === 'impala' && self.parseResult.suggestTables.identifierChain && self.parseResult.suggestTables.identifierChain.length === 1) {
-        databasesDeferred.done(function (databases) {
-          var foundDb = databases.some(function (dbEntry) {
-            return hueUtils.equalIgnoreCase(dbEntry.name, self.parseResult.suggestTables.identifierChain[0].name);
-          });
-          if (foundDb) {
-            fetchTables();
-          } else {
-            self.parseResult.suggestColumns = { tables: [{ identifierChain: self.parseResult.suggestTables.identifierChain }] };
-            tablesDeferred.reject();
-          }
-        });
-      } else if (self.snippet.type() === 'impala' && self.parseResult.suggestTables.identifierChain && self.parseResult.suggestTables.identifierChain.length > 1) {
-        self.parseResult.suggestColumns = { tables: [{ identifierChain: self.parseResult.suggestTables.identifierChain }] };
-        tablesDeferred.reject();
-      } else {
-        fetchTables();
-      }
-    } else {
-      tablesDeferred.reject();
-    }
-
-    return tablesDeferred;
-  };
-
-  AutocompleteResults.prototype.handleColumns = function (colRefDeferred, tablesDeferred) {
-    var self = this;
-    var columnsDeferred = $.Deferred();
-
-    tablesDeferred.always(function () {
-      if (self.parseResult.suggestColumns) {
-        initLoading(self.loadingColumns, columnsDeferred);
-        columnsDeferred.done(self.appendEntries);
-
-        var suggestColumns = self.parseResult.suggestColumns;
-        var columnSuggestions = [];
-        // For multiple tables we need to merge and make sure identifiers are unique
-        var columnDeferrals = [];
-
-        var waitForCols = function () {
-          $.when.apply($, columnDeferrals).always(function () {
-            self.mergeColumns(columnSuggestions);
-            if (self.snippet.type() === 'hive' && /[^\.]$/.test(self.editor().getTextBeforeCursor())) {
-              columnSuggestions.push({
-                value: 'BLOCK__OFFSET__INSIDE__FILE',
-                meta: HUE_I18n.autocomplete.meta.virtual,
-                category: CATEGORIES.VIRTUAL_COLUMN,
-                popular: ko.observable(false),
-                details: { name: 'BLOCK__OFFSET__INSIDE__FILE' }
-              });
-              columnSuggestions.push({
-                value: 'INPUT__FILE__NAME',
-                meta: HUE_I18n.autocomplete.meta.virtual,
-                category: CATEGORIES.VIRTUAL_COLUMN,
-                popular: ko.observable(false),
-                details: { name: 'INPUT__FILE__NAME' }
-              });
-            }
-            columnsDeferred.resolve(columnSuggestions);
-          });
-        };
-
-        if (suggestColumns.types && suggestColumns.types[0] === 'COLREF') {
-          colRefDeferred.done(function (colRef) {
-            suggestColumns.tables.forEach(function (table) {
-              columnDeferrals.push(self.addColumns(table, [colRef.type.toUpperCase()], columnSuggestions));
-            });
-            waitForCols();
-          });
-        } else {
-          suggestColumns.tables.forEach(function (table) {
-            columnDeferrals.push(self.addColumns(table, suggestColumns.types || ['T'], columnSuggestions));
-          });
-          waitForCols();
-        }
-      } else {
-        columnsDeferred.reject();
-      }
-    });
-
-    return columnsDeferred;
-  };
-
-  AutocompleteResults.prototype.addColumns = function (table, types, columnSuggestions) {
-    var self = this;
-    var addColumnsDeferred = $.Deferred();
-
-    if (typeof table.identifierChain !== 'undefined' && table.identifierChain.length === 1 && typeof table.identifierChain[0].cte !== 'undefined') {
-      if (typeof self.parseResult.commonTableExpressions !== 'undefined' && self.parseResult.commonTableExpressions.length > 0) {
-        self.parseResult.commonTableExpressions.every(function (cte) {
-          if (hueUtils.equalIgnoreCase(cte.alias, table.identifierChain[0].cte)) {
-            cte.columns.forEach(function (column) {
-              var type = typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
-              if (typeof column.alias !== 'undefined') {
-                columnSuggestions.push({
-                  value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
-                  filterValue: column.alias,
-                  meta: type,
-                  category: CATEGORIES.COLUMN,
-                  table: table,
-                  popular: ko.observable(false),
-                  details: column
-                })
-              } else if (typeof column.identifierChain !== 'undefined' && column.identifierChain.length > 0 && typeof column.identifierChain[column.identifierChain.length - 1].name !== 'undefined') {
-                columnSuggestions.push({
-                  value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.identifierChain[column.identifierChain.length - 1].name),
-                  filterValue: column.identifierChain[column.identifierChain.length - 1].name,
-                  meta: type,
-                  category: CATEGORIES.COLUMN,
-                  table: table,
-                  popular: ko.observable(false),
-                  details: column
-                })
-              }
-            });
-            return false;
-          }
-          return true;
-        })
-      }
-      addColumnsDeferred.resolve();
-    } else if (typeof table.identifierChain !== 'undefined' && table.identifierChain.length === 1 && typeof table.identifierChain[0].subQuery !== 'undefined') {
-      var foundSubQuery = locateSubQuery(self.parseResult.subQueries, table.identifierChain[0].subQuery);
-
-      var addSubQueryColumns = function (subQueryColumns) {
-        subQueryColumns.forEach(function (column) {
-          if (column.alias || column.identifierChain) {
-            // TODO: Potentially fetch column types for sub-queries, possible performance hit.
-            var type = typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
-            if (column.alias) {
-              columnSuggestions.push({
-                value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
-                filterValue: column.alias,
-                meta: type,
-                category: CATEGORIES.COLUMN,
-                table: table,
-                popular: ko.observable(false),
-                details: column
-              })
-            } else if (column.identifierChain && column.identifierChain.length > 0) {
-              columnSuggestions.push({
-                value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.identifierChain[column.identifierChain.length - 1].name),
-                filterValue: column.identifierChain[column.identifierChain.length - 1].name,
-                meta: type,
-                category: CATEGORIES.COLUMN,
-                table: table,
-                popular: ko.observable(false),
-                details: column
-              })
-            }
-          } else if (column.subQuery && foundSubQuery.subQueries) {
-            var foundNestedSubQuery = locateSubQuery(foundSubQuery.subQueries, column.subQuery);
-            if (foundNestedSubQuery !== null) {
-              addSubQueryColumns(foundNestedSubQuery.columns);
-            }
-          }
-        });
-      };
-      if (foundSubQuery !== null && foundSubQuery.columns.length > 0) {
-        addSubQueryColumns(foundSubQuery.columns);
-      }
-      addColumnsDeferred.resolve();
-    } else if (typeof table.identifierChain !== 'undefined') {
-      var addColumnsFromEntry = function (dataCatalogEntry) {
-        self.cancellablePromises.push(dataCatalogEntry.getSourceMeta({ silenceErrors: true, cancellable: true }).done(function (sourceMeta) {
-          self.cancellablePromises.push(dataCatalogEntry.getChildren({ silenceErrors: true, cancellable: true })
-            .done(function (childEntries) {
-              childEntries.forEach(function (childEntry) {
-                var name = sqlUtils.backTickIfNeeded(self.snippet.type(), childEntry.name);
-                if (self.snippet.type() === 'hive' && (childEntry.isArray() || childEntry.isMap())) {
-                  name += '[]';
-                }
-                  if (SqlFunctions.matchesType(self.snippet.type(), types, [childEntry.getType().toUpperCase()])
-                      || SqlFunctions.matchesType(self.snippet.type(), [childEntry.getType().toUpperCase()], types)
-                      || childEntry.getType === 'column'
-                      || childEntry.isComplex()) {
-                    columnSuggestions.push({
-                      value: name,
-                      meta: childEntry.getType(),
-                      table: table,
-                      category: CATEGORIES.COLUMN,
-                      popular: ko.observable(false),
-                      weightAdjust: types[0].toUpperCase() !== 'T' && types.some(function (type) { return hueUtils.equalIgnoreCase(type, childEntry.getType()) }) ? 1 : 0,
-                      hasCatalogEntry: true,
-                      details: childEntry
-                    });
-                  }
-              });
-              if (self.snippet.type() === 'hive' && (dataCatalogEntry.isArray() || dataCatalogEntry.isMap()) ) {
-                // Remove 'item' or 'value' and 'key' for Hive
-                columnSuggestions.pop();
-                if (dataCatalogEntry.isMap()) {
-                  columnSuggestions.pop();
-                }
-              }
-
-              var complexExtras = sourceMeta.value && sourceMeta.value.fields || sourceMeta.item && sourceMeta.item.fields;
-              if ((self.snippet.type() === 'impala' || self.snippet.type() === 'hive') && complexExtras) {
-                complexExtras.forEach(function (field) {
-                  var fieldType = field.type.indexOf('<') !== -1 ? field.type.substring(0, field.type.indexOf('<')) : field.type;
-                  columnSuggestions.push({
-                    value: field.name,
-                    meta: fieldType,
-                    table: table,
-                    category: CATEGORIES.COLUMN,
-                    popular: ko.observable(false),
-                    weightAdjust: types[0].toUpperCase() !== 'T' && types.some(function (type) { return hueUtils.equalIgnoreCase(type, fieldType) }) ? 1 : 0,
-                    hasCatalogEntry: false,
-                    details: field
-                  });
-                });
-              }
-              addColumnsDeferred.resolve();
-            }).fail(addColumnsDeferred.reject));
-        }).fail(addColumnsDeferred.reject));
-      };
-
-      if (self.parseResult.suggestColumns && self.parseResult.suggestColumns.identifierChain) {
-        self.fetchFieldsForIdentifiers(table.identifierChain.concat(self.parseResult.suggestColumns.identifierChain)).done(addColumnsFromEntry).fail(addColumnsDeferred.reject);
-      } else {
-        self.fetchFieldsForIdentifiers(table.identifierChain).done(addColumnsFromEntry).fail(addColumnsDeferred.reject);
-      }
-    } else {
-      addColumnsDeferred.resolve();
-    }
-    return addColumnsDeferred;
-  };
-
-  AutocompleteResults.prototype.mergeColumns = function (columnSuggestions) {
-    columnSuggestions.sort(function (a, b) {
-      return a.value.localeCompare(b.value);
-    });
-
-    for (var i = 0; i < columnSuggestions.length; i++) {
-      var suggestion = columnSuggestions[i];
-      suggestion.isColumn = true;
-      var hasDuplicates = false;
-      for (i; i + 1 < columnSuggestions.length && columnSuggestions[i + 1].value === suggestion.value; i++) {
-        var nextTable = columnSuggestions[i + 1].table;
-        if (typeof nextTable.alias !== 'undefined') {
-          columnSuggestions[i + 1].value = nextTable.alias + '.' + columnSuggestions[i + 1].value
-        } else if (typeof nextTable.identifierChain !== 'undefined' && nextTable.identifierChain.length > 0) {
-          var previousIdentifier = nextTable.identifierChain[nextTable.identifierChain.length - 1];
-          if (typeof previousIdentifier.name !== 'undefined') {
-            columnSuggestions[i + 1].value = previousIdentifier.name + '.' + columnSuggestions[i + 1].value;
-          } else if (typeof previousIdentifier.subQuery !== 'undefined') {
-            columnSuggestions[i + 1].value = previousIdentifier.subQuery + '.' + columnSuggestions[i + 1].value;
-          }
-        }
-        hasDuplicates = true;
-      }
-      if (typeof suggestion.table.alias !== 'undefined') {
-        suggestion.value = suggestion.table.alias + '.' + suggestion.value;
-      } else if (hasDuplicates && typeof suggestion.table.identifierChain !== 'undefined' && suggestion.table.identifierChain.length > 0) {
-        var lastIdentifier = suggestion.table.identifierChain[suggestion.table.identifierChain.length - 1];
-        if (typeof lastIdentifier.name !== 'undefined') {
-          suggestion.value = lastIdentifier.name + '.' + suggestion.value;
-        } else if (typeof lastIdentifier.subQuery !== 'undefined') {
-          suggestion.value = lastIdentifier.subQuery + '.' + suggestion.value;
-        }
-      }
-    }
-  };
-
-  AutocompleteResults.prototype.handleValues = function (colRefDeferred) {
-    var self = this;
-    var suggestValues = self.parseResult.suggestValues;
-    if (suggestValues) {
-      var valueSuggestions = [];
-      if (self.parseResult.colRef && self.parseResult.colRef.identifierChain) {
-        valueSuggestions.push({
-          value: '${' + self.parseResult.colRef.identifierChain[self.parseResult.colRef.identifierChain.length - 1].name + '}',
-          meta: HUE_I18n.autocomplete.meta.variable,
-          category: CATEGORIES.VARIABLE,
-          popular: ko.observable(false),
-          details: null
-        });
-      }
-      colRefDeferred.done(function (colRef) {
-        if (colRef.sample) {
-          var isString = colRef.type === "string";
-          var startQuote = suggestValues.partialQuote ? '' : '\'';
-          var endQuote = typeof suggestValues.missingEndQuote !== 'undefined' && suggestValues.missingEndQuote === false ? '' : suggestValues.partialQuote || '\'';
-          colRef.sample.forEach(function (sample) {
-            valueSuggestions.push({
-              value: isString ? startQuote + sample + endQuote : new String(sample),
-              meta: HUE_I18n.autocomplete.meta.sample,
-              category: CATEGORIES.SAMPLE,
-              popular: ko.observable(false),
-              details: null
-            })
-          });
-        }
-        self.appendEntries(valueSuggestions);
-      });
-    }
-  };
-
-  AutocompleteResults.prototype.handlePaths = function () {
-    var self = this;
-    var suggestHdfs = self.parseResult.suggestHdfs;
-    var pathsDeferred = $.Deferred();
-
-    if (suggestHdfs) {
-      initLoading(self.loadingPaths, pathsDeferred);
-      pathsDeferred.done(self.appendEntries);
-
-      var path = suggestHdfs.path;
-      if (path === '') {
-        self.appendEntries([{
-          value: 'adl://',
-          meta: HUE_I18n.autocomplete.meta.keyword,
-          category: CATEGORIES.KEYWORD,
-          weightAdjust: 0,
-          popular: ko.observable(false),
-          details: null
-        },{
-          value: 's3a://',
-          meta: HUE_I18n.autocomplete.meta.keyword,
-          category: CATEGORIES.KEYWORD,
-          weightAdjust: 0,
-          popular: ko.observable(false),
-          details: null
-        },{
-          value: 'hdfs://',
-          meta: HUE_I18n.autocomplete.meta.keyword,
-          category: CATEGORIES.KEYWORD,
-          weightAdjust: 0,
-          popular: ko.observable(false),
-          details: null
-        },{
-          value: '/',
-          meta: 'dir',
-          category: CATEGORIES.HDFS,
-          popular: ko.observable(false),
-          details: null
-        }]);
-      }
-
-      var fetchFunction = 'fetchHdfsPath';
-
-      if (/^s3a:\/\//i.test(path)) {
-        fetchFunction = 'fetchS3Path';
-        path = path.substring(5);
-      } else if (/^adl:\/\//i.test(path)) {
-        fetchFunction = 'fetchAdlsPath';
-        path = path.substring(5);
-      } else if (/^hdfs:\/\//i.test(path)) {
-        path = path.substring(6);
-      }
-
-      var parts = path.split('/');
-      // Drop the first " or '
-      parts.shift();
-      // Last one is either partial name or empty
-      parts.pop();
-
-      self.lastKnownRequests.push(self.apiHelper[fetchFunction]({
-        pathParts: parts,
-        successCallback: function (data) {
-          if (!data.error) {
-            var pathSuggestions = [];
-            data.files.forEach(function (file) {
-              if (file.name !== '..' && file.name !== '.') {
-                pathSuggestions.push({
-                  value: path === '' ? '/' + file.name : file.name,
-                  meta: file.type,
-                  category: CATEGORIES.HDFS,
-                  popular: ko.observable(false),
-                  details: file
-                });
-              }
-            });
-            pathsDeferred.resolve(pathSuggestions);
-          }
-          pathsDeferred.reject();
-        },
-        silenceErrors: true,
-        errorCallback: pathsDeferred.reject,
-        timeout: AUTOCOMPLETE_TIMEOUT
-      }));
-    } else {
-      pathsDeferred.reject();
-    }
-    return pathsDeferred;
-  };
-
-  AutocompleteResults.prototype.tableIdentifierChainsToPaths = function (tables) {
-    var self = this;
-    var paths = [];
-    tables.forEach(function (table) {
-      // Could be subquery
-      var isTable = table.identifierChain.every(function (identifier) { return typeof identifier.name !== 'undefined' });
-      if (isTable) {
-        var path = $.map(table.identifierChain, function (identifier) {
-          return identifier.name;
-        });
-        if (path.length === 1) {
-          path.unshift(self.activeDatabase);
-        }
-        paths.push(path);
-      }
-    });
-    return paths;
-  };
-
-  AutocompleteResults.prototype.handleJoins = function () {
-    var self = this;
-    var joinsDeferred = $.Deferred();
-    var suggestJoins = self.parseResult.suggestJoins;
-    if (HAS_OPTIMIZER && suggestJoins) {
-      initLoading(self.loadingJoins, joinsDeferred);
-      joinsDeferred.done(self.appendEntries);
-
-      var paths = self.tableIdentifierChainsToPaths(suggestJoins.tables);
-      if (paths.length) {
-        dataCatalog.getMultiTableEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), paths: paths }).done(function (multiTableEntry) {
-        self.cancellablePromises.push(multiTableEntry.getTopJoins({ silenceErrors: true, cancellable: true  }).done(function (topJoins) {
-          var joinSuggestions = [];
-          var totalCount = 0;
-          if (topJoins.values) {
-            topJoins.values.forEach(function (value) {
-
-              var joinType = value.joinType || 'join';
-              joinType += ' ';
-              var suggestionString = suggestJoins.prependJoin ? (self.parseResult.lowerCase ? joinType.toLowerCase() : joinType.toUpperCase()) : '';
-              var first = true;
-
-              var existingTables = {};
-              suggestJoins.tables.forEach(function (table) {
-                existingTables[table.identifierChain[table.identifierChain.length - 1].name] = true;
-              });
-
-              var joinRequired = false;
-              var tablesAdded = false;
-              value.tables.forEach(function (table) {
-                var tableParts = table.split('.');
-                if (!existingTables[tableParts[tableParts.length - 1]]) {
-                  tablesAdded = true;
-                  var identifier = self.convertNavOptQualifiedIdentifier(table, suggestJoins.tables);
-                  suggestionString += joinRequired ? (self.parseResult.lowerCase ? ' join ' : ' JOIN ') + identifier : identifier;
-                  joinRequired = true;
-                }
-              });
-
-              if (value.joinCols.length > 0) {
-                if (!tablesAdded && suggestJoins.prependJoin) {
-                  suggestionString = '';
-                  tablesAdded = true;
-                }
-                suggestionString += self.parseResult.lowerCase ? ' on ' : ' ON ';
-              }
-              if (tablesAdded) {
-                value.joinCols.forEach(function (joinColPair) {
-                  if (!first) {
-                    suggestionString += self.parseResult.lowerCase ? ' and ' : ' AND ';
-                  }
-                  suggestionString += self.convertNavOptQualifiedIdentifier(joinColPair.columns[0], suggestJoins.tables, self.snippet.type()) + ' = ' + self.convertNavOptQualifiedIdentifier(joinColPair.columns[1], suggestJoins.tables, self.snippet.type());
-                  first = false;
-                });
-                totalCount += value.totalQueryCount;
-                joinSuggestions.push({
-                  value: suggestionString,
-                  meta: HUE_I18n.autocomplete.meta.join,
-                  category: suggestJoins.prependJoin ? CATEGORIES.POPULAR_JOIN : CATEGORIES.POPULAR_ACTIVE_JOIN,
-                  popular: ko.observable(true),
-                  details: value
-                });
-              }
-            });
-            joinSuggestions.forEach(function (suggestion) {
-              suggestion.details.relativePopularity = totalCount === 0 ? suggestion.details.totalQueryCount : Math.round(100 * suggestion.details.totalQueryCount / totalCount);
-              suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
-            });
-          }
-          joinsDeferred.resolve(joinSuggestions);
-        }).fail(joinsDeferred.reject));
-      }).fail(joinsDeferred.reject);
-      } else {
-        joinsDeferred.reject();
-      }
-    } else {
-      joinsDeferred.reject();
-    }
-    return joinsDeferred;
-  };
-
-  AutocompleteResults.prototype.handleJoinConditions = function () {
-    var self = this;
-    var joinConditionsDeferred = $.Deferred();
-    var suggestJoinConditions = self.parseResult.suggestJoinConditions;
-    if (HAS_OPTIMIZER && suggestJoinConditions) {
-      initLoading(self.loadingJoinConditions, joinConditionsDeferred);
-      joinConditionsDeferred.done(self.appendEntries);
-
-      var paths = self.tableIdentifierChainsToPaths(suggestJoinConditions.tables);
-      if (paths.length) {
-        dataCatalog.getMultiTableEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), paths: paths }).done(function (multiTableEntry) {
-          self.cancellablePromises.push(multiTableEntry.getTopJoins({ silenceErrors: true, cancellable: true }).done(function (topJoins) {
-          var joinConditionSuggestions = [];
-          var totalCount = 0;
-          if (topJoins.values) {
-            topJoins.values.forEach(function (value) {
-              if (value.joinCols.length > 0) {
-                var suggestionString = suggestJoinConditions.prependOn ? (self.parseResult.lowerCase ? 'on ' : 'ON ') : '';
-                var first = true;
-                value.joinCols.forEach(function (joinColPair) {
-                  if (!first) {
-                    suggestionString += self.parseResult.lowerCase ? ' and ' : ' AND ';
-                  }
-                  suggestionString += self.convertNavOptQualifiedIdentifier(joinColPair.columns[0], suggestJoinConditions.tables) + ' = ' + self.convertNavOptQualifiedIdentifier(joinColPair.columns[1], suggestJoinConditions.tables);
-                  first = false;
-                });
-                totalCount += value.totalQueryCount;
-                joinConditionSuggestions.push({
-                  value: suggestionString,
-                  meta: HUE_I18n.autocomplete.meta.joinCondition,
-                  category: CATEGORIES.POPULAR_JOIN_CONDITION,
-                  popular: ko.observable(true),
-                  details: value
-                });
-              }
-            });
-            joinConditionSuggestions.forEach(function (suggestion) {
-              suggestion.details.relativePopularity = totalCount === 0 ? suggestion.details.totalQueryCount : Math.round(100 * suggestion.details.totalQueryCount / totalCount);
-              suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
-            });
-          }
-
-          joinConditionsDeferred.resolve(joinConditionSuggestions);
-        }).fail(joinConditionsDeferred.reject));
-        }).fail(joinConditionsDeferred.reject);
-      } else {
-        joinConditionsDeferred.reject();
-      }
-    } else {
-      joinConditionsDeferred.reject();
-    }
-
-    return joinConditionsDeferred;
-  };
-
-  AutocompleteResults.prototype.handleAggregateFunctions = function () {
-    var self = this;
-    var aggregateFunctionsDeferred = $.Deferred();
-
-    var suggestAggregateFunctions = self.parseResult.suggestAggregateFunctions;
-    if (HAS_OPTIMIZER && suggestAggregateFunctions && suggestAggregateFunctions.tables.length > 0) {
-      initLoading(self.loadingAggregateFunctions, aggregateFunctionsDeferred);
-      aggregateFunctionsDeferred.done(self.appendEntries);
-
-      var paths = self.tableIdentifierChainsToPaths(suggestAggregateFunctions.tables);
-      if (paths.length) {
-        dataCatalog.getMultiTableEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), paths: paths }).done(function (multiTableEntry) {
-          self.cancellablePromises.push(multiTableEntry.getTopAggs({ silenceErrors: true, cancellable: true }).done(function (topAggs) {
-            var aggregateFunctionsSuggestions = [];
-            if (topAggs.values && topAggs.values.length > 0) {
-
-              // Expand all column names to the fully qualified name including db and table.
-              topAggs.values.forEach(function (value) {
-                value.aggregateInfo.forEach(function (info) {
-                  value.aggregateClause = value.aggregateClause.replace(new RegExp('([^.])' + info.columnName, 'gi'), '$1' + info.databaseName + '.' + info.tableName + '.' + info.columnName);
-                });
-              });
-
-              // Substitute qualified table identifiers with either alias or table when multiple tables are present or just empty string
-              var substitutions = [];
-              suggestAggregateFunctions.tables.forEach(function (table) {
-                var replaceWith = table.alias ? table.alias + '.' : (suggestAggregateFunctions.tables.length > 1 ? table.identifierChain[table.identifierChain.length - 1].name + '.' : '');
-                if (table.identifierChain.length > 1) {
-                  substitutions.push({
-                    replace: new RegExp($.map(table.identifierChain, function (identifier) {
-                      return identifier.name
-                    }).join('\.') + '\.', 'gi'),
-                    with: replaceWith
-                  })
-                } else if (table.identifierChain.length === 1) {
-                  substitutions.push({
-                    replace: new RegExp(self.activeDatabase + '\.' + table.identifierChain[0].name + '\.', 'gi'),
-                    with: replaceWith
-                  });
-                  substitutions.push({
-                    replace: new RegExp(table.identifierChain[0].name + '\.', 'gi'),
-                    with: replaceWith
-                  })
-                }
-              });
-
-              var totalCount = 0;
-              topAggs.values.forEach(function (value) {
-                var clean = value.aggregateClause;
-                substitutions.forEach(function (substitution) {
-                  clean = clean.replace(substitution.replace, substitution.with);
-                });
-                totalCount += value.totalQueryCount;
-                value.function = SqlFunctions.findFunction(self.snippet.type(), value.aggregateFunction);
-                aggregateFunctionsSuggestions.push({
-                  value: clean,
-                  meta: value.function.returnTypes.join('|'),
-                  category: CATEGORIES.POPULAR_AGGREGATE,
-                  weightAdjust: Math.min(value.totalQueryCount, 99),
-                  popular: ko.observable(true),
-                  details: value
-                });
-              });
-
-              aggregateFunctionsSuggestions.forEach(function (suggestion) {
-                suggestion.details.relativePopularity = totalCount === 0 ? suggestion.details.totalQueryCount : Math.round(100 * suggestion.details.totalQueryCount / totalCount);
-                suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
-              });
-            }
-            aggregateFunctionsDeferred.resolve(aggregateFunctionsSuggestions);
-          }).fail(aggregateFunctionsDeferred.reject));
-        }).fail(aggregateFunctionsDeferred.reject);
-      } else {
-        aggregateFunctionsDeferred.reject();
-      }
-    } else {
-      aggregateFunctionsDeferred.reject();
-    }
-    return aggregateFunctionsDeferred;
-  };
-
-  /**
-   * Merges popular group by and order by columns with the column suggestions
-   *
-   * @param sourceDeferred
-   * @param columnsDeferred
-   * @param suggestions
-   */
-  var mergeWithColumns = function (sourceDeferred, columnsDeferred, suggestions) {
-    columnsDeferred.done(function (columns) {
-      var suggestionIndex = {};
-      suggestions.forEach(function (suggestion) {
-        suggestionIndex[suggestion.value] = suggestion;
-      });
-      columns.forEach(function (col) {
-        if (suggestionIndex[col.details.name]) {
-          col.category = suggestionIndex[col.details.name].category
-        }
-      });
-      sourceDeferred.resolve([]);
-    })
-  };
-
-  AutocompleteResults.prototype.handlePopularGroupByOrOrderBy = function (navOptAttribute, suggestSpec, deferred, columnsDeferred) {
-    var self = this;
-    var paths = [];
-    suggestSpec.tables.forEach(function (table) {
-      if (table.identifierChain) {
-        if (table.identifierChain.length === 1 && table.identifierChain[0].name) {
-          paths.push([self.activeDatabase, table.identifierChain[0].name])
-        } else if (table.identifierChain.length === 2 && table.identifierChain[0].name && table.identifierChain[1].name) {
-          paths.push([table.identifierChain[0].name, table.identifierChain[1].name]);
-        }
-      }
-    });
-
-    self.cancellablePromises.push(dataCatalog.getCatalog(self.snippet.type())
-      .loadNavOptPopularityForTables({ namespace: self.snippet.namespace(), compute: self.snippet.compute(), paths: paths, silenceErrors: true, cancellable: true }).done(function (entries) {
-        var totalColumnCount = 0;
-        var matchedEntries = [];
-        var prefix = suggestSpec.prefix ? (self.parseResult.lowerCase ? suggestSpec.prefix.toLowerCase() : suggestSpec.prefix) + ' ' : '';
-
-        entries.forEach(function (entry) {
-          if (entry.navOptPopularity[navOptAttribute]) {
-            totalColumnCount += entry.navOptPopularity[navOptAttribute].columnCount;
-            matchedEntries.push(entry);
-          }
-        });
-        if (totalColumnCount > 0) {
-          var suggestions = [];
-          matchedEntries.forEach(function (entry) {
-            var filterValue = self.createNavOptIdentifierForColumn(entry.navOptPopularity[navOptAttribute], suggestSpec.tables);
-            suggestions.push({
-              value: prefix + filterValue,
-              filterValue: filterValue,
-              meta: navOptAttribute === 'groupByColumn' ? HUE_I18n.autocomplete.meta.groupBy : HUE_I18n.autocomplete.meta.orderBy,
-              category: navOptAttribute === 'groupByColumn' ? CATEGORIES.POPULAR_GROUP_BY : CATEGORIES.POPULAR_ORDER_BY,
-              weightAdjust:  Math.round(100 * entry.navOptPopularity[navOptAttribute].columnCount / totalColumnCount),
-              popular: ko.observable(true),
-              hasCatalogEntry: false,
-              details: entry
-            });
-          });
-          if (prefix === '' && suggestions.length) {
-            mergeWithColumns(deferred, columnsDeferred, suggestions);
-          } else {
-            deferred.resolve(suggestions);
-          }
-        } else {
-          deferred.reject();
-        }
-      }).fail(deferred.reject));
-  };
-
-  AutocompleteResults.prototype.handleGroupBys = function (columnsDeferred) {
-    var self = this;
-    var groupBysDeferred = $.Deferred();
-    var suggestGroupBys = self.parseResult.suggestGroupBys;
-    if (HAS_OPTIMIZER && suggestGroupBys) {
-      initLoading(self.loadingGroupBys, groupBysDeferred);
-      groupBysDeferred.done(self.appendEntries);
-      self.handlePopularGroupByOrOrderBy('groupByColumn', suggestGroupBys, groupBysDeferred, columnsDeferred);
-    } else {
-      groupBysDeferred.reject();
-    }
-
-    return groupBysDeferred;
-  };
-
-  AutocompleteResults.prototype.handleOrderBys = function (columnsDeferred) {
-    var self = this;
-    var orderBysDeferred = $.Deferred();
-    var suggestOrderBys = self.parseResult.suggestOrderBys;
-    if (HAS_OPTIMIZER && suggestOrderBys) {
-      initLoading(self.loadingOrderBys, orderBysDeferred);
-      orderBysDeferred.done(self.appendEntries);
-      self.handlePopularGroupByOrOrderBy('orderByColumn', suggestOrderBys, orderBysDeferred, columnsDeferred);
-    } else {
-      orderBysDeferred.reject();
-    }
-    return orderBysDeferred;
-  };
-
-  AutocompleteResults.prototype.handleFilters = function () {
-    var self = this;
-    var filtersDeferred = $.Deferred();
-    var suggestFilters = self.parseResult.suggestFilters;
-    if (HAS_OPTIMIZER && suggestFilters) {
-      initLoading(self.loadingFilters, filtersDeferred);
-      filtersDeferred.done(self.appendEntries);
-
-      var paths = self.tableIdentifierChainsToPaths(suggestFilters.tables);
-      if (paths.length) {
-        dataCatalog.getMultiTableEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), paths: paths }).done(function (multiTableEntry) {
-          self.cancellablePromises.push(multiTableEntry.getTopFilters({ silenceErrors: true, cancellable: true }).done(function (topFilters) {
-            var filterSuggestions = [];
-            var totalCount = 0;
-            if (topFilters.values) {
-              topFilters.values.forEach(function (value) {
-                if (typeof value.popularValues !== 'undefined' && value.popularValues.length > 0) {
-                  value.popularValues.forEach(function (popularValue) {
-                    if (typeof popularValue.group !== 'undefined') {
-                      popularValue.group.forEach(function (grp) {
-                        var compVal = suggestFilters.prefix ? (self.parseResult.lowerCase ? suggestFilters.prefix.toLowerCase() : suggestFilters.prefix) + ' ' : '';
-                        compVal += self.createNavOptIdentifier(value.tableName, grp.columnName, suggestFilters.tables);
-                        if (!/^ /.test(grp.op)) {
-                          compVal += ' ';
-                        }
-                        compVal += self.parseResult.lowerCase ? grp.op.toLowerCase() : grp.op;
-                        if (!/ $/.test(grp.op)) {
-                          compVal += ' ';
-                        }
-                        compVal += grp.literal;
-                        totalCount += popularValue.count;
-                        filterSuggestions.push({
-                          value: compVal,
-                          meta: HUE_I18n.autocomplete.meta.filter,
-                          category: CATEGORIES.POPULAR_FILTER,
-                          popular: ko.observable(true),
-                          details: popularValue
-                        });
-                      });
-                    }
-                  });
-                }
-              });
-            }
-            filterSuggestions.forEach(function (suggestion) {
-              suggestion.details.relativePopularity = totalCount === 0 ? suggestion.details.count : Math.round(100 * suggestion.details.count / totalCount);
-              suggestion.weightAdjust = suggestion.details.relativePopularity + 1;
-            });
-
-            filtersDeferred.resolve(filterSuggestions);
-          }).fail(filtersDeferred.reject));
-        }).fail(filtersDeferred.reject);
-      } else {
-        filtersDeferred.reject();
-      }
-    } else {
-      filtersDeferred.reject();
-    }
-    return filtersDeferred;
-  };
-
-  AutocompleteResults.prototype.handlePopularTables = function (tablesDeferred) {
-    var self = this;
-    var popularTablesDeferred = $.Deferred();
-    if (HAS_OPTIMIZER && self.parseResult.suggestTables) {
-      initLoading(self.loadingPopularTables, popularTablesDeferred);
-
-      var db = self.parseResult.suggestTables.identifierChain
-        && self.parseResult.suggestTables.identifierChain.length === 1
-        && self.parseResult.suggestTables.identifierChain[0].name ? self.parseResult.suggestTables.identifierChain[0].name : self.activeDatabase;
-
-      dataCatalog.getEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), path: [ db ], temporaryOnly: self.temporaryOnly }).done(function (entry) {
-        self.cancellablePromises.push(entry.loadNavOptPopularityForChildren({ silenceErrors: true, cancellable: true }).done(function (childEntries) {
-          var totalPopularity = 0;
-          var popularityIndex = {};
-          childEntries.forEach(function (childEntry) {
-            if (childEntry.navOptPopularity && childEntry.navOptPopularity.popularity) {
-              popularityIndex[childEntry.name] = true;
-              totalPopularity += childEntry.navOptPopularity.popularity;
-            }
-          });
-          if (totalPopularity > 0 && Object.keys(popularityIndex).length) {
-            tablesDeferred.done(function (tableSuggestions) {
-              tableSuggestions.forEach(function (suggestion) {
-                if (popularityIndex[suggestion.details.name]) {
-                  suggestion.relativePopularity = Math.round(100 * suggestion.details.navOptPopularity.popularity / totalPopularity);
-                  if (suggestion.relativePopularity >= 5) {
-                    suggestion.popular(true);
-                  }
-                  suggestion.weightAdjust = suggestion.relativePopularity;
-                }
-              });
-              popularTablesDeferred.resolve();
-            }).fail(popularTablesDeferred.reject);
-          } else {
-            popularTablesDeferred.resolve();
-          }
-        }).fail(popularTablesDeferred.reject));
-      }).fail(popularTablesDeferred.reject);
-    } else {
-      popularTablesDeferred.reject();
-    }
-    return popularTablesDeferred
-  };
-
-  AutocompleteResults.prototype.handlePopularColumns = function (columnsDeferred) {
-    var self = this;
-    var popularColumnsDeferred = $.Deferred();
-    var suggestColumns = self.parseResult.suggestColumns;
-
-    // The columnsDeferred gets resolved synchronously when the data is cached, if not, assume there are some suggestions.
-    var hasColumnSuggestions = true;
-    columnsDeferred.done(function (columns) {
-      hasColumnSuggestions = columns.length > 0;
-    });
-
-    if (hasColumnSuggestions && HAS_OPTIMIZER && suggestColumns && suggestColumns.source !== 'undefined') {
-      initLoading(self.loadingPopularColumns, popularColumnsDeferred);
-
-      var paths = [];
-      suggestColumns.tables.forEach(function (table) {
-        if (table.identifierChain && table.identifierChain.length > 0) {
-          if (table.identifierChain.length === 1 && table.identifierChain[0].name) {
-            paths.push([self.activeDatabase, table.identifierChain[0].name])
-          } else if (table.identifierChain.length === 2 && table.identifierChain[0].name && table.identifierChain[1].name) {
-            paths.push([table.identifierChain[0].name, table.identifierChain[1].name]);
-          }
-        }
-      });
-
-      self.cancellablePromises.push(dataCatalog.getCatalog(self.snippet.type()).loadNavOptPopularityForTables({
-        namespace: self.snippet.namespace(),
-        compute: self.snippet.compute(),
-        paths: paths,
-        silenceErrors: true,
-        cancellable: true
-      }).done(function (popularEntries) {
-        var valueAttribute = '';
-        switch (suggestColumns.source) {
-          case 'select':
-            valueAttribute = 'selectColumn';
-            break;
-          case 'group by':
-            valueAttribute = 'groupByColumn';
-            break;
-          case 'order by':
-            valueAttribute = 'orderByColumn';
-        }
-
-        var popularityIndex = {};
-
-        popularEntries.forEach(function (popularEntry) {
-          if (popularEntry.navOptPopularity && popularEntry.navOptPopularity[valueAttribute]) {
-            popularityIndex[popularEntry.getQualifiedPath()] = true;
-          }
-        });
-
-        if (!valueAttribute || Object.keys(popularityIndex).length === 0) {
-          popularColumnsDeferred.reject();
-          return;
-        }
-
-        columnsDeferred.done(function (columns) {
-          var totalColumnCount = 0;
-          var matchedSuggestions = [];
-          columns.forEach(function (suggestion) {
-            if (suggestion.hasCatalogEntry && popularityIndex[suggestion.details.getQualifiedPath()]) {
-              matchedSuggestions.push(suggestion);
-              totalColumnCount += suggestion.details.navOptPopularity[valueAttribute].columnCount;
-            }
-          });
-          if (totalColumnCount > 0) {
-            matchedSuggestions.forEach(function (matchedSuggestion) {
-              matchedSuggestion.relativePopularity = Math.round(100 * matchedSuggestion.details.navOptPopularity[valueAttribute].columnCount / totalColumnCount);
-              if (matchedSuggestion.relativePopularity  >= 5) {
-                matchedSuggestion.popular(true);
-              }
-              matchedSuggestion.weightAdjust = matchedSuggestion.relativePopularity ;
-            });
-          }
-          popularColumnsDeferred.resolve();
-        }).fail(popularColumnsDeferred.reject);
-      }));
-    } else {
-      popularColumnsDeferred.reject();
-    }
-    return popularColumnsDeferred;
-  };
-
-  AutocompleteResults.prototype.createNavOptIdentifier = function (navOptTableName, navOptColumnName, tables) {
-    var self = this;
-    var path = navOptTableName + '.' + navOptColumnName.split('.').pop();
-    for (var i = 0; i < tables.length; i++) {
-      var tablePath = '';
-      if (tables[i].identifierChain.length == 2) {
-        tablePath = $.map(tables[i].identifierChain, function (identifier) { return identifier.name }).join('.');
-      } else if (tables[i].identifierChain.length == 1) {
-        tablePath = self.activeDatabase + '.' + tables[i].identifierChain[0].name;
-      }
-      if (path.indexOf(tablePath) === 0) {
-        path = path.substring(tablePath.length + 1);
-        if (tables[i].alias) {
-          path = tables[i].alias + '.' + path;
-        } else if (tables.length > 0) {
-          path = tables[i].identifierChain[tables[i].identifierChain.length - 1].name + '.' + path;
-        }
-        break;
-      }
-    }
-    return path;
-  };
-
-  AutocompleteResults.prototype.createNavOptIdentifierForColumn = function (navOptColumn, tables) {
-    var self = this;
-    for (var i = 0; i < tables.length; i++) {
-      if (navOptColumn.dbName && (navOptColumn.dbName !== self.activeDatabase || navOptColumn.dbName !== tables[i].identifierChain[0].name)) {
-        continue;
-      }
-      if (navOptColumn.tableName && hueUtils.equalIgnoreCase(navOptColumn.tableName, tables[i].identifierChain[tables[i].identifierChain.length - 1].name) && tables[i].alias) {
-        return tables[i].alias + '.' + navOptColumn.columnName;
-      }
-    }
-
-    if (navOptColumn.dbName && navOptColumn.dbName !== self.activeDatabase) {
-      return navOptColumn.dbName + '.' + navOptColumn.tableName + '.' + navOptColumn.columnName;
-    }
-    if (tables.length > 1) {
-      return navOptColumn.tableName + '.' + navOptColumn.columnName;
-    }
-    return navOptColumn.columnName;
-  };
-
-  AutocompleteResults.prototype.convertNavOptQualifiedIdentifier = function (qualifiedIdentifier, tables, type) {
-    var self = this;
-    var aliases = [];
-    var tablesHasDefaultDatabase = false;
-    tables.forEach(function (table) {
-      tablesHasDefaultDatabase = tablesHasDefaultDatabase || hueUtils.equalIgnoreCase(table.identifierChain[0].name.toLowerCase(), self.activeDatabase.toLowerCase());
-      if (table.alias) {
-        aliases.push({ qualifiedName: $.map(table.identifierChain, function (identifier) { return identifier.name }).join('.').toLowerCase(), alias: table.alias });
-      }
-    });
-
-    for (var i = 0; i < aliases.length; i++) {
-      if (qualifiedIdentifier.toLowerCase().indexOf(aliases[i].qualifiedName) === 0) {
-        return aliases[i].alias + qualifiedIdentifier.substring(aliases[i].qualifiedName.length);
-      } else if (qualifiedIdentifier.toLowerCase().indexOf(self.activeDatabase.toLowerCase() + '.' + aliases[i].qualifiedName) === 0) {
-        return aliases[i].alias + qualifiedIdentifier.substring((self.activeDatabase + '.' + aliases[i].qualifiedName).length);
-      }
-    }
-
-    if (qualifiedIdentifier.toLowerCase().indexOf(self.activeDatabase.toLowerCase()) === 0 && !tablesHasDefaultDatabase) {
-      return qualifiedIdentifier.substring(self.activeDatabase.length + 1);
-    }
-    if (type === 'hive') {
-      // Remove DB reference if given for Hive
-      var parts = qualifiedIdentifier.split('.');
-      if (parts.length > 2) {
-        return parts.slice(1).join('.')
-      }
-    }
-    return qualifiedIdentifier;
-  };
-
-  /**
-   * Helper function to fetch columns/fields given an identifierChain, this also takes care of expanding arrays
-   * and maps to match the required format for the API.
-   *
-   * @param originalIdentifierChain
-   */
-  AutocompleteResults.prototype.fetchFieldsForIdentifiers = function (originalIdentifierChain) {
-    var self = this;
-    var deferred = $.Deferred();
-    var path = [];
-    for (var i = 0; i < originalIdentifierChain.length; i++) {
-      if (originalIdentifierChain[i].name && !originalIdentifierChain[i].subQuery) {
-        path.push(originalIdentifierChain[i].name)
-      } else {
-        return deferred.reject().promise();
-      }
-    }
-
-    var fetchFieldsInternal =  function (remainingPath, fetchedPath) {
-      if (!fetchedPath) {
-        fetchedPath = [];
-      }
-      if (remainingPath.length > 0) {
-        fetchedPath.push(remainingPath.shift());
-        // Parser sometimes knows if it's a map or array.
-        if (remainingPath.length > 0 && (remainingPath[0] === 'item' || remainingPath[0].name === 'value')) {
-          fetchedPath.push(remainingPath.shift());
-        }
-      }
-
-      dataCatalog.getEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), path: fetchedPath, temporaryOnly: self.temporaryOnly }).done(function (catalogEntry) {
-        self.cancellablePromises.push(catalogEntry.getSourceMeta({ silenceErrors: true, cancellable: true }).done(function (sourceMeta) {
-          if (self.snippet.type() === 'hive'
-              && typeof sourceMeta.extended_columns !== 'undefined'
-              && sourceMeta.extended_columns.length === 1
-              && /^(?:map|array|struct)/i.test(sourceMeta.extended_columns[0].type)) {
-            remainingPath.unshift(data.extended_columns[0].name)
-          }
-          if (remainingPath.length) {
-            if (/value|item|key/i.test(remainingPath[0])) {
-              fetchedPath.push(remainingPath.shift());
-            } else if (sourceMeta.type === 'array') {
-              fetchedPath.push('item');
-            } else if (sourceMeta.type === 'map') {
-              fetchedPath.push('value');
-            }
-            fetchFieldsInternal(remainingPath, fetchedPath)
-          } else {
-            deferred.resolve(catalogEntry);
-          }
-        }).fail(deferred.reject));
-      }).fail(deferred.reject);
-    };
-
-    // For Impala the first parts of the identifier chain could be either database or table, either:
-    // SELECT | FROM database.table -or- SELECT | FROM table.column
-
-    // For Hive it could be either:
-    // SELECT col.struct FROM db.tbl -or- SELECT col.struct FROM tbl
-    if (path.length > 1 && (self.snippet.type() === 'impala' || self.snippet.type() === 'hive')) {
-      dataCatalog.getEntry({ sourceType: self.snippet.type(), namespace: self.snippet.namespace(), compute: self.snippet.compute(), path: [], temporaryOnly: self.temporaryOnly }).done(function (catalogEntry) {
-        self.cancellablePromises.push(catalogEntry.getChildren({ silenceErrors: true, cancellable: true }).done(function (databaseEntries) {
-          var firstIsDb = databaseEntries.some(function (dbEntry) {
-            return hueUtils.equalIgnoreCase(dbEntry.name, path[0]);
-          });
-          if (!firstIsDb) {
-            path.unshift(self.activeDatabase);
-          }
-          fetchFieldsInternal(path);
-        }).fail(deferred.reject));
-      }).fail(deferred.reject);
-    } else if (path.length > 1) {
-      fetchFieldsInternal(path);
-    } else {
-      path.unshift(self.activeDatabase);
-      fetchFieldsInternal(path);
-    }
-
-    return deferred.promise();
-  };
-
-  return AutocompleteResults;
-})();
-
-var SqlAutocompleter3 = (function () {
-  /**
-   * @param {Object} options
-   * @param {Snippet} options.snippet
-   * @param {string} [options.fixedPrefix] - Optional prefix to always use on parse
-   * @param {string} [options.fixedPostfix] - Optional postfix to always use on parse
-   * @constructor
-   */
-  function SqlAutocompleter3(options) {
-    var self = this;
-    self.snippet = options.snippet;
-    self.editor = options.editor;
-    self.fixedPrefix = options.fixedPrefix || function () { return '' };
-    self.fixedPostfix = options.fixedPostfix || function () { return '' };
-    self.suggestions = new AutocompleteResults(options);
-  }
-
-  SqlAutocompleter3.prototype.parseActiveStatement = function () {
-    var self = this;
-    if (self.snippet.positionStatement() && self.snippet.positionStatement().location) {
-      var activeStatementLocation = self.snippet.positionStatement().location;
-      var cursorPosition = self.editor().getCursorPosition();
-
-      if ((activeStatementLocation.first_line - 1 < cursorPosition.row || (activeStatementLocation.first_line - 1 === cursorPosition.row && activeStatementLocation.first_column <= cursorPosition.column)) &&
-        (activeStatementLocation.last_line - 1 > cursorPosition.row || (activeStatementLocation.last_line - 1 === cursorPosition.row && activeStatementLocation.last_column >= cursorPosition.column))) {
-        var beforeCursor = self.fixedPrefix() + self.editor().session.getTextRange({
-          start: {
-            row: activeStatementLocation.first_line - 1,
-            column: activeStatementLocation.first_column
-          },
-          end: cursorPosition
-        });
-        var afterCursor = self.editor().session.getTextRange({
-          start: cursorPosition,
-          end: {
-            row: activeStatementLocation.last_line - 1,
-            column: activeStatementLocation.last_column
-          }
-        }) + self.fixedPostfix();
-        return sqlAutocompleteParser.parseSql(beforeCursor, afterCursor, self.snippet.type(), false);
-      }
-    }
-  };
-
-  SqlAutocompleter3.prototype.autocomplete = function () {
-    var self = this;
-    var parseResult;
-    try {
-      huePubSub.publish('get.active.editor.locations', function (locations) {
-        // This could happen in case the user is editing at the borders of the statement and the locations haven't
-        // been updated yet, in that case we have to force a location update before parsing
-        if (self.snippet.ace && self.snippet.ace() && locations && self.snippet.ace().lastChangeTime !== locations.editorChangeTime) {
-          huePubSub.publish('editor.refresh.statement.locations', self.snippet);
-        }
-      }, self.snippet);
-
-      parseResult = self.parseActiveStatement();
-
-      if (typeof hueDebug !== 'undefined' && hueDebug.showParseResult) {
-        console.log(parseResult);
-      }
-    } catch (e) {
-      if (typeof console.warn !== 'undefined') {
-        console.warn(e);
-      }
-    }
-
-    // In the unlikely case the statement parser fails we fall back to parsing all of it
-    if (!parseResult) {
-      try {
-        parseResult = sqlAutocompleteParser.parseSql(self.editor().getTextBeforeCursor(), self.editor().getTextAfterCursor(), self.snippet.type(), false);
-      } catch (e) {
-        if (typeof console.warn !== 'undefined') {
-          console.warn(e);
-        }
-      }
-    }
-
-    if (!parseResult) {
-      // This prevents Ace from inserting garbled text in case of exception
-      huePubSub.publish('hue.ace.autocompleter.done');
-    } else {
-      try {
-        if (self.lastContextRequest) {
-          self.lastContextRequest.dispose();
-        }
-        self.lastContextRequest = self.snippet.whenContextSet().done(function () {
-          self.suggestions.update(parseResult);
-        }).fail(function () {
-          huePubSub.publish('hue.ace.autocompleter.done');
-        });
-      } catch (e) {
-        if (typeof console.warn !== 'undefined') {
-          console.warn(e);
-        }
-        huePubSub.publish('hue.ace.autocompleter.done');
-      }
-    }
-  };
-
-  return SqlAutocompleter3;
-})();

+ 0 - 3956
desktop/core/src/desktop/static/desktop/js/sqlFunctions.js

@@ -1,3956 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-var PigFunctions = (function () {
-  var EVAL_FUNCTIONS = {
-    avg: { signature: 'AVG(%VAR%)', draggable: 'AVG()' },
-    concat: { signature: 'CONCAT(%VAR1%, %VAR2%)', draggable: 'CONCAT()' },
-    count: { signature: 'COUNT(%VAR%)', draggable: 'COUNT()' },
-    count_start: { signature: 'COUNT_START(%VAR%)', draggable: 'COUNT_START()' },
-    is_empty: { signature: 'IsEmpty(%VAR%)', draggable: 'IsEmpty()' },
-    diff: { signature: 'DIFF(%VAR1%, %VAR2%)', draggable: 'DIFF()' },
-    max: { signature: 'MAX(%VAR%)', draggable: 'MAX()' },
-    min: { signature: 'MIN(%VAR%)', draggable: 'MIN()' },
-    size: { signature: 'SIZE(%VAR%)', draggable: 'SIZE()' },
-    sum: { signature: 'SUM(%VAR%)', draggable: 'SUM()' },
-    tokenize: { signature: 'TOKENIZE(%VAR%, %DELIM%)', draggable: 'TOKENIZE()' }
-  };
-
-  var RELATIONAL_OPERATORS = {
-    cogroup: { signature: 'COGROUP %VAR% BY %VAR%', draggable: 'COGROUP %VAR% BY %VAR%' },
-    cross: { signature: 'CROSS %VAR1%, %VAR2%;', draggable: 'CROSS %VAR1%, %VAR2%;' },
-    distinct: { signature: 'DISTINCT %VAR%;', draggable: 'DISTINCT %VAR%;' },
-    filter: { signature: 'FILTER %VAR% BY %COND%', draggable: 'FILTER %VAR% BY %COND%' },
-    flatten: { signature: 'FLATTEN(%VAR%)', draggable: 'FLATTEN()' },
-    foreach_generate: { signature: 'FOREACH %DATA% GENERATE %NEW_DATA%;', draggable: 'FOREACH %DATA% GENERATE %NEW_DATA%;' },
-    foreach: { signature: 'FOREACH %DATA% {%NESTED_BLOCK%};', draggable: 'FOREACH %DATA% {%NESTED_BLOCK%};' },
-    group_by: { signature: 'GROUP %VAR% BY %VAR%', draggable: 'GROUP %VAR% BY %VAR%' },
-    group_all: { signature: 'GROUP %VAR% ALL', draggable: 'GROUP %VAR% ALL' },
-    join: { signature: 'JOIN %VAR% BY ', draggable: 'JOIN %VAR% BY ' },
-    limit: { signature: 'LIMIT %VAR% %N%', draggable: 'LIMIT %VAR% %N%' },
-    order: { signature: 'ORDER %VAR% BY %FIELD%', draggable: 'ORDER %VAR% BY %FIELD%' },
-    sample: { signature: 'SAMPLE %VAR% %SIZE%', draggable: 'SAMPLE %VAR% %SIZE%' },
-    split: { signature: 'SPLIT %VAR1% INTO %VAR2% IF %EXPRESSIONS%', draggable: 'SPLIT %VAR1% INTO %VAR2% IF %EXPRESSIONS%' },
-    union: { signature: 'UNION %VAR1%, %VAR2%', draggable: 'UNION %VAR1%, %VAR2%' }
-  };
-
-  var INPUT_OUTPUT = {
-    load: { signature: 'LOAD \'%FILE%\';',  draggable: 'LOAD \'%FILE%\';' },
-    dump: { signature: 'DUMP %VAR%;', draggable: 'DUMP %VAR%;' },
-    store: { signature: 'STORE %VAR% INTO %PATH%;', draggable: 'STORE %VAR% INTO %PATH%;' }
-  };
-
-  var DEBUG = {
-    explain: { signature: 'EXPLAIN %VAR%;', draggable: 'EXPLAIN %VAR%;' },
-    illustrate: { signature: 'ILLUSTRATE %VAR%;' , draggable: 'ILLUSTRATE %VAR%;' },
-    describe: { signature: 'DESCRIBE %VAR%;', draggable: 'DESCRIBE %VAR%;' }
-  };
-
-  var HCATALOG = {
-    LOAD: { signature: 'LOAD \'%TABLE%\' USING org.apache.hcatalog.pig.HCatLoader();', draggable: 'LOAD \'%TABLE%\' USING org.apache.hcatalog.pig.HCatLoader();' }
-  };
-
-  var MATH_FUNCTIONS = {
-    abs: { signature: 'ABS(%VAR%)', draggable: 'ABS()' },
-    acos: { signature: 'ACOS(%VAR%)', draggable: 'ACOS()' },
-    asin: { signature: 'ASIN(%VAR%)', draggable: 'ASIN()' },
-    atan: { signature: 'ATAN(%VAR%)', draggable: 'ATAN()' },
-    cbrt: { signature: 'CBRT(%VAR%)', draggable: 'CBRT()' },
-    ceil: { signature: 'CEIL(%VAR%)', draggable: 'CEIL()' },
-    cos: { signature: 'COS(%VAR%)', draggable: 'COS()' },
-    cosh: { signature: 'COSH(%VAR%)', draggable: 'COSH()' },
-    exp: { signature: 'EXP(%VAR%)', draggable: 'EXP()' },
-    floor: { signature: 'FLOOR(%VAR%)', draggable: 'FLOOR()' },
-    log: { signature: 'LOG(%VAR%)', draggable: 'LOG()' },
-    log10: { signature: 'LOG10(%VAR%)', draggable: 'LOG10()' },
-    random: { signature: 'RANDOM(%VAR%)', draggable: 'RANDOM()' },
-    round: { signature: 'ROUND(%VAR%)', draggable: 'ROUND()' },
-    sin: { signature: 'SIN(%VAR%)', draggable: 'SIN()' },
-    sinh: { signature: 'SINH(%VAR%)', draggable: 'SINH()' },
-    sqrt: { signature: 'SQRT(%VAR%)', draggable: 'SQRT()' },
-    tan: { signature: 'TAN(%VAR%)', draggable: 'TAN()' },
-    tanh: { signature: 'TANH(%VAR%)', draggable: 'TANH()' }
-  };
-
-  var TUPLE_BAG_MAP = {
-    totuple: { signature: 'TOTUPLE(%VAR%)',draggable: 'TOTUPLE()' },
-    tobag: { signature: 'TOBAG(%VAR%)',draggable: 'TOBAG()' },
-    tomap: { signature: 'TOMAP(%KEY%, %VALUE%)',draggable: 'TOMAP()' },
-    top: { signature: 'TOP(%topN%, %COLUMN%, %RELATION%)',draggable: 'TOP()' }
-  };
-
-  var STRING_FUNCTIONS = {
-    indexof: { signature: 'INDEXOF(%STRING%, \'%CHARACTER%\', %STARTINDEX%)',draggable: 'INDEXOF()' },
-    last_index_of: { signature: 'LAST_INDEX_OF(%STRING%, \'%CHARACTER%\', %STARTINDEX%)',draggable: 'LAST_INDEX_OF()' },
-    lower: { signature: 'LOWER(%STRING%)',draggable: 'LOWER()' },
-    regex_extract: { signature: 'REGEX_EXTRACT(%STRING%, %REGEX%, %INDEX%)',draggable: 'REGEX_EXTRACT()' },
-    regex_extract_all: { signature: 'REGEX_EXTRACT_ALL(%STRING%, %REGEX%)',draggable: 'REGEX_EXTRACT_ALL()' },
-    replace: { signature: 'REPLACE(%STRING%, \'%oldChar%\', \'%newChar%\')',draggable: 'REPLACE()' },
-    strsplit: { signature: 'STRSPLIT(%STRING%, %REGEX%, %LIMIT%)',draggable: 'STRSPLIT()' },
-    substring: { signature: 'SUBSTRING(%STRING%, %STARTINDEX%, %STOPINDEX%)',draggable: 'SUBSTRING()' },
-    trim: { signature: 'TRIM(%STRING%)',draggable: 'TRIM()' },
-    ucfirst: { signature: 'UCFIRST(%STRING%)',draggable: 'UCFIRST()' },
-    upper: { signature: 'UPPER(%STRING%)',draggable: 'UPPER()' }
-  };
-
-  var MACROS = {
-    import: { signature: 'IMPORT \'%PATH_TO_MACRO%\';', draggable: 'IMPORT \'%PATH_TO_MACRO%\';' }
-  };
-
-  var HBASE = {
-    load: { signature: 'LOAD \'hbase://%TABLE%\' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(\'%columnList%\')', draggable: 'LOAD \'hbase://%TABLE%\' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(\'%columnList%\')' },
-    store: { signature: 'STORE %VAR% INTO \'hbase://%TABLE%\' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(\'%columnList%\')', draggable: 'STORE %VAR% INTO \'hbase://%TABLE%\' USING org.apache.pig.backend.hadoop.hbase.HBaseStorage(\'%columnList%\')' }
-  };
-
-  var PYTHON_UDF = {
-    register: { signature: 'REGISTER \'python_udf.py\' USING jython AS myfuncs;', draggable: 'REGISTER \'python_udf.py\' USING jython AS myfuncs;' }
-  };
-
-  var CATEGORIZED_FUNCTIONS = [
-    { name: 'Eval', functions: EVAL_FUNCTIONS },
-    { name: 'Relational Operators', functions: RELATIONAL_OPERATORS },
-    { name: 'Input and Output', functions: INPUT_OUTPUT },
-    { name: 'Debug', functions: DEBUG },
-    { name: 'HCatalog', functions: HCATALOG },
-    { name: 'Math', functions: MATH_FUNCTIONS },
-    { name: 'Tuple, Bag and Map', functions: TUPLE_BAG_MAP },
-    { name: 'String', functions: STRING_FUNCTIONS },
-    { name: 'Macros', functions: MACROS },
-    { name: 'HBase', functions: HBASE },
-    { name: 'Python UDF', functions: PYTHON_UDF }
-  ];
-
-  return {
-    CATEGORIZED_FUNCTIONS: CATEGORIZED_FUNCTIONS
-  }
-})();
-
-var SqlSetOptions = (function () {
-  var SET_OPTIONS = {
-    hive: {},
-    impala: {
-      'ALLOW_ERASURE_CODED_FILES' : {
-        description: 'Use the ALLOW_ERASURE_CODED_FILES query option to enable or disable the support of erasure coded files in Impala. Until Impala is fully tested and certified with erasure coded files, this query option is set to FALSE by default.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'APPX_COUNT_DISTINCT': {
-        description: 'Allows multiple COUNT(DISTINCT) operations within a single query, by internally rewriting each COUNT(DISTINCT) to use the NDV() function. The resulting count is approximate rather than precise.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'BATCH_SIZE': {
-        description: 'Number of rows evaluated at a time by SQL operators. Unspecified or a size of 0 uses a predefined default size. Using a large number improves responsiveness, especially for scan operations, at the cost of a higher memory footprint.',
-        type: 'Numeric',
-        default: '0 (meaning the predefined default of 1024)'
-      },
-      'BUFFER_POOL_LIMIT': {
-        description: 'Defines a limit on the amount of memory that a query can allocate from the internal buffer pool. The value for this limit applies to the memory on each host, not the aggregate memory across the cluster. Typically not changed by users, except during diagnosis of out-of-memory errors during queries.',
-        type: 'Integer',
-        default: 'The default setting for this option is the lower of 80% of the MEM_LIMIT setting, or the MEM_LIMIT setting minus 100 MB.'
-      },
-      'COMPRESSION_CODEC': {
-        description: 'When Impala writes Parquet data files using the INSERT statement, the underlying compression is controlled by the COMPRESSION_CODEC query option.',
-        type: 'String; SNAPPY, GZIP or NONE',
-        default: 'SNAPPY'
-      },
-      'COMPUTE_STATS_MIN_SAMPLE_SIZE': {
-        description: 'The COMPUTE_STATS_MIN_SAMPLE_SIZE query option specifies the minimum number of bytes that will be scanned in COMPUTE STATS TABLESAMPLE, regardless of the user-supplied sampling percent. This query option prevents sampling for very small tables where accurate stats can be obtained cheaply without sampling because the minimum sample size is required to get meaningful stats.',
-        type: 'Integer',
-        default: '1073741824 (1GB)'
-      },
-      'DEFAULT_JOIN_DISTRIBUTION_MODE': {
-        description: 'This option determines the join distribution that Impala uses when any of the tables involved in a join query is missing statistics.\n\nThe setting DEFAULT_JOIN_DISTRIBUTION_MODE=SHUFFLE is recommended when setting up and deploying new clusters, because it is less likely to result in serious consequences such as spilling or out-of-memory errors if the query plan is based on incomplete information.',
-        type: 'Integer; The allowed values are BROADCAST (equivalent to 0) or SHUFFLE (equivalent to 1).',
-        default: '0'
-      },
-      'DEFAULT_SPILLABLE_BUFFER_SIZE': {
-        description: 'Specifies the default size for a memory buffer used when the spill-to-disk mechanism is activated, for example for queries against a large table with no statistics, or large join operations.\n\nAccepts a numeric value that represents a size in bytes; you can also use a suffix of m or mb for megabytes, or g or gb for gigabytes. If you specify a value with unrecognized formats, subsequent queries fail with an error.',
-        type: 'Integer',
-        default: '2097152 (2 MB)'
-      },
-      'DISABLE_CODEGEN': {
-        description: 'This is a debug option, intended for diagnosing and working around issues that cause crashes. If a query fails with an "illegal instruction" or other hardware-specific message, try setting DISABLE_CODEGEN=true and running the query again. If the query succeeds only when the DISABLE_CODEGEN option is turned on, submit the problem to Cloudera Support and include that detail in the problem report. Do not otherwise run with this setting turned on, because it results in lower overall performance.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'DISABLE_ROW_RUNTIME_FILTERING': {
-        description: 'The DISABLE_ROW_RUNTIME_FILTERING query option reduces the scope of the runtime filtering feature. Queries still dynamically prune partitions, but do not apply the filtering logic to individual rows within partitions.\n\nOnly applies to queries against Parquet tables. For other file formats, Impala only prunes at the level of partitions, not individual rows.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'DISABLE_STREAMING_PREAGGREGATIONS': {
-        description: 'Turns off the "streaming preaggregation" optimization that is available in CDH 5.7 / Impala 2.5 and higher. This optimization reduces unnecessary work performed by queries that perform aggregation operations on columns with few or no duplicate values, for example DISTINCT id_column or GROUP BY unique_column. If the optimization causes regressions in existing queries that use aggregation functions, you can turn it off as needed by setting this query option.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'DISABLE_UNSAFE_SPILLS': {
-        description: 'Enable this option if you prefer to have queries fail when they exceed the Impala memory limit, rather than write temporary data to disk.\n\nQueries that "spill" to disk typically complete successfully, when in earlier Impala releases they would have failed. However, queries with exorbitant memory requirements due to missing statistics or inefficient join clauses could become so slow as a result that you would rather have them cancelled automatically and reduce the memory usage through standard Impala tuning techniques.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'EXEC_SINGLE_NODE_ROWS_THRESHOLD': {
-        description: 'This setting controls the cutoff point (in terms of number of rows scanned) below which Impala treats a query as a "small" query, turning off optimizations such as parallel execution and native code generation. The overhead for these optimizations is applicable for queries involving substantial amounts of data, but it makes sense to skip them for queries involving tiny amounts of data. Reducing the overhead for small queries allows Impala to complete them more quickly, keeping YARN resources, admission control slots, and so on available for data-intensive queries.',
-        type: 'Numeric',
-        default: '100'
-      },
-      'EXEC_TIME_LIMIT_S': {
-        description: 'The EXEC_TIME_LIMIT_S query option sets a time limit on query execution. If a query is still executing when time limit expires, it is automatically canceled. The option is intended to prevent runaway queries that execute for much longer than intended.',
-        type: 'Numeric',
-        default: '0 (no time limit)'
-      },
-      'EXPLAIN_LEVEL': {
-        description: 'Controls the amount of detail provided in the output of the EXPLAIN statement. The basic output can help you identify high-level performance issues such as scanning a higher volume of data or more partitions than you expect. The higher levels of detail show how intermediate results flow between nodes and how different SQL operations such as ORDER BY, GROUP BY, joins, and WHERE clauses are implemented within a distributed query.',
-        type: 'String or Int; 0 - MINIMAL, 1 - STANDARD, 2 - EXTENDED or 3 - VERBOSE',
-        default: '1'
-      },
-      'HBASE_CACHE_BLOCKS': {
-        description: 'Setting this option is equivalent to calling the setCacheBlocks method of the class org.apache.hadoop.hbase.client.Scan, in an HBase Java application. Helps to control the memory pressure on the HBase RegionServer, in conjunction with the HBASE_CACHING query option.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'HBASE_CACHING': {
-        description: 'Setting this option is equivalent to calling the setCaching method of the class org.apache.hadoop.hbase.client.Scan, in an HBase Java application. Helps to control the memory pressure on the HBase RegionServer, in conjunction with the HBASE_CACHE_BLOCKS query option.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'MAX_ERRORS': {
-        description: 'Maximum number of non-fatal errors for any particular query that are recorded in the Impala log file. For example, if a billion-row table had a non-fatal data error in every row, you could diagnose the problem without all billion errors being logged. Unspecified or 0 indicates the built-in default value of 1000.\n\nThis option only controls how many errors are reported. To specify whether Impala continues or halts when it encounters such errors, use the ABORT_ON_ERROR option.',
-        type: 'Numeric',
-        default: '0 (meaning 1000 errors)'
-      },
-      'MAX_MEM_ESTIMATE_FOR_ADMISSION': {
-        description: 'Use the MAX_MEM_ESTIMATE_FOR_ADMISSION query option to set an upper limit on the memory estimates of a query as a workaround for over-estimates precluding a query from being admitted.',
-        type: 'Numeric',
-        default: ''
-      },
-      'MAX_NUM_RUNTIME_FILTERS': {
-        description: 'The MAX_NUM_RUNTIME_FILTERS query option sets an upper limit on the number of runtime filters that can be produced for each query.',
-        type: 'Integer',
-        default: '10'
-      },
-      'MAX_ROW_SIZE': {
-        description: 'Ensures that Impala can process rows of at least the specified size. (Larger rows might be successfully processed, but that is not guaranteed.) Applies when constructing intermediate or final rows in the result set. This setting prevents out-of-control memory use when accessing columns containing huge strings.\n\nAccepts a numeric value that represents a size in bytes; you can also use a suffix of m or mb for megabytes, or g or gb for gigabytes. If you specify a value with unrecognized formats, subsequent queries fail with an error.',
-        type: 'Integer',
-        default: '524288 (512 KB)'
-      },
-      'MAX_SCAN_RANGE_LENGTH': {
-        description: 'Maximum length of the scan range. Interacts with the number of HDFS blocks in the table to determine how many CPU cores across the cluster are involved with the processing for a query. (Each core processes one scan range.)\n\nLowering the value can sometimes increase parallelism if you have unused CPU capacity, but a too-small value can limit query performance because each scan range involves extra overhead.\n\nOnly applicable to HDFS tables. Has no effect on Parquet tables. Unspecified or 0 indicates backend default, which is the same as the HDFS block size for each table.',
-        type: 'Numeric',
-        default: '0'
-      },
-      'MEM_LIMIT': {
-        description: 'When resource management is not enabled, defines the maximum amount of memory a query can allocate on each node. Therefore, the total memory that can be used by a query is the MEM_LIMIT times the number of nodes.\n\nAccepts a numeric value that represents a size in bytes; you can also use a suffix of m or mb for megabytes, or g or gb for gigabytes. If you specify a value with unrecognized formats, subsequent queries fail with an error.',
-        type: 'Numeric',
-        default: '0 (unlimited)'
-      },
-      'MIN_SPILLABLE_BUFFER_SIZE': {
-        description: 'Specifies the minimum size for a memory buffer used when the spill-to-disk mechanism is activated, for example for queries against a large table with no statistics, or large join operations.\n\nAccepts a numeric value that represents a size in bytes; you can also use a suffix of m or mb for megabytes, or g or gb for gigabytes. If you specify a value with unrecognized formats, subsequent queries fail with an error.',
-        type: 'Integer',
-        default: '65536 (64 KB)'
-      },
-      'MT_DOP': {
-        description: 'Sets the degree of parallelism used for certain operations that can benefit from multithreaded execution. You can specify values higher than zero to find the ideal balance of response time, memory usage, and CPU usage during statement processing.',
-        type: 'Integer; Range from 0 to 64',
-        default: '0'
-      },
-      'NUM_NODES': {
-        description: 'Limit the number of nodes that process a query, typically during debugging.',
-        type: 'Numeric; Only accepts the values 0 (meaning all nodes) or 1 (meaning all work is done on the coordinator node).',
-        default: '0'
-      },
-      'NUM_SCANNER_THREADS': {
-        description: 'Maximum number of scanner threads (on each node) used for each query. By default, Impala uses as many cores as are available (one thread per core). You might lower this value if queries are using excessive resources on a busy cluster. Impala imposes a maximum value automatically, so a high value has no practical',
-        type: 'Numeric',
-        default: '0'
-      },
-      'OPTIMIZE_PARTITION_KEY_SCANS': {
-        description: 'Enables a fast code path for queries that apply simple aggregate functions to partition key columns: MIN(key_column), MAX(key_column), or COUNT(DISTINCT key_column).',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'PARQUET_ANNOTATE_STRINGS_UTF8': {
-        description: 'Causes Impala INSERT and CREATE TABLE AS SELECT statements to write Parquet files that use the UTF-8 annotation for STRING columns.\n\nBy default, Impala represents a STRING column in Parquet as an unannotated binary field.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'PARQUET_FALLBACK_SCHEMA_RESOLUTION': {
-        description: 'Allows Impala to look up columns within Parquet files by column name, rather than column order, when necessary.',
-        type: 'integer or string. Allowed values are 0 for POSITION and 1 for NAME.',
-        default: '0'
-      },
-      'PARQUET_FILE_SIZE': {
-        description: 'Specifies the maximum size of each Parquet data file produced by Impala INSERT statements.',
-        type: 'Numeric, with optional unit specifier.',
-        default: '0 (produces files with a target size of 256 MB; files might be larger for very wide tables)'
-      },
-      'PREFETCH_MODE': {
-        description: 'Determines whether the prefetching optimization is applied during join query processing.',
-        type: 'Numeric (0, 1) or corresponding mnemonic strings (NONE, HT_BUCKET).',
-        default: '1 (equivalent to HT_BUCKET)'
-      },
-      'QUERY_TIMEOUT_S': {
-        description: 'Sets the idle query timeout value for the session, in seconds. Queries that sit idle for longer than the timeout value are automatically cancelled. If the system administrator specified the --idle_query_timeout startup option, QUERY_TIMEOUT_S must be smaller than or equal to the --idle_query_timeout value.',
-        type: 'Numeric',
-        default: '0 (no timeout if --idle_query_timeout not in effect; otherwise, use --idle_query_timeout value)'
-      },
-      'REQUEST_POOL': {
-        description: 'The pool or queue name that queries should be submitted to. Only applies when you enable the Impala admission control feature. Specifies the name of the pool used by requests from Impala to the resource manager.',
-        type: 'String',
-        default: 'empty (use the user-to-pool mapping defined by an impalad startup option in the Impala configuration file)'
-      },
-      'REPLICA_PREFERENCE': {
-        description: 'The REPLICA_PREFERENCE query option lets you distribute the work more evenly if hotspots and bottlenecks persist. It causes the access cost of all replicas of a data block to be considered equal to or worse than the configured value. This allows Impala to schedule reads to suboptimal replicas (e.g. local in the presence of cached ones) in order to distribute the work across more executor nodes.',
-        type: 'Numeric (0, 2, 4) or corresponding mnemonic strings (CACHE_LOCAL, DISK_LOCAL, REMOTE). The gaps in the numeric sequence are to accomodate other intermediate values that might be added in the future.',
-        default: '0 (equivalent to CACHE_LOCAL)'
-      },
-      'RUNTIME_BLOOM_FILTER_SIZE': {
-        description: 'Size (in bytes) of Bloom filter data structure used by the runtime filtering feature.',
-        type: 'Integer; Maximum 16 MB.',
-        default: '1048576 (1 MB)'
-      },
-      'RUNTIME_FILTER_MAX_SIZE': {
-        description: 'The RUNTIME_FILTER_MAX_SIZE query option adjusts the settings for the runtime filtering feature. This option defines the maximum size for a filter, no matter what the estimates produced by the planner are. This value also overrides any lower number specified for the RUNTIME_BLOOM_FILTER_SIZE query option. Filter sizes are rounded up to the nearest power of two.',
-        type: 'Integer',
-        default: '0 (meaning use the value from the corresponding impalad startup option)'
-      },
-      'RUNTIME_FILTER_MIN_SIZE': {
-        description: 'The RUNTIME_FILTER_MIN_SIZE query option adjusts the settings for the runtime filtering feature. This option defines the minimum size for a filter, no matter what the estimates produced by the planner are. This value also overrides any lower number specified for the RUNTIME_BLOOM_FILTER_SIZE query option. Filter sizes are rounded up to the nearest power of two.',
-        type: 'Integer',
-        default: '0 (meaning use the value from the corresponding impalad startup option)'
-      },
-      'RUNTIME_FILTER_MODE': {
-        description: 'The RUNTIME_FILTER_MODE query option adjusts the settings for the runtime filtering feature. It turns this feature on and off, and controls how extensively the filters are transmitted between hosts.',
-        type: 'Numeric (0, 1, 2) or corresponding mnemonic strings (OFF, LOCAL, GLOBAL).',
-        default: '2 (equivalent to GLOBAL); formerly was 1 / LOCAL, in CDH 5.7 / Impala 2.5'
-      },
-      'RUNTIME_FILTER_WAIT_TIME_MS': {
-        description: 'The RUNTIME_FILTER_WAIT_TIME_MS query option adjusts the settings for the runtime filtering feature. It specifies a time in milliseconds that each scan node waits for runtime filters to be produced by other plan fragments.',
-        type: 'Integer',
-        default: '0 (meaning use the value from the corresponding impalad startup option)'
-      },
-      'S3_SKIP_INSERT_STAGING': {
-        description: 'Speeds up INSERT operations on tables or partitions residing on the Amazon S3 filesystem. The tradeoff is the possibility of inconsistent data left behind if an error occurs partway through the operation.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'true (shown as 1 in output of SET statement)'
-      },
-      'SCHEDULE_RANDOM_REPLICA': {
-        description: 'The SCHEDULE_RANDOM_REPLICA query option fine-tunes the algorithm for deciding which host processes each HDFS data block. It only applies to tables and partitions that are not enabled for the HDFS caching feature.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'SCRATCH_LIMIT': {
-        description: 'Specifies the maximum amount of disk storage, in bytes, that any Impala query can consume on any host using the "spill to disk" mechanism that handles queries that exceed the memory limit.',
-        type: 'Numeric, with optional unit specifier',
-        default: '-1 (amount of spill space is unlimited)'
-      },
-      'SHUFFLE_DISTINCT_EXPRS': {
-        description: 'The SHUFFLE_DISTINCT_EXPRS query option controls the shuffling behavior when a query has both grouping and distinct expressions. Impala can optionally include the distinct expressions in the hash exchange to spread the data among more nodes. However, this plan requires one more hash exchange phase. It is recommended that you turn off this option if the NDVs of the grouping expressions are high.',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'SYNC_DDL': {
-        description: 'When enabled, causes any DDL operation such as CREATE TABLE or ALTER TABLE to return only when the changes have been propagated to all other Impala nodes in the cluster by the Impala catalog service. That way, if you issue a subsequent CONNECT statement in impala-shell to connect to a different node in the cluster, you can be sure that other node will already recognize any added or changed tables. (The catalog service automatically broadcasts the DDL changes to all nodes automatically, but without this option there could be a period of inconsistency if you quickly switched to another node, such as by issuing a subsequent query through a load-balancing proxy.)',
-        type: 'Boolean; recognized values are 1 and 0, or true and false; any other value interpreted as false',
-        default: 'false (shown as 0 in output of SET statement)'
-      },
-      'TIMEZONE': {
-        description: 'The TIMEZONE query option defines the timezone used for conversions between UTC and the local time. If not set, Impala uses the system time zone where the Coordinator Impalad runs. As query options are not sent to the Coordinator immediately, the timezones are validated only when the query runs.',
-        type: 'String, can be a canonical code or a time zone name defined in the IANA Time Zone Database. The value is case-sensitive.',
-        default: 'Coordinator Impalad system time zone.'
-      },
-      'TOPN_BYTES_LIMIT': {
-        description: 'The TOPN_BYTES_LIMIT query option places a limit on the amount of estimated memory that Impala can process for top-N queries.',
-        type: 'Numeric',
-        default: '536870912 (512 MB)'
-      }
-    }
-  };
-
-  var createOptionHtml = function (funcDesc) {
-    var html = '<div class="fn-details">';
-    if (funcDesc.description) {
-      html += '<p><span style="white-space: pre; font-family: monospace;">' + funcDesc.description + '</span></p>';
-    }
-    if (funcDesc.type) {
-      html += '<p>Type:' + funcDesc.type + '</p>';
-    }
-    if (funcDesc.default) {
-      html += '<p>Default:' + funcDesc.default + '</p>';
-    }
-    html += '<div>';
-    return html;
-  };
-
-  var suggestOptions = function (dialect, completions, category) {
-    if (dialect === 'hive' || dialect === 'impala') {
-      Object.keys(SET_OPTIONS[dialect]).forEach(function (name) {
-        completions.push({
-          category: category,
-          value: name,
-          meta: '',
-          popular: ko.observable(false),
-          weightAdjust: 0,
-          details: SET_OPTIONS[dialect][name]
-        })
-      });
-    }
-  };
-
-  return {
-    suggestOptions : suggestOptions
-  };
-})();
-
-var SqlFunctions = (function () {
-
-  var MATHEMATICAL_FUNCTIONS = {
-    hive: {
-      abs: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'abs(DOUBLE a)',
-        draggable: 'abs()',
-        description: 'Returns the absolute value.'
-      },
-      acos: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'acos(DECIMAL|DOUBLE a)',
-        draggable: 'acos()',
-        description: 'Returns the arccosine of a if -1<=a<=1 or NULL otherwise.'
-      },
-      asin: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'asin(DECIMAL|DOUBLE a)',
-        draggable: 'asin()',
-        description: 'Returns the arc sin of a if -1<=a<=1 or NULL otherwise.'
-      },
-      atan: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'atan(DECIMAL|DOUBLE a)',
-        draggable: 'atan()',
-        description: 'Returns the arctangent of a.'
-      },
-      bin: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}]],
-        signature: 'bin(BIGINT a)',
-        draggable: 'bin()',
-        description: 'Returns the number in binary format'
-      },
-      bround: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'INT', optional: true}]],
-        signature: 'bround(DOUBLE a [, INT decimals])',
-        draggable: 'bround()',
-        description: 'Returns the rounded BIGINT value of a using HALF_EVEN rounding mode with optional decimal places d.'
-      },
-      cbrt: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'cbft(DOUBLE a)',
-        draggable: 'cbft()',
-        description: 'Returns the cube root of a double value.'
-      },
-      ceil: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'ceil(DOUBLE a)',
-        draggable: 'ceil()',
-        description: 'Returns the minimum BIGINT value that is equal to or greater than a.'
-      },
-      ceiling: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'ceiling(DOUBLE a)',
-        draggable: 'ceiling()',
-        description: 'Returns the minimum BIGINT value that is equal to or greater than a.'
-      },
-      conv: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BIGINT'}, {type: 'STRING'}], [{type: 'INT'}], [{type: 'INT'}]],
-        signature: 'conv(BIGINT|STRING a, INT from_base, INT to_base)',
-        draggable: 'conv()',
-        description: 'Converts a number from a given base to another'
-      },
-      cos: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'cos(DECIMAL|DOUBLE a)',
-        draggable: 'cos()',
-        description: 'Returns the cosine of a (a is in radians).'
-      },
-      degrees: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'degrees(DECIMAL|DOUBLE a)',
-        draggable: 'degrees()',
-        description: 'Converts value of a from radians to degrees.'
-      },
-      e: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[]],
-        signature: 'e()',
-        draggable: 'e()',
-        description: 'Returns the value of e.'
-      },
-      exp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'exp(DECIMAL|DOUBLE a)',
-        draggable: 'exp()',
-        description: 'Returns e^a where e is the base of the natural logarithm.'
-      },
-      factorial: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'factorial(INT a)',
-        draggable: 'factorial()',
-        description: 'Returns the factorial of a. Valid a is [0..20].'
-      },
-      floor: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'floor(DOUBLE a)',
-        draggable: 'floor()',
-        description: 'Returns the maximum BIGINT value that is equal to or less than a.'
-      },
-      greatest: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'greatest(T a1, T a2, ...)',
-        draggable: 'greatest()',
-        description: 'Returns the greatest value of the list of values. Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with ">" operator.'
-      },
-      hex: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}, {type: 'BINARY'}, {type: 'STRING'}]],
-        signature: 'hex(BIGINT|BINARY|STRING a)',
-        draggable: 'hex()',
-        description: 'If the argument is an INT or binary, hex returns the number as a STRING in hexadecimal format. Otherwise if the number is a STRING, it converts each character into its hexadecimal representation and returns the resulting STRING.'
-      },
-      least: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'least(T a1, T a2, ...)',
-        draggable: 'least()',
-        description: 'Returns the least value of the list of values. Fixed to return NULL when one or more arguments are NULL, and strict type restriction relaxed, consistent with "<" operator.'
-      },
-      ln: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'ln(DECIMAL|DOUBLE a)',
-        draggable: 'ln()',
-        description: 'Returns the natural logarithm of the argument a'
-      },
-      log: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}], [{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'log(DECIMAL|DOUBLE base, DECIMAL|DOUBLE a)',
-        draggable: 'log()',
-        description: 'Returns the base-base logarithm of the argument a.'
-      },
-      log10: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'log10(DECIMAL|DOUBLE a)',
-        draggable: 'log10()',
-        description: 'Returns the base-10 logarithm of the argument a.'
-      },
-      log2: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'log2(DECIMAL|DOUBLE a)',
-        draggable: 'log2()',
-        description: 'Returns the base-2 logarithm of the argument a.'
-      },
-      negative: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'INT'}]],
-        signature: 'negative(T<DOUBLE|INT> a)',
-        draggable: 'negative()',
-        description: 'Returns -a.'
-      },
-      pi: {
-        returnTypes: ['DOUBLE'],
-        arguments: [],
-        signature: 'pi()',
-        draggable: 'pi()',
-        description: 'Returns the value of pi.'
-      },
-      pmod: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'INT'}], [{type: 'T'}]],
-        signature: 'pmod(T<DOUBLE|INT> a, T b)',
-        draggable: 'pmod()',
-        description: 'Returns the positive value of a mod b'
-      },
-      positive: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'INT'}]],
-        signature: 'positive(T<DOUBLE|INT> a)',
-        draggable: 'positive()',
-        description: 'Returns a.'
-      },
-      pow: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'pow(DOUBLE a, DOUBLE p)',
-        draggable: 'pow()',
-        description: 'Returns a^p'
-      },
-      power: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'power(DOUBLE a, DOUBLE p)',
-        draggable: 'power()',
-        description: 'Returns a^p'
-      },
-      radians: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'radians(DECIMAL|DOUBLE a)',
-        draggable: 'radians()',
-        description: 'Converts value of a from degrees to radians.'
-      },
-      rand: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'INT', optional: true}]],
-        signature: 'rand([INT seed])',
-        draggable: 'rand()',
-        description: 'Returns a random number (that changes from row to row) that is distributed uniformly from 0 to 1. Specifying the seed will make sure the generated random number sequence is deterministic.'
-      },
-      round: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'INT', optional: true}]],
-        signature: 'round(DOUBLE a [, INT d])',
-        draggable: 'round()',
-        description: 'Returns the rounded BIGINT value of a or a rounded to d decimal places.'
-      },
-      shiftleft: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BIGINT'}, {type: 'INT'}, {type: 'SMALLINT'}, {type: 'TINYINT'}], [{type: 'INT'}]],
-        signature: 'shiftleft(T<BIGINT|INT|SMALLINT|TINYINT> a, INT b)',
-        draggable: 'shiftleft()',
-        description: 'Bitwise left shift. Shifts a b positions to the left. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.'
-      },
-      shiftright: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BIGINT'}, {type: 'INT'}, {type: 'SMALLINT'}, {type: 'TINYINT'}], [{type: 'INT'}]],
-        signature: 'shiftright(T<BIGINT|INT|SMALLINT|TINYINT> a, INT b)',
-        draggable: 'shiftright()',
-        description: 'Bitwise right shift. Shifts a b positions to the right. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.'
-      },
-      shiftrightunsigned: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BIGINT'}, {type: 'INT'}, {type: 'SMALLINT'}, {type: 'TINYINT'}], [{type: 'INT'}]],
-        signature: 'shiftrightunsigned(T<BIGINT|INT|SMALLINT|TINYINT> a, INT b)',
-        draggable: 'shiftrightunsigned()',
-        description: 'Bitwise unsigned right shift. Shifts a b positions to the right. Returns int for tinyint, smallint and int a. Returns bigint for bigint a.'
-      },
-      sign: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'INT'}]],
-        signature: 'sign(T<DOUBLE|INT> a)',
-        draggable: 'sign()',
-        description: 'Returns the sign of a as \'1.0\' (if a is positive) or \'-1.0\' (if a is negative), \'0.0\' otherwise. The decimal version returns INT instead of DOUBLE.'
-      },
-      sin: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'sin(DECIMAL|DOUBLE a)',
-        draggable: 'sin()',
-        description: 'Returns the sine of a (a is in radians).'
-      },
-      sqrt: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'sqrt(DECIMAL|DOUBLE a)',
-        draggable: 'sqrt()',
-        description: 'Returns the square root of a'
-      },
-      tan: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}]],
-        signature: 'tan(DECIMAL|DOUBLE a)',
-        draggable: 'tan()',
-        description: 'Returns the tangent of a (a is in radians).'
-      },
-      unhex: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'unhex(STRING a)',
-        draggable: 'unhex()',
-        description: 'Inverse of hex. Interprets each pair of characters as a hexadecimal number and converts to the byte representation of the number.'
-      },
-      width_bucket: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'NUMBER'}, {type: 'NUMBER'}, {type: 'NUMBER'}, {type: 'INT'}]],
-        signature: 'width_bucket(NUMBER expr, NUMBER min_value, NUMBER max_value, INT num_buckets)',
-        draggable: 'width_bucket()',
-        description: 'Returns an integer between 0 and num_buckets+1 by mapping expr into the ith equally sized bucket. Buckets are made by dividing [min_value, max_value] into equally sized regions. If expr < min_value, return 1, if expr > max_value return num_buckets+1. (as of Hive 3.0.0)'
-      }
-    },
-    impala: {
-      abs: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'abs(T a)',
-        draggable: 'abs()',
-        description: 'Returns the absolute value of the argument. Use this function to ensure all return values are positive. This is different than the positive() function, which returns its argument unchanged (even if the argument was negative).'
-      },
-      acos: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'acos(DOUBLE a)',
-        draggable: 'acos()',
-        description: 'Returns the arccosine of the argument.'
-      },
-      asin: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'asin(DOUBLE a)',
-        draggable: 'asin()',
-        description: 'Returns the arcsine of the argument.'
-      },
-      atan: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'atan(DOUBLE a)',
-        draggable: 'atan()',
-        description: 'Returns the arctangent of the argument.'
-      },
-      atan2: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'atan2(DOUBLE a, DOUBLE b)',
-        draggable: 'atan2()',
-        description: 'Returns the arctangent of the two arguments, with the signs of the arguments used to determine the quadrant of the result.'
-      },
-      bin: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}]],
-        signature: 'bin(BIGINT a)',
-        draggable: 'bin()',
-        description: 'Returns the binary representation of an integer value, that is, a string of 0 and 1 digits.'
-      },
-      ceil: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}]],
-        signature: 'ceil(T<DOUBLE|DECIMAL> a)',
-        draggable: 'ceil()',
-        description: 'Returns the smallest integer that is greater than or equal to the argument.'
-      },
-      ceiling: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}]],
-        signature: 'ceiling(T<DOUBLE|DECIMAL> a)',
-        draggable: 'ceiling()',
-        description: 'Returns the smallest integer that is greater than or equal to the argument.'
-      },
-      conv: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BIGINT'}, {type: 'STRING'}], [{type: 'INT'}], [{type: 'INT'}]],
-        signature: 'conv(T<BIGINT|STRING> a, INT from_base, INT to_base)',
-        draggable: 'conv()',
-        description: 'Returns a string representation of an integer value in a particular base. The input value can be a string, for example to convert a hexadecimal number such as fce2 to decimal. To use the return value as a number (for example, when converting to base 10), use CAST() to convert to the appropriate type.'
-      },
-      cos: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'cos(DOUBLE a)',
-        draggable: 'cos()',
-        description: 'Returns the cosine of the argument.'
-      },
-      cosh: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'cosh(DOUBLE a)',
-        draggable: 'cosh()',
-        description: 'Returns the hyperbolic cosine of the argument.'
-      },
-      cot: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'cot(DOUBLE a)',
-        draggable: 'cot()',
-        description: 'Returns the cotangent of the argument.'
-      },
-      dceil: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}]],
-        signature: 'dceil(T<DOUBLE|DECIMAL> a)',
-        draggable: 'dceil()',
-        description: 'Returns the smallest integer that is greater than or equal to the argument.'
-      },
-      degrees: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'degrees(DOUBLE a)',
-        draggable: 'degrees()',
-        description: 'Converts argument value from radians to degrees.'
-      },
-      dexp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'dexp(DOUBLE a)',
-        draggable: 'dexp()',
-        description: 'Returns the mathematical constant e raised to the power of the argument.'
-      },
-      dfloor: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}]],
-        signature: 'dfloor(T<DOUBLE|DECIMAL> a)',
-        draggable: 'dfloor()',
-        description: 'Returns the largest integer that is less than or equal to the argument.'
-      },
-      dlog1: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'dlog1(DOUBLE a)',
-        draggable: 'dlog1()',
-        description: 'Returns the natural logarithm of the argument.'
-      },
-      dpow: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'dpow(DOUBLE a, DOUBLE p)',
-        draggable: 'dpow()',
-        description: 'Returns the first argument raised to the power of the second argument.'
-      },
-      dround: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}], [{type: 'INT', optional: true}]],
-        signature: 'dround(DOUBLE a [, INT d]), round(DECIMAL val, INT d)',
-        draggable: 'dround()',
-        description: 'Rounds a floating-point value. By default (with a single argument), rounds to the nearest integer. Values ending in .5 are rounded up for positive numbers, down for negative numbers (that is, away from zero). The optional second argument specifies how many digits to leave after the decimal point; values greater than zero produce a floating-point return value rounded to the requested number of digits to the right of the decimal point.'
-      },
-      dsqrt: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'dsqrt(DOUBLE a)',
-        draggable: 'dsqrt()',
-        description: 'Returns the square root of the argument.'
-      },
-      dtrunc: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{ type: 'NUMBER', optional: true }]],
-        signature: 'dtrunc(T<DOUBLE|DECIMAL> a, [NUMBER b])',
-        draggable: 'dtrunc()',
-        description: 'Removes some or all fractional digits from a numeric value. With no argument, removes all fractional digits, leaving an integer value. The optional argument specifies the number of fractional digits to include in the return value, and only applies with the argument type is DECIMAL. truncate(), trunc() and dtrunc() are aliases for the same function.'
-      },
-      e: {
-        returnTypes: ['DOUBLE'],
-        arguments: [],
-        signature: 'e()',
-        draggable: 'e()',
-        description: 'Returns the mathematical constant e.'
-      },
-      exp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'exp(DOUBLE a)',
-        draggable: 'exp()',
-        description: 'Returns the mathematical constant e raised to the power of the argument.'
-      },
-      factorial: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'factorial(T a)',
-        draggable: 'factorial()',
-        description: 'Computes the factorial of an integer value. It works with any integer type. You can use either the factorial() function or the ! operator. The factorial of 0 is 1. Likewise, the factorial() function returns 1 for any negative value. The maximum positive value for the input argument is 20; a value of 21 or greater overflows the range for a BIGINT and causes an error.'
-      },
-      floor: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}]],
-        signature: 'floor(T<DOUBLE|DECIMAL> a)',
-        draggable: 'floor()',
-        description: 'Returns the largest integer that is less than or equal to the argument.'
-      },
-      fmod: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DOUBLE'}], [{type: 'FLOAT'}, {type: 'FLOAT'}]],
-        signature: 'fmod(DOUBLE a, DOUBLE b), fmod(FLOAT a, FLOAT b)',
-        draggable: 'fmod()',
-        description: 'Returns the modulus of a floating-point number'
-      },
-      fpow: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'fpow(DOUBLE a, DOUBLE p)',
-        draggable: 'fpow()',
-        description: 'Returns the first argument raised to the power of the second argument.'
-      },
-      fnv_hash: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'fnv_hash(T a)',
-        draggable: 'fnv_hash()',
-        description: 'Returns a consistent 64-bit value derived from the input argument, for convenience of implementing hashing logic in an application.'
-      },
-      greatest: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'greatest(T a1, T a2, ...)',
-        draggable: 'greatest()',
-        description: 'Returns the largest value from a list of expressions.'
-      },
-      hex: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}, {type: 'STRING'}]],
-        signature: 'hex(T<BIGINT|STRING> a)',
-        draggable: 'hex()',
-        description: 'Returns the hexadecimal representation of an integer value, or of the characters in a string.'
-      },
-      is_inf: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'is_inf(DOUBLE a)',
-        draggable: 'is_inf()',
-        description: 'Tests whether a value is equal to the special value "inf", signifying infinity.'
-      },
-      is_nan: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'is_nan(DOUBLE A)',
-        draggable: 'is_nan()',
-        description: 'Tests whether a value is equal to the special value "NaN", signifying "not a number".'
-      },
-      least: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'least(T a1, T a2, ...)',
-        draggable: 'least()',
-        description: 'Returns the smallest value from a list of expressions.'
-      },
-      ln: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'ln(DOUBLE a)',
-        draggable: 'ln()',
-        description: 'Returns the natural logarithm of the argument.'
-      },
-      log: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'log(DOUBLE base, DOUBLE a)',
-        draggable: 'log()',
-        description: 'Returns the logarithm of the second argument to the specified base.'
-      },
-      log10: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'log10(DOUBLE a)',
-        draggable: 'log10()',
-        description: 'Returns the logarithm of the argument to the base 10.'
-      },
-      log2: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'log2(DOUBLE a)',
-        draggable: 'log2()',
-        description: 'Returns the logarithm of the argument to the base 2.'
-      },
-      max_bigint: {
-        returnTypes: ['BIGINT'],
-        arguments: [],
-        signature: 'max_bigint()',
-        draggable: 'max_bigint()',
-        description: 'Returns the largest value of the associated integral type.'
-      },
-      max_int: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'max_int()',
-        draggable: 'max_int()',
-        description: 'Returns the largest value of the associated integral type.'
-      },
-      max_smallint: {
-        returnTypes: ['SMALLINT'],
-        arguments: [],
-        signature: 'max_smallint()',
-        draggable: 'max_smallint()',
-        description: 'Returns the largest value of the associated integral type.'
-      },
-      max_tinyint: {
-        returnTypes: ['TINYINT'],
-        arguments: [],
-        signature: 'max_tinyint()',
-        draggable: 'max_tinyint()',
-        description: 'Returns the largest value of the associated integral type.'
-      },
-      min_bigint: {
-        returnTypes: ['BIGINT'],
-        arguments: [],
-        signature: 'min_bigint()',
-        draggable: 'min_bigint()',
-        description: 'Returns the smallest value of the associated integral type (a negative number).'
-      },
-      min_int: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'min_int()',
-        draggable: 'min_int()',
-        description: 'Returns the smallest value of the associated integral type (a negative number).'
-      },
-      min_smallint: {
-        returnTypes: ['SMALLINT'],
-        arguments: [],
-        signature: 'min_smallint()',
-        draggable: 'min_smallint()',
-        description: 'Returns the smallest value of the associated integral type (a negative number).'
-      },
-      min_tinyint: {
-        returnTypes: ['TINYINT'],
-        arguments: [],
-        signature: 'min_tinyint()',
-        draggable: 'min_tinyint()',
-        description: 'Returns the smallest value of the associated integral type (a negative number).'
-      },
-      mod: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'mod(T a, T b)',
-        draggable: 'mod()',
-        description: 'Returns the modulus of a number. Equivalent to the % arithmetic operator. Works with any size integer type, any size floating-point type, and DECIMAL with any precision and scale.'
-      },
-      murmur_hash: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'murmur_hash(T a)',
-        draggable: 'murmur_hash()',
-        description: 'Returns a consistent 64-bit value derived from the input argument, for convenience of implementing MurmurHash2 non-cryptographic hash function.'
-      },
-      negative: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'negative(T a)',
-        draggable: 'negative()',
-        description: 'Returns the argument with the sign reversed; returns a positive value if the argument was already negative.'
-      },
-      pi: {
-        returnTypes: ['DOUBLE'], 
-        arguments: [], 
-        signature: 'pi()',
-        draggable: 'pi()', 
-        description: 'Returns the constant pi.'
-      },
-      pmod: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'INT'}], [{type: 'T'}]],
-        signature: 'pmod(T<DOUBLE|INT> a, T b)',
-        draggable: 'pmod()',
-        description: 'Returns the positive modulus of a number.'
-      },
-      positive: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'positive(T a)',
-        draggable: 'positive()',
-        description: 'Returns the original argument unchanged (even if the argument is negative).'
-      },
-      pow: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'pow(DOUBLE a, DOUBLE p)',
-        draggable: 'pow()',
-        description: 'Returns the first argument raised to the power of the second argument.'
-      },
-      power: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}]],
-        signature: 'power(DOUBLE a, DOUBLE p)',
-        draggable: 'power()',
-        description: 'Returns the first argument raised to the power of the second argument.'
-      },
-      precision: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'NUMBER'}]],
-        signature: 'precision(numeric_expression)',
-        draggable: 'precision()',
-        description: 'Computes the precision (number of decimal digits) needed to represent the type of the argument expression as a DECIMAL value.'
-      },
-      quotient: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'BIGINT'}, {type: 'DOUBLE'}], [{type: 'BIGINT'}, {type: 'DOUBLE'}]],
-        signature: 'quotient(BIGINT numerator, BIGINT denominator), quotient(DOUBLE numerator, DOUBLE denominator)',
-        draggable: 'quotient()',
-        description: 'Returns the first argument divided by the second argument, discarding any fractional part. Avoids promoting arguments to DOUBLE as happens with the / SQL operator.'
-      },
-      radians: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'radians(DOUBLE a)',
-        draggable: 'radians()',
-        description: 'Converts argument value from degrees to radians.'
-      },
-      rand: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'INT', optional: true}]],
-        signature: 'rand([INT seed])',
-        draggable: 'rand()',
-        description: 'Returns a random value between 0 and 1. After rand() is called with a seed argument, it produces a consistent random sequence based on the seed value.'
-      },
-      random: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'INT', optional: true}]],
-        signature: 'random([INT seed])',
-        draggable: 'random()',
-        description: 'Returns a random value between 0 and 1. After rand() is called with a seed argument, it produces a consistent random sequence based on the seed value.'
-      },
-      round: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DECIMAL'}, {type: 'DOUBLE'}], [{type: 'INT', optional: true}]],
-        signature: 'round(DOUBLE a [, INT d]), round(DECIMAL val, INT d)',
-        draggable: 'round()',
-        description: 'Rounds a floating-point value. By default (with a single argument), rounds to the nearest integer. Values ending in .5 are rounded up for positive numbers, down for negative numbers (that is, away from zero). The optional second argument specifies how many digits to leave after the decimal point; values greater than zero produce a floating-point return value rounded to the requested number of digits to the right of the decimal point.'
-      },
-      scale: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'NUMBER'}]],
-        signature: 'scale(numeric_expression)',
-        draggable: 'scale()',
-        description: 'Computes the scale (number of decimal digits to the right of the decimal point) needed to represent the type of the argument expression as a DECIMAL value.'
-      },
-      sign: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'sign(DOUBLE a)',
-        draggable: 'sign()',
-        description: 'Returns -1, 0, or 1 to indicate the signedness of the argument value.'
-      },
-      sin: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'sin(DOUBLE a)',
-        draggable: 'sin()',
-        description: 'Returns the sine of the argument.'
-      },
-      sinh: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'sinh(DOUBLE a)',
-        draggable: 'sinh()',
-        description: 'Returns the hyperbolic sine of the argument.'
-      },
-      sqrt: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'sqrt(DOUBLE a)',
-        draggable: 'sqrt()',
-        description: 'Returns the square root of the argument.'
-      },
-      tan: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'tan(DOUBLE a)',
-        draggable: 'tan()',
-        description: 'Returns the tangent of the argument.'
-      },
-      tanh: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DOUBLE'}]],
-        signature: 'tanh(DOUBLE a)',
-        draggable: 'tanh()',
-        description: 'Returns the tangent of the argument.'
-      },
-      trunc: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{ type: 'NUMBER', optional: true }]],
-        signature: 'trunc(T<DOUBLE|DECIMAL> a, [NUMBER b])',
-        draggable: 'trunc()',
-        description: 'Removes some or all fractional digits from a numeric value. With no argument, removes all fractional digits, leaving an integer value. The optional argument specifies the number of fractional digits to include in the return value, and only applies with the argument type is DECIMAL. truncate(), trunc() and dtrunc() are aliases for the same function.'
-      },
-      truncate: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{ type: 'NUMBER', optional: true }]],
-        signature: 'truncate(T<DOUBLE|DECIMAL> a, [NUMBER b])',
-        draggable: 'truncate()',
-        description: 'Removes some or all fractional digits from a numeric value. With no argument, removes all fractional digits, leaving an integer value. The optional argument specifies the number of fractional digits to include in the return value, and only applies with the argument type is DECIMAL. truncate(), trunc() and dtrunc() are aliases for the same function.'
-      },
-      unhex: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'unhex(STRING a)',
-        draggable: 'unhex()',
-        description: 'Returns a string of characters with ASCII values corresponding to pairs of hexadecimal digits in the argument.'
-      },
-      width_bucket: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{type: 'DOUBLE'}, {type: 'DECIMAL'}], [{type: 'INT'}]],
-        signature: 'width_bucket(DECIMAL expr, DECIMAL min_value, DECIMAL max_value, INT num_buckets)',
-        draggable: 'width_bucket()',
-        description: 'Returns the bucket number in which the expr value would fall in the histogram where its range between min_value and max_value is divided into num_buckets buckets of identical sizes.'
-      },
-    }
-  };
-
-  var COMPLEX_TYPE_CONSTRUCTS = {
-    hive: {
-      array: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'array(val1, val2, ...)',
-        draggable: 'array()',
-        description: 'Creates an array with the given elements.'
-      },
-      create_union: {
-        returnTypes: ['UNION'],
-        arguments: [[{type: 'T'}], [{type: 'T', multiple: true}]],
-        signature: 'create_union(tag, val1, val2, ...)',
-        draggable: 'create_union()',
-        description: 'Creates a union type with the value that is being pointed to by the tag parameter.'
-      },
-      map: {
-        returnTypes: ['MAP'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'map(key1, value1, ...)',
-        draggable: 'map()',
-        description: 'Creates a map with the given key/value pairs.'
-      },
-      named_struct: {
-        returnTypes: ['STRUCT'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'named_struct(name1, val1, ...)',
-        draggable: 'named_struct()',
-        description: 'Creates a struct with the given field names and values.'
-      },
-      struct: {
-        returnTypes: ['STRUCT'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'struct(val1, val2, ...)',
-        draggable: 'struct()',
-        description: 'Creates a struct with the given field values. Struct field names will be col1, col2, ....'
-      }
-    },
-    impala: {}
-  };
-
-  var AGGREGATE_FUNCTIONS = {
-    generic: {
-      count: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'count(col)',
-        draggable: 'count()',
-        description: 'count(*) - Returns the total number of retrieved rows, including rows containing NULL values. count(expr) - Returns the number of rows for which the supplied expression is non-NULL.'
-      },
-      sum: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'sum(col)',
-        draggable: 'sum()',
-        description: 'Returns the sum of the elements in the group or the sum of the distinct values of the column in the group.'
-      },
-      max: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'max(col)',
-        draggable: 'max()',
-        description: 'Returns the maximum value of the column in the group.'
-      },
-      min: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'min(col)',
-        draggable: 'min()',
-        description: 'Returns the minimum of the column in the group.'
-      }
-    },
-    hive: {
-      avg: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'avg(col)',
-        draggable: 'avg()',
-        description: 'Returns the average of the elements in the group or the average of the distinct values of the column in the group.'
-      },
-      collect_set: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'T'}]],
-        signature: 'collect_set(col)',
-        draggable: 'collect_set()',
-        description: 'Returns a set of objects with duplicate elements eliminated.'
-      },
-      collect_list: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'T'}]],
-        signature: 'collect_list(col)',
-        draggable: 'collect_list()',
-        description: 'Returns a list of objects with duplicates. (As of Hive 0.13.0.)'
-      },
-      corr: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'corr(col1, col2)',
-        draggable: 'corr()',
-        description: 'Returns the Pearson coefficient of correlation of a pair of a numeric columns in the group.'
-      },
-      count: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'count([DISTINCT] col)',
-        draggable: 'count()',
-        description: 'count(*) - Returns the total number of retrieved rows, including rows containing NULL values. count(expr) - Returns the number of rows for which the supplied expression is non-NULL. count(DISTINCT expr[, expr]) - Returns the number of rows for which the supplied expression(s) are unique and non-NULL. Execution of this can be optimized with hive.optimize.distinct.rewrite.'
-      },
-      covar_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'covar_pop(col1, col2)',
-        draggable: 'covar_pop()',
-        description: 'Returns the population covariance of a pair of numeric columns in the group.'
-      },
-      covar_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'covar_samp(col1, col2)',
-        draggable: 'covar_samp()',
-        description: 'Returns the sample covariance of a pair of a numeric columns in the group.'
-      },
-      histogram_numeric: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'T'}], [{type: 'INT'}]],
-        signature: 'histogram_numeric(col, b)',
-        draggable: 'histogram_numeric()',
-        description: 'Computes a histogram of a numeric column in the group using b non-uniformly spaced bins. The output is an array of size b of double-valued (x,y) coordinates that represent the bin centers and heights.'
-      },
-      max: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'max(col)',
-        draggable: 'max()',
-        description: 'Returns the maximum value of the column in the group.'
-      },
-      min: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'min(col)',
-        draggable: 'min()',
-        description: 'Returns the minimum of the column in the group.'
-      },
-      ntile: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'ntile(INT x)',
-        draggable: 'ntile()',
-        description: 'Divides an ordered partition into x groups called buckets and assigns a bucket number to each row in the partition. This allows easy calculation of tertiles, quartiles, deciles, percentiles and other common summary statistics. (As of Hive 0.11.0.)'
-      },
-      percentile: {
-        returnTypes: ['DOUBLE', 'ARRAY'],
-        arguments: [[{type: 'BIGINT'}], [{type: 'ARRAY'}, {type: 'DOUBLE'}]],
-        signature: 'percentile(BIGINT col, p), array<DOUBLE> percentile(BIGINT col, array(p1 [, p2]...))',
-        draggable: 'percentile()',
-        description: 'Returns the exact pth percentile (or percentiles p1, p2, ..) of a column in the group (does not work with floating point types). p must be between 0 and 1. NOTE: A true percentile can only be computed for integer values. Use PERCENTILE_APPROX if your input is non-integral.'
-      },
-      percentile_approx: {
-        returnTypes: ['DOUBLE', 'ARRAY'],
-        arguments: [[{type: 'DOUBLE'}], [{type: 'DOUBLE'}, {type: 'ARRAY'}], [{type: 'BIGINT', optional: true}]],
-        signature: 'percentile_approx(DOUBLE col, p, [, B]), array<DOUBLE> percentile_approx(DOUBLE col, array(p1 [, p2]...), [, B])',
-        draggable: 'percentile_approx()',
-        description: 'Returns an approximate pth percentile (or percentiles p1, p2, ..) of a numeric column (including floating point types) in the group. The B parameter controls approximation accuracy at the cost of memory. Higher values yield better approximations, and the default is 10,000. When the number of distinct values in col is smaller than B, this gives an exact percentile value.'
-      },
-      regr_avgx: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_avgx(T independent, T dependent)',
-        draggable: 'regr_avgx()',
-        description: 'Equivalent to avg(dependent). As of Hive 2.2.0.'
-      },
-      regr_avgy: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_avgy(T independent, T dependent)',
-        draggable: 'regr_avgy()',
-        description: 'Equivalent to avg(dependent). As of Hive 2.2.0.'
-      },
-      regr_count: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_count(T independent, T dependent)',
-        draggable: 'regr_count()',
-        description: 'Returns the number of non-null pairs used to fit the linear regression line. As of Hive 2.2.0.'
-      },
-      regr_intercept: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_intercept(T independent, T dependent)',
-        draggable: 'regr_intercept()',
-        description: 'Returns the y-intercept of the linear regression line, i.e. the value of b in the equation dependent = a * independent + b. As of Hive 2.2.0.'
-      },
-      regr_r2: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_r2(T independent, T dependent)',
-        draggable: 'regr_r2()',
-        description: 'Returns the coefficient of determination for the regression. As of Hive 2.2.0.'
-      },
-      regr_slope: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_slope(T independent, T dependent)',
-        draggable: 'regr_slope()',
-        description: 'Returns the slope of the linear regression line, i.e. the value of a in the equation dependent = a * independent + b. As of Hive 2.2.0.'
-      },
-      regr_sxx: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_sxx(T independent, T dependent)',
-        draggable: 'regr_sxx()',
-        description: 'Equivalent to regr_count(independent, dependent) * var_pop(dependent). As of Hive 2.2.0.'
-      },
-      regr_sxy: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_sxy(T independent, T dependent)',
-        draggable: 'regr_sxy()',
-        description: 'Equivalent to regr_count(independent, dependent) * covar_pop(independent, dependent). As of Hive 2.2.0.'
-      },
-      regr_syy: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'regr_syy(T independent, T dependent)',
-        draggable: 'regr_syy()',
-        description: 'Equivalent to regr_count(independent, dependent) * var_pop(independent). As of Hive 2.2.0.'
-      },
-      stddev_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'stddev_pop(col)',
-        draggable: 'stddev_pop()',
-        description: 'Returns the standard deviation of a numeric column in the group.'
-      },
-      stddev_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'stddev_samp(col)',
-        draggable: 'stddev_samp()',
-        description: 'Returns the unbiased sample standard deviation of a numeric column in the group.'
-      },
-      sum: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'sum(col)',
-        draggable: 'sum()',
-        description: 'Returns the sum of the elements in the group or the sum of the distinct values of the column in the group.'
-      },
-      variance: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'variance(col)',
-        draggable: 'variance()',
-        description: 'Returns the variance of a numeric column in the group.'
-      },
-      var_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'var_pop(col)',
-        draggable: 'var_pop()',
-        description: 'Returns the variance of a numeric column in the group.'
-      },
-      var_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'var_samp(col)',
-        draggable: 'var_samp()',
-        description: 'Returns the unbiased sample variance of a numeric column in the group.'
-      }
-    },
-    impala: {
-      appx_median: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'appx_median([DISTINCT|ALL] T col)',
-        draggable: 'appx_median()',
-        description: 'An aggregate function that returns a value that is approximately the median (midpoint) of values in the set of input values.'
-      },
-      avg: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'NUMBER'}]],
-        signature: 'avg([DISTINCT|ALL] col)',
-        draggable: 'avg()',
-        description: 'An aggregate function that returns the average value from a set of numbers. Its single argument can be numeric column, or the numeric result of a function or expression applied to the column value. Rows with a NULL value for the specified column are ignored. If the table is empty, or all the values supplied to AVG are NULL, AVG returns NULL.'
-      },
-      count: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'T'}]],
-        signature: 'count([DISTINCT|ALL] col)',
-        draggable: 'count()',
-        description: 'An aggregate function that returns the number of rows, or the number of non-NULL rows.'
-      },
-      group_concat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'T'}], [{type: 'STRING', optional: true}]],
-        signature: 'group_concat([ALL] col [, separator])',
-        draggable: 'group_concat()',
-        description: 'An aggregate function that returns a single string representing the argument value concatenated together for each row of the result set. If the optional separator string is specified, the separator is added between each pair of concatenated values. The default separator is a comma followed by a space.'
-      },
-      max: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'max([DISTINCT | ALL] T col)',
-        draggable: 'max()',
-        description: 'An aggregate function that returns the maximum value from a set of numbers. Opposite of the MIN function. Its single argument can be numeric column, or the numeric result of a function or expression applied to the column value. Rows with a NULL value for the specified column are ignored. If the table is empty, or all the values supplied to MAX are NULL, MAX returns NULL.'
-      },
-      min: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'min([DISTINCT | ALL] T col)',
-        draggable: 'min()',
-        description: 'An aggregate function that returns the minimum value from a set of numbers. Opposite of the MAX function. Its single argument can be numeric column, or the numeric result of a function or expression applied to the column value. Rows with a NULL value for the specified column are ignored. If the table is empty, or all the values supplied to MIN are NULL, MIN returns NULL.'
-      },
-      ndv: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'ndv([DISTINCT | ALL] col)',
-        draggable: 'ndv()',
-        description: 'An aggregate function that returns an approximate value similar to the result of COUNT(DISTINCT col), the "number of distinct values". It is much faster than the combination of COUNT and DISTINCT, and uses a constant amount of memory and thus is less memory-intensive for columns with high cardinality.'
-      },
-      stddev: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'stddev([DISTINCT | ALL] col)',
-        draggable: 'stddev()',
-        description: 'Returns the standard deviation of a numeric column in the group.'
-      },
-      stddev_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'stddev_pop([DISTINCT | ALL] col)',
-        draggable: 'stddev_pop()',
-        description: 'Returns the population standard deviation of a numeric column in the group.'
-      },
-      stddev_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'stddev_samp([DISTINCT | ALL] col)',
-        draggable: 'stddev_samp()',
-        description: 'Returns the unbiased sample standard deviation of a numeric column in the group.'
-      },
-      sum: {
-        returnTypes: ['BIGINT', 'DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'sum([DISTINCT | ALL] col)',
-        draggable: 'sum()',
-        description: 'An aggregate function that returns the sum of a set of numbers. Its single argument can be numeric column, or the numeric result of a function or expression applied to the column value. Rows with a NULL value for the specified column are ignored. If the table is empty, or all the values supplied to MIN are NULL, SUM returns NULL.'
-      },
-      variance: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'variance([DISTINCT | ALL] col)',
-				draggable: 'variance()',
-        description: 'An aggregate function that returns the variance of a set of numbers. This is a mathematical property that signifies how far the values spread apart from the mean. The return value can be zero (if the input is a single value, or a set of identical values), or a positive number otherwise.'
-      },
-      variance_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'variance_pop([DISTINCT | ALL] col)',
-				draggable: 'variance_pop()',
-        description: 'An aggregate function that returns the population variance of a set of numbers. This is a mathematical property that signifies how far the values spread apart from the mean. The return value can be zero (if the input is a single value, or a set of identical values), or a positive number otherwise.'
-      },
-      variance_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'variance_samp([DISTINCT | ALL] col)',
-				draggable: 'variance_samp()',
-        description: 'An aggregate function that returns the sample variance of a set of numbers. This is a mathematical property that signifies how far the values spread apart from the mean. The return value can be zero (if the input is a single value, or a set of identical values), or a positive number otherwise.'
-      },
-      var_pop: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'var_pop(col)',
-				draggable: 'var_pop()',
-        description: 'Returns the variance of a numeric column in the group.'
-      },
-      var_samp: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'T'}]],
-        signature: 'var_samp(col)',
-				draggable: 'var_samp()',
-        description: 'Returns the unbiased sample variance of a numeric column in the group.'
-      }
-    }
-  };
-
-  var COLLECTION_FUNCTIONS = {
-    hive: {
-      array_contains: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'ARRAY'}], [{type: 'T'}]],
-        signature: 'array_contains(Array<T> a, val)',
-				draggable: 'array_contains()',
-        description: 'Returns TRUE if the array contains value.'
-      },
-      map_keys: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'MAP'}]],
-        signature: 'array<K.V> map_keys(Map<K.V> a)',
-				draggable: 'array<K.V> map_keys()',
-        description: 'Returns an unordered array containing the keys of the input map.'
-      },
-      map_values: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'MAP'}]],
-        signature: 'array<K.V> map_values(Map<K.V> a)',
-				draggable: 'array<K.V> map_values()',
-        description: 'Returns an unordered array containing the values of the input map.'
-      },
-      size: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'ARRAY'}, {type: 'MAP'}]],
-        signature: 'size(Map<K.V>|Array<T> a)',
-				draggable: 'size()',
-        description: 'Returns the number of elements in the map or array type.'
-      },
-      sort_array: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'ARRAY'}]],
-        signature: 'sort_array(Array<T> a)',
-				draggable: 'sort_array()',
-        description: 'Sorts the input array in ascending order according to the natural ordering of the array elements and returns it.'
-      }
-    },
-    impala: {}
-  };
-
-  var TYPE_CONVERSION_FUNCTIONS = {
-    hive: {
-      binary: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'BINARY'}, {type: 'STRING'}]],
-        signature: 'binary(BINARY|STRING a)',
-				draggable: 'binary()',
-        description: 'Casts the parameter into a binary.'
-      },
-      cast: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'cast(a as T)',
-				draggable: 'cast()',
-        description: 'Converts the results of the expression expr to type T. For example, cast(\'1\' as BIGINT) will convert the string \'1\' to its integral representation. A null is returned if the conversion does not succeed. If cast(expr as boolean) Hive returns true for a non-empty string.'
-      }
-    },
-    impala: {
-      cast: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }]],
-        signature: 'cast(a as T)',
-				draggable: 'cast()',
-        description: 'Converts the results of the expression expr to type T. For example, cast(\'1\' as BIGINT) will convert the string \'1\' to its integral representation. A null is returned if the conversion does not succeed. If cast(expr as boolean) Hive returns true for a non-empty string.'
-      },
-      typeof: {
-        returnTypes: ['STRING'],
-        arguments: [[{ type: 'T' }]],
-        signature: 'typeof(T a)',
-        draggable: 'typeof()',
-        description: 'Returns the name of the data type corresponding to an expression. For types with extra attributes, such as length for CHAR and VARCHAR, or precision and scale for DECIMAL, includes the full specification of the type.'
-      }
-    }
-  };
-
-  var DATE_FUNCTIONS = {
-    hive: {
-      add_months: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}, {type: 'TIMESTAMP'}], [{type: 'INT'}]],
-        signature: 'add_months(DATE|STRING|TIMESTAMP start_date, INT num_months)',
-				draggable: 'add_months()',
-        description: 'Returns the date that is num_months after start_date (as of Hive 1.1.0). start_date is a string, date or timestamp. num_months is an integer. The time part of start_date is ignored. If start_date is the last day of the month or if the resulting month has fewer days than the day component of start_date, then the result is the last day of the resulting month. Otherwise, the result has the same day component as start_date.'
-      },
-      current_date: {
-        returnTypes: ['DATE'],
-        arguments: [],
-        signature: 'current_date',
-        draggable: 'current_date',
-        description: 'Returns the current date at the start of query evaluation (as of Hive 1.2.0). All calls of current_date within the same query return the same value.'
-      },
-      current_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [],
-        signature: 'current_timestamp()',
-				draggable: 'current_timestamp()',
-        description: 'Returns the current timestamp at the start of query evaluation (as of Hive 1.2.0). All calls of current_timestamp within the same query return the same value.'
-      },
-      datediff: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'datediff(STRING enddate, STRING startdate)',
-				draggable: 'datediff()',
-        description: 'Returns the number of days from startdate to enddate: datediff(\'2009-03-01\', \'2009-02-27\') = 2.'
-      },
-      date_add: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'date_add(DATE startdate, INT days)',
-				draggable: 'date_add()',
-        description: 'Adds a number of days to startdate: date_add(\'2008-12-31\', 1) = \'2009-01-01\'. T = pre 2.1.0: STRING, 2.1.0 on: DATE'
-      },
-      date_format: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}, {type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'date_format(DATE|TIMESTAMP|STRING ts, STRING fmt)',
-				draggable: 'date_format()',
-        description: 'Converts a date/timestamp/string to a value of string in the format specified by the date format fmt (as of Hive 1.2.0). Supported formats are Java SimpleDateFormat formats – https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html. The second argument fmt should be constant. Example: date_format(\'2015-04-08\', \'y\') = \'2015\'.'
-      },
-      date_sub: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'date_sub(DATE startdate, INT days)',
-				draggable: 'date_sub()',
-        description: 'Subtracts a number of days to startdate: date_sub(\'2008-12-31\', 1) = \'2008-12-30\'. T = pre 2.1.0: STRING, 2.1.0 on: DATE'
-      },
-      day: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'day(STRING date)',
-				draggable: 'day()',
-        description: 'Returns the day part of a date or a timestamp string: day(\'1970-11-01 00:00:00\') = 1, day(\'1970-11-01\') = 1.'
-      },
-      dayofmonth: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'dayofmonth(STRING date)',
-				draggable: 'dayofmonth()',
-        description: 'Returns the day part of a date or a timestamp string: dayofmonth(\'1970-11-01 00:00:00\') = 1, dayofmonth(\'1970-11-01\') = 1.'
-      },
-      extract: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'extract(field FROM source)',
-        draggable: 'extract()',
-        description: 'Retrieve fields such as days or hours from source (as of Hive 2.2.0). Source must be a date, timestamp, interval or a string that can be converted into either a date or timestamp. Supported fields include: day, dayofweek, hour, minute, month, quarter, second, week and year.'
-      },
-      from_unixtime: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'BIGINT'}], [{type: 'STRING', optional: true}]],
-        signature: 'from_unixtime(BIGINT unixtime [, STRING format])',
-				draggable: 'from_unixtime()',
-        description: 'Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale, return 0 if fail: unix_timestamp(\'2009-03-20 11:30:01\') = 1237573801'
-      },
-      from_utc_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'T'}], [{type: 'STRING'}]],
-        signature: 'from_utc_timestamp(T a, STRING timezone)',
-				draggable: 'from_utc_timestamp()',
-        description: 'Assumes given timestamp is UTC and converts to given timezone (as of Hive 0.8.0). For example, from_utc_timestamp(\'1970-01-01 08:00:00\',\'PST\') returns 1970-01-01 00:00:00'
-      },
-      hour: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'hour(STRING date)',
-				draggable: 'hour()',
-        description: 'Returns the hour of the timestamp: hour(\'2009-07-30 12:58:59\') = 12, hour(\'12:58:59\') = 12.'
-      },
-      last_day: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'last_day(STRING date)',
-				draggable: 'last_day()',
-        description: 'Returns the last day of the month which the date belongs to (as of Hive 1.1.0). date is a string in the format \'yyyy-MM-dd HH:mm:ss\' or \'yyyy-MM-dd\'. The time part of date is ignored.'
-      },
-      minute: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'minute(STRING date)',
-				draggable: 'minute()',
-        description: 'Returns the minute of the timestamp.'
-      },
-      month: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'month(STRING date)',
-				draggable: 'month()',
-        description: 'Returns the month part of a date or a timestamp string: month(\'1970-11-01 00:00:00\') = 11, month(\'1970-11-01\') = 11.'
-      },
-      months_between: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}, {type: 'TIMESTAMP'}], [{type: 'DATE'}, {type: 'STRING'}, {type: 'TIMESTAMP'}]],
-        signature: 'months_between(DATE|TIMESTAMP|STRING date1, DATE|TIMESTAMP|STRING date2)',
-				draggable: 'months_between()',
-        description: 'Returns number of months between dates date1 and date2 (as of Hive 1.2.0). If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise the UDF calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2. date1 and date2 type can be date, timestamp or string in the format \'yyyy-MM-dd\' or \'yyyy-MM-dd HH:mm:ss\'. The result is rounded to 8 decimal places. Example: months_between(\'1997-02-28 10:30:00\', \'1996-10-30\') = 3.94959677'
-      },
-      next_day: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'next_day(STRING start_date, STRING day_of_week)',
-				draggable: 'next_day()',
-        description: 'Returns the first date which is later than start_date and named as day_of_week (as of Hive 1.2.0). start_date is a string/date/timestamp. day_of_week is 2 letters, 3 letters or full name of the day of the week (e.g. Mo, tue, FRIDAY). The time part of start_date is ignored. Example: next_day(\'2015-01-14\', \'TU\') = 2015-01-20.'
-      },
-      quarter: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'DATE'}, {type: 'STRING'}, {type: 'TIMESTAMP'}]],
-        signature: 'quarter(DATE|TIMESTAMP|STRING a)',
-        draggable: 'quarter()',
-        description: 'Returns the quarter of the year for a date, timestamp, or string in the range 1 to 4. Example: quarter(\'2015-04-08\') = 2.'
-      },
-      second: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'second(STRING date)',
-				draggable: 'second()',
-        description: 'Returns the second of the timestamp.'
-      },
-      to_date: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'to_date(STRING timestamp)',
-				draggable: 'to_date()',
-        description: 'Returns the date part of a timestamp string, example to_date(\'1970-01-01 00:00:00\'). T = pre 2.1.0: STRING 2.1.0 on: DATE'
-      },
-      to_utc_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'T'}], [{type: 'STRING'}]],
-        signature: 'to_utc_timestamp(T a, STRING timezone)',
-				draggable: 'to_utc_timestamp()',
-        description: 'Assumes given timestamp is in given timezone and converts to UTC (as of Hive 0.8.0). For example, to_utc_timestamp(\'1970-01-01 00:00:00\',\'PST\') returns 1970-01-01 08:00:00.'
-      },
-      trunc: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'trunc(STRING date, STRING format)',
-				draggable: 'trunc()',
-        description: 'Returns date truncated to the unit specified by the format (as of Hive 1.2.0). Supported formats: MONTH/MON/MM, YEAR/YYYY/YY. Example: trunc(\'2015-03-17\', \'MM\') = 2015-03-01.'
-      },
-      unix_timestamp: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'STRING', optional: true}], [{type: 'STRING', optional: true}]],
-        signature: 'unix_timestamp([STRING date [, STRING pattern]])',
-				draggable: 'unix_timestamp()',
-        description: 'Convert time string with given pattern to Unix time stamp (in seconds), return 0 if fail: unix_timestamp(\'2009-03-20\', \'yyyy-MM-dd\') = 1237532400.'
-      },
-      weekofyear: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'weekofyear(STRING date)',
-				draggable: 'weekofyear()',
-        description: 'Returns the week number of a timestamp string: weekofyear(\'1970-11-01 00:00:00\') = 44, weekofyear(\'1970-11-01\') = 44.'
-      },
-      year: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'year(STRING date)',
-				draggable: 'year()',
-        description: 'Returns the year part of a date or a timestamp string: year(\'1970-01-01 00:00:00\') = 1970, year(\'1970-01-01\') = 1970'
-      }
-    },
-    impala: {
-      add_months: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'add_months(TIMESTAMP date, BIGINT|INT months)',
-				draggable: 'add_months()',
-        description: 'Returns the specified date and time plus some number of months.'
-      },
-      adddate: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'adddate(TIMESTAMP startdate, BIGINT|INT days)',
-				draggable: 'adddate()',
-        description: 'Adds a specified number of days to a TIMESTAMP value. Similar to date_add(), but starts with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.'
-      },
-      current_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [],
-        signature: 'current_timestamp()',
-				draggable: 'current_timestamp()',
-        description: 'Alias for the now() function.'
-      },
-      date_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'INT'}]],
-        signature: 'date_add(TIMESTAMP startdate, INT days), date_add(TIMESTAMP startdate, interval_expression)',
-        draggable: 'date_add()',
-        description: 'Adds a specified number of days to a TIMESTAMP value. The first argument can be a string, which is automatically cast to TIMESTAMP if it uses the recognized format. With an INTERVAL expression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on.'
-      },
-      date_part: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'STRING'}], [{type: 'TIMESTAMP'}]],
-        signature: 'date_part(STRING unit, TIMESTAMP timestamp)',
-				draggable: 'date_part()',
-        description: 'Similar to EXTRACT(), with the argument order reversed. Supports the same date and time units as EXTRACT(). For compatibility with SQL code containing vendor extensions.'
-      },
-      date_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'INT'}]],
-        signature: 'date_sub(TIMESTAMP startdate, INT days), date_sub(TIMESTAMP startdate, interval_expression)',
-        draggable: 'date_sub()',
-        description: 'Subtracts a specified number of days from a TIMESTAMP value. The first argument can be a string, which is automatically cast to TIMESTAMP if it uses the recognized format. With an INTERVAL expression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on.'
-      },
-      date_trunc: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'STRING'}], [{type: 'TIMESTAMP'}]],
-        signature: 'date_trunc(STRING unit, TIMESTAMP timestamp)',
-        draggable: 'date_trunc()',
-        description: 'Truncates a TIMESTAMP value to the specified precision. The unit argument value for truncating TIMESTAMP values is not case-sensitive. This argument string can be one of: \'microseconds\', \'milliseconds\', \'second\', \'minute\', \'hour\', \'day\', \'week\', \'month\', \'year\', \'decade\', \'century\' or \'millennium\'.'
-      },
-      datediff: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'TIMESTAMP'}]],
-        signature: 'datediff(TIMESTAMP enddate, TIMESTAMP startdate)',
-				draggable: 'datediff()',
-        description: 'Returns the number of days between two TIMESTAMP values.'
-      },
-      day: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'day(TIMESTAMP date)',
-				draggable: 'day()',
-        description: 'Returns the day field from the date portion of a TIMESTAMP. The value represents the day of the month, therefore is in the range 1-31, or less for months without 31 days.'
-      },
-      dayname: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'dayname(TIMESTAMP date)',
-				draggable: 'dayname()',
-        description: 'Returns the day field from a TIMESTAMP value, converted to the string corresponding to that day name. The range of return values is \'Sunday\' to \'Saturday\'. Used in report-generating queries, as an alternative to calling dayofweek() and turning that numeric return value into a string using a CASE expression.'
-      },
-      dayofmonth: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'dayofmonth(TIMESTAMP date)',
-				draggable: 'dayofmonth()',
-        description: 'Returns the day field from the date portion of a TIMESTAMP. The value represents the day of the month, therefore is in the range 1-31, or less for months without 31 days.'
-      },
-      dayofweek: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'dayofweek(TIMESTAMP date)',
-				draggable: 'dayofweek()',
-        description: 'Returns the day field from the date portion of a TIMESTAMP, corresponding to the day of the week. The range of return values is 1 (Sunday) to 7 (Saturday).'
-      },
-      dayofyear: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'dayofyear(TIMESTAMP date)',
-				draggable: 'dayofyear()',
-        description: 'Returns the day field from a TIMESTAMP value, corresponding to the day of the year. The range of return values is 1 (January 1) to 366 (December 31 of a leap year).'
-      },
-      days_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'days_add(TIMESTAMP startdate, BIGINT|INT days)',
-				draggable: 'days_add()',
-        description: 'Adds a specified number of days to a TIMESTAMP value. Similar to date_add(), but starts with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.'
-      },
-      days_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'days_sub(TIMESTAMP startdate, BIGINT|INT days)',
-				draggable: 'days_sub()',
-        description: 'Subtracts a specified number of days from a TIMESTAMP value. Similar to date_sub(), but starts with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.'
-      },
-      extract: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'extract(TIMESTAMP date, STRING unit), extract(STRING unit FROM TIMESTAMP date)',
-        draggable: 'extract()',
-        description: 'Returns one of the numeric date or time fields from a TIMESTAMP value.'
-      },
-      from_timestamp: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'from_timestamp(TIMESTAMP val, STRING format)',
-        draggable: 'from_timestamp()',
-        description: 'Converts a specified timestamp to a string with the given format. Example: from_timestamp(cast(\'1999-01-01 10:10:10\' as timestamp), \'yyyy-MM-dd\')" results in "1999-01-01"'
-      },
-      from_unixtime: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}], [{type: 'STRING', optional: true}]],
-        signature: 'from_unixtime(BIGINT unixtime [, STRING format])',
-				draggable: 'from_unixtime()',
-        description: 'Converts the number of seconds from the Unix epoch to the specified time into a string in the local time zone.'
-      },
-      from_utc_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'from_utc_timestamp(TIMESTAMP date, STRING timezone)',
-				draggable: 'from_utc_timestamp()',
-        description: 'Converts a specified UTC timestamp value into the appropriate value for a specified time zone.'
-      },
-      hour: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'hour(TIMESTAMP date)',
-				draggable: 'hour()',
-        description: 'Returns the hour field from a TIMESTAMP field.'
-      },
-      hours_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'hours_add(TIMESTAMP date, BIGINT|INT hours)',
-				draggable: 'hours_add()',
-        description: 'Returns the specified date and time plus some number of hours.'
-      },
-      hours_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'hours_sub(TIMESTAMP date, BIGINT|INT hours)',
-				draggable: 'hours_sub()',
-        description: 'Returns the specified date and time minus some number of hours.'
-      },
-      int_months_between: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'TIMESTAMP'}]],
-        signature: 'int_months_between(TIMESTAMP newer, TIMESTAMP older)',
-        draggable: 'int_months_between()',
-        description: 'Returns the number of months between the date portions of two TIMESTAMP values, as an INT representing only the full months that passed.'
-      },
-      last_day: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'last_day(TIMESTAMP t)',
-        draggable: 'last_day()',
-        description: 'Returns a TIMESTAMP corresponding to the beginning of the last calendar day in the same month as the TIMESTAMP argument.'
-      },
-      microseconds_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'microseconds_add(TIMESTAMP date, BIGINT|INT microseconds)',
-				draggable: 'microseconds_add()',
-        description: 'Returns the specified date and time plus some number of microseconds.'
-      },
-      microseconds_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'microseconds_sub(TIMESTAMP date, BIGINT|INT microseconds)',
-				draggable: 'microseconds_sub()',
-        description: 'Returns the specified date and time minus some number of microseconds.'
-      },
-      millisecond: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'millisecond(TIMESTAMP date)',
-        draggable: 'millisecond()',
-        description: 'Returns the millisecond portion of a TIMESTAMP value.'
-      },
-      milliseconds_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'milliseconds_add(TIMESTAMP date, BIGINT|INT milliseconds)',
-				draggable: 'milliseconds_add()',
-        description: 'Returns the specified date and time plus some number of milliseconds.'
-      },
-      milliseconds_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'milliseconds_sub(TIMESTAMP date, BIGINT|INT milliseconds)',
-				draggable: 'milliseconds_sub()',
-        description: 'Returns the specified date and time minus some number of milliseconds.'
-      },
-      minute: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'minute(TIMESTAMP date)',
-				draggable: 'minute()',
-        description: 'Returns the minute field from a TIMESTAMP value.'
-      },
-      minutes_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'minutes_add(TIMESTAMP date, BIGINT|INT minutes)',
-				draggable: 'minutes_add()',
-        description: 'Returns the specified date and time plus some number of minutes.'
-      },
-      minutes_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'minutes_sub(TIMESTAMP date, BIGINT|INT minutes)',
-				draggable: 'minutes_sub()',
-        description: 'Returns the specified date and time minus some number of minutes.'
-      },
-      month: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'month(TIMESTAMP date)',
-				draggable: 'month()',
-        description: 'Returns the month field, represented as an integer, from the date portion of a TIMESTAMP.'
-      },
-      monthname: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'monthname(TIMESTAMP date)',
-        draggable: 'monthname()',
-        description: 'Returns the month field from TIMESTAMP value, converted to the string corresponding to that month name.'
-      },
-      months_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'months_add(TIMESTAMP date, BIGINT|INT months)',
-				draggable: 'months_add()',
-        description: 'Returns the specified date and time plus some number of months.'
-      },
-      months_between: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'TIMESTAMP'}]],
-        signature: 'months_between(TIMESTAMP newer, TIMESTAMP older)',
-        draggable: 'months_between()',
-        description: 'Returns the number of months between the date portions of two TIMESTAMP values. Can include a fractional part representing extra days in addition to the full months between the dates. The fractional component is computed by dividing the difference in days by 31 (regardless of the month).'
-      },
-      months_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'months_sub(TIMESTAMP date, BIGINT|INT months)',
-				draggable: 'months_sub()',
-        description: 'Returns the specified date and time minus some number of months.'
-      },
-      nanoseconds_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'nanoseconds_add(TIMESTAMP date, BIGINT|INT nanoseconds)',
-				draggable: 'nanoseconds_add()',
-        description: 'Returns the specified date and time plus some number of nanoseconds.'
-      },
-      nanoseconds_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'nanoseconds_sub(TIMESTAMP date, BIGINT|INT nanoseconds)',
-				draggable: 'nanoseconds_sub()',
-        description: 'Returns the specified date and time minus some number of nanoseconds.'
-      },
-      next_day: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'next_day(TIMESTAMP date, STRING weekday)',
-        draggable: 'next_day()',
-        description: 'Returns the date of the weekday that follows the specified date. The weekday parameter is case-insensitive. The following values are accepted for weekday: "Sunday"/"Sun", "Monday"/"Mon", "Tuesday"/"Tue", "Wednesday"/"Wed", "Thursday"/"Thu", "Friday"/"Fri", "Saturday"/"Sat".'
-      },
-      now: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [],
-        signature: 'now()',
-				draggable: 'now()',
-        description: 'Returns the current date and time (in the local time zone) as a timestamp value.'
-      },
-      quarter: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'quarter(TIMESTAMP date)',
-        draggable: 'quarter()',
-        description: 'Returns the quarter in the input TIMESTAMP expression as an integer value, 1, 2, 3, or 4, where 1 represents January 1 through March 31.'
-      },
-      second: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'second(TIMESTAMP date)',
-				draggable: 'second()',
-        description: 'Returns the second field from a TIMESTAMP value.'
-      },
-      seconds_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'seconds_add(TIMESTAMP date, BIGINT|INT seconds)',
-				draggable: 'seconds_add()',
-        description: 'Returns the specified date and time plus some number of seconds.'
-      },
-      seconds_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'seconds_sub(TIMESTAMP date, BIGINT|INT seconds)',
-				draggable: 'seconds_sub()',
-        description: 'Returns the specified date and time minus some number of seconds.'
-      },
-      subdate: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'subdate(TIMESTAMP startdate, BIGINT|INT days)',
-				draggable: 'subdate()',
-        description: 'Subtracts a specified number of days from a TIMESTAMP value. Similar to date_sub(), but starts with an actual TIMESTAMP value instead of a string that is converted to a TIMESTAMP.'
-      },
-      timeofday: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'timeofday()',
-        draggable: 'timeofday()',
-        description: 'Returns a string representation of the current date and time, according to the time of the local system, including any time zone designation.'
-      },
-      timestamp_cmp: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'TIMESTAMP'}]],
-        signature: 'timestamp_cmp(TIMESTAMP t1, TIMESTAMP t2)',
-        draggable: 'timestamp_cmp()',
-        description: 'Tests if one TIMESTAMP value is newer than, older than, or identical to another TIMESTAMP. Returns either -1, 0, 1 or NULL.'
-      },
-      to_date: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'to_date(TIMESTAMP date)',
-				draggable: 'to_date()',
-        description: 'Returns a string representation of the date field from a timestamp value.'
-      },
-      to_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        altArguments: [[{type: 'BIGINT'}]],
-        signature: 'to_timestamp([STRING val, STRING format]|[BIGINT val])',
-        draggable: 'to_timestamp()',
-        description: 'Converts a bigint (delta from the Unix epoch) or a string with the specified format to a timestamp. Example: to_timestamp(\'1970-01-01 00:00:00\', \'yyyy-MM-dd HH:mm:ss\').'
-      },
-      to_utc_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'to_utc_timestamp(TIMESTAMP date, STRING timezone)',
-				draggable: 'to_utc_timestamp()',
-        description: 'Converts a specified timestamp value in a specified time zone into the corresponding value for the UTC time zone.'
-      },
-      trunc: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'STRING'}]],
-        signature: 'trunc(TIMESTAMP date, STRING unit)',
-				draggable: 'trunc()',
-        description: 'Strips off fields and optionally rounds a TIMESTAMP value. The unit argument value is case-sensitive. This argument string can be one of: SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y: Year. Q: Quarter. MONTH, MON, MM, RM: Month. WW, W: Same day of the week as the first day of the month. DDD, DD, J: Day. DAY, DY, D: Starting day of the week. (Not necessarily the current day.) HH, HH12, HH24: Hour. A TIMESTAMP value truncated to the hour is always represented in 24-hour notation, even for the HH12 argument string. MI: Minute.'
-      },
-      unix_timestamp: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING', optional: true}], [{type: 'STRING', optional: true}]],
-        altArguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'unix_timestamp([STRING datetime [, STRING format]]|[TIMESTAMP datetime])',
-				draggable: 'unix_timestamp()',
-        description: 'Returns an integer value representing the current date and time as a delta from the Unix epoch, or converts from a specified date and time value represented as a TIMESTAMP or STRING.'
-      },
-      utc_timestamp: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [],
-        signature: 'utc_timestamp()',
-        draggable: 'utc_timestamp()',
-        description: 'Returns a TIMESTAMP corresponding to the current date and time in the UTC time zone.'
-      },
-      weekofyear: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'weekofyear(TIMESTAMP date)',
-				draggable: 'weekofyear()',
-        description: 'Returns the corresponding week (1-53) from the date portion of a TIMESTAMP.'
-      },
-      weeks_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'weeks_add(TIMESTAMP date, BIGINT|INT weeks)',
-				draggable: 'weeks_add()',
-        description: 'Returns the specified date and time plus some number of weeks.'
-      },
-      weeks_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'weeks_sub(TIMESTAMP date, BIGINT|INT weeks)',
-				draggable: 'weeks_sub()',
-        description: 'Returns the specified date and time minus some number of weeks.'
-      },
-      year: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'TIMESTAMP'}]],
-        signature: 'year(TIMESTAMP date)',
-				draggable: 'year()',
-        description: 'Returns the year field from the date portion of a TIMESTAMP.'
-      },
-      years_add: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'years_add(TIMESTAMP date, BIGINT|INT years)',
-				draggable: 'years_add()',
-        description: 'Returns the specified date and time plus some number of years.'
-      },
-      years_sub: {
-        returnTypes: ['TIMESTAMP'],
-        arguments: [[{type: 'TIMESTAMP'}], [{type: 'BIGINT'}, {type: 'INT'}]],
-        signature: 'years_sub(TIMESTAMP date, BIGINT|INT years)',
-				draggable: 'years_sub()',
-        description: 'Returns the specified date and time minus some number of years.'
-      }
-    }
-  };
-
-  var CONDITIONAL_FUNCTIONS = {
-    hive: {
-      assert_true: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BOOLEAN'}]],
-        signature: 'assert_true(BOOLEAN condition)',
-        draggable: 'assert_true()',
-        description: 'Throw an exception if \'condition\' is not true, otherwise return null (as of Hive 0.8.0). For example, select assert_true (2<1).'
-      },
-      coalesce: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'coalesce(T v1, T v2, ...)',
-				draggable: 'coalesce()',
-        description: 'Returns the first v that is not NULL, or NULL if all v\'s are NULL.'
-      },
-      if: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BOOLEAN'}], [{type: 'T'}], [{type: 'T'}]],
-        signature: 'if(BOOLEAN testCondition, T valueTrue, T valueFalseOrNull)',
-				draggable: 'if()',
-        description: 'Returns valueTrue when testCondition is true, returns valueFalseOrNull otherwise.'
-      },
-      isnotnull: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'T'}]],
-        signature: 'isnotnull(a)',
-				draggable: 'isnotnull()',
-        description: 'Returns true if a is not NULL and false otherwise.'
-      },
-      isnull: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'T'}]],
-        signature: 'isnull(a)',
-				draggable: 'isnull()',
-        description: 'Returns true if a is NULL and false otherwise.'
-      },
-      nullif: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'nullif(a, b)',
-        draggable: 'nullif()',
-        description: 'Returns NULL if a=b; otherwise returns a (as of Hive 2.2.0).'
-      },
-      nvl: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'nvl(T value, T default_value)',
-				draggable: 'nvl()',
-        description: 'Returns default value if value is null else returns value (as of Hive 0.11).'
-      }
-    },
-    impala: {
-      coalesce: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'coalesce(T v1, T v2, ...)',
-				draggable: 'coalesce()',
-        description: 'Returns the first specified argument that is not NULL, or NULL if all arguments are NULL.'
-      },
-      decode: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}], [{type: 'T', multiple: true}]],
-        signature: 'decode(T expression, T search1, T result1 [, T search2, T result2 ...] [, T default] )',
-				draggable: 'decode()',
-        description: 'Compares an expression to one or more possible values, and returns a corresponding result when a match is found.'
-      },
-      if: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'BOOLEAN'}], [{type: 'T'}], [{type: 'T'}]],
-        signature: 'if(BOOLEAN condition, T ifTrue, T ifFalseOrNull)',
-				draggable: 'if()',
-        description: 'Tests an expression and returns a corresponding result depending on whether the result is true, false, or NULL.'
-      },
-      ifnull: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'ifnull(T a, T ifNotNull)',
-				draggable: 'ifnull()',
-        description: 'Alias for the isnull() function, with the same behavior. To simplify porting SQL with vendor extensions to Impala.'
-      },
-      isfalse: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'BOOLEAN'}]],
-        signature: 'isfalse(BOOLEAN condition)',
-        draggable: 'isfalse()',
-        description: 'Tests if a Boolean expression is false or not. Returns true if so. If the argument is NULL, returns false. Identical to isnottrue(), except it returns the opposite value for a NULL argument.'
-      },
-      isnotfalse: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'BOOLEAN'}]],
-        signature: 'isnotfalse(BOOLEAN condition)',
-        draggable: 'isnotfalse()',
-        description: 'Tests if a Boolean expression is not false (that is, either true or NULL). Returns true if so. If the argument is NULL, returns true. Identical to istrue(), except it returns the opposite value for a NULL argument.'
-      },
-      isnottrue: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'BOOLEAN'}]],
-        signature: 'isnottrue(BOOLEAN condition)',
-        draggable: 'isnottrue()',
-        description: 'Tests if a Boolean expression is not true (that is, either false or NULL). Returns true if so. If the argument is NULL, returns true. Identical to isfalse(), except it returns the opposite value for a NULL argument.'
-      },
-      isnull: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'isnull(T a, T ifNotNull)',
-				draggable: 'isnull()',
-        description: 'Tests if an expression is NULL, and returns the expression result value if not. If the first argument is NULL, returns the second argument.'
-      },
-      istrue: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'BOOLEAN'}]],
-        signature: 'istrue(BOOLEAN condition)',
-        draggable: 'istrue()',
-        description: 'Tests if a Boolean expression is true or not. Returns true if so. If the argument is NULL, returns false. Identical to isnotfalse(), except it returns the opposite value for a NULL argument.'
-      },
-      nonnullvalue: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'T'}]],
-        signature: 'nonnullvalue(T expression)',
-        draggable: 'nonnullvalue()',
-        description: 'Tests if an expression (of any type) is NULL or not. Returns false if so. The converse of nullvalue().'
-      },
-      nullif: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'nullif(T expr1, T expr2)',
-				draggable: 'nullif()',
-        description: 'Returns NULL if the two specified arguments are equal. If the specified arguments are not equal, returns the value of expr1. The data types of the expressions must be compatible. You cannot use an expression that evaluates to NULL for expr1; that way, you can distinguish a return value of NULL from an argument value of NULL, which would never match expr2.'
-      },
-      nullifzero: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'NUMBER'}]],
-        signature: 'nullifzero(T numeric_expr)',
-				draggable: 'nullifzero()',
-        description: 'Returns NULL if the numeric expression evaluates to 0, otherwise returns the result of the expression.'
-      },
-      nullvalue: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'T'}]],
-        signature: 'nullvalue(T expression)',
-        draggable: 'nullvalue()',
-        description: 'Tests if an expression (of any type) is NULL or not. Returns true if so. The converse of nonnullvalue().'
-      },
-      nvl: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}]],
-        signature: 'nvl(T a, T ifNotNull)',
-				draggable: 'nvl()',
-        description: 'Alias for the isnull() function. Tests if an expression is NULL, and returns the expression result value if not. If the first argument is NULL, returns the second argument. Equivalent to the nvl() function from Oracle Database or ifnull() from MySQL.'
-      },
-      nvl2: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'T'}], [{type: 'T'}]],
-        signature: 'nvl2(T a, T ifNull, T ifNotNull)',
-        draggable: 'nvl2()',
-        description: 'Enhanced variant of the nvl() function. Tests an expression and returns different result values depending on whether it is NULL or not. If the first argument is NULL, returns the second argument. If the first argument is not NULL, returns the third argument. Equivalent to the nvl2() function from Oracle.'
-      },
-      zeroifnull: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'NUMBER'}]],
-        signature: 'zeroifnull(T numeric_expr)',
-				draggable: 'zeroifnull()',
-        description: 'Returns 0 if the numeric expression evaluates to NULL, otherwise returns the result of the expression.'
-      }
-    }
-  };
-
-  var STRING_FUNCTIONS = {
-    hive: {
-      ascii: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'ascii(STRING str)',
-				draggable: 'ascii()',
-        description: 'Returns the numeric value of the first character of str.'
-      },
-      base64: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BINARY'}]],
-        signature: 'base64(BINARY bin)',
-				draggable: 'base64()',
-        description: 'Converts the argument from binary to a base 64 string (as of Hive 0.12.0).'
-      },
-      chr: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BIGINT'}, {type: 'DOUBLE'}]],
-        signature: 'chr(BIGINT|DOUBLE a)',
-        draggable: 'chr()',
-        description: 'Returns the ASCII character having the binary equivalent to a (as of Hive 1.3.0 and 2.1.0). If a is larger than 256 the result is equivalent to chr(a % 256). Example: select chr(88); returns "X".'
-      },
-      char_length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'char_length(STRING a)',
-        draggable: 'char_length()',
-        description: 'Returns the number of UTF-8 characters contained in str (as of Hive 2.2.0). This is shorthand for character_length.'
-      },
-      character_length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'character_length(STRING a)',
-        draggable: 'character_length()',
-        description: 'Returns the number of UTF-8 characters contained in str (as of Hive 2.2.0). The function char_length is shorthand for this function.'
-      },
-      concat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING', multiple: true}, {type: 'BINARY', multiple: true}]],
-        signature: 'concat(STRING|BINARY a, STRING|BINARY b...)',
-				draggable: 'concat()',
-        description: 'Returns the string or bytes resulting from concatenating the strings or bytes passed in as parameters in order. For example, concat(\'foo\', \'bar\') results in \'foobar\'. Note that this function can take any number of input strings.'
-      },
-      concat_ws: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING', multiple: true}]],
-        altArguments: [[{type: 'STRING'}], [{type: 'ARRAY'}]],
-        signature: 'concat_ws(STRING sep, STRING a, STRING b...), concat_ws(STRING sep, Array<STRING>)',
-        draggable: 'concat_ws()',
-        description: 'Like concat(), but with custom separator SEP.'
-      },
-      context_ngrams: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'ARRAY'}], [{type: 'ARRAY'}], [{type: 'INT'}], [{type: 'INT'}]],
-        signature: 'array<struct<STRING,DOUBLE>> context_ngrams(Array<Array<STRING>>, Array<STRING>, INT k, INT pf)',
-				draggable: 'array<struct<STRING,DOUBLE>> context_ngrams()',
-        description: 'Returns the top-k contextual N-grams from a set of tokenized sentences, given a string of "context".'
-      },
-      decode: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'BINARY'}], [{type: 'STRING'}]],
-        signature: 'decode(BINARY bin, STRING charset)',
-				draggable: 'decode()',
-        description: 'Decodes the first argument into a String using the provided character set (one of \'US-ASCII\', \'ISO-8859-1\', \'UTF-8\', \'UTF-16BE\', \'UTF-16LE\', \'UTF-16\'). If either argument is null, the result will also be null. (As of Hive 0.12.0.)'
-      },
-      elt: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'INT'}], [{type: 'STRING' , multiple: true }]],
-        signature: 'elt(INT n, STRING str, STRING str1, ...])',
-        draggable: 'elt()',
-        description: 'Return string at index number. For example elt(2,\'hello\',\'world\') returns \'world\'. Returns NULL if N is less than 1 or greater than the number of arguments.'
-      },
-      encode: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'encode(STRING src, STRING charset)',
-				draggable: 'encode()',
-        description: 'Encodes the first argument into a BINARY using the provided character set (one of \'US-ASCII\', \'ISO-8859-1\', \'UTF-8\', \'UTF-16BE\', \'UTF-16LE\', \'UTF-16\'). If either argument is null, the result will also be null. (As of Hive 0.12.0.)'
-      },
-      field: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'T' , multiple: true }]],
-        signature: 'field(T val, T val1, ...])',
-        draggable: 'field()',
-        description: 'Returns the index of val in the val1,val2,val3,... list or 0 if not found. For example field(\'world\',\'say\',\'hello\',\'world\') returns 3. All primitive types are supported, arguments are compared using str.equals(x). If val is NULL, the return value is 0.'
-      },
-      find_in_set: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'find_in_set(STRING str, STRING strList)',
-				draggable: 'find_in_set()',
-        description: 'Returns the first occurance of str in strList where strList is a comma-delimited string. Returns null if either argument is null. Returns 0 if the first argument contains any commas. For example, find_in_set(\'ab\', \'abc,b,ab,c,def\') returns 3.'
-      },
-      format_number: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'NUMBER'}], [{type: 'INT'}]],
-        signature: 'format_number(NUMBER x, INT d)',
-				draggable: 'format_number()',
-        description: 'Formats the number X to a format like \'#,###,###.##\', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. (As of Hive 0.10.0; bug with float types fixed in Hive 0.14.0, decimal type support added in Hive 0.14.0)'
-      },
-      get_json_object: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'get_json_object(STRING json_string, STRING path)',
-				draggable: 'get_json_object()',
-        description: 'Extracts json object from a json string based on json path specified, and returns json string of the extracted json object. It will return null if the input json string is invalid. NOTE: The json path can only have the characters [0-9a-z_], i.e., no upper-case or special characters. Also, the keys *cannot start with numbers.* This is due to restrictions on Hive column names.'
-      },
-      initcap: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'initcap(STRING a)',
-				draggable: 'initcap()',
-        description: 'Returns string, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by whitespace. (As of Hive 1.1.0.)'
-      },
-      instr: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'instr(STRING str, STRING substr)',
-				draggable: 'instr()',
-        description: 'Returns the position of the first occurrence of substr in str. Returns null if either of the arguments are null and returns 0 if substr could not be found in str. Be aware that this is not zero based. The first character in str has index 1.'
-      },
-      in_file: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'in_file(STRING str, STRING filename)',
-				draggable: 'in_file()',
-        description: 'Returns true if the string str appears as an entire line in filename.'
-      },
-      length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'length(STRING a)',
-				draggable: 'length()',
-        description: 'Returns the length of the string.'
-      },
-      levenshtein: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'levenshtein(STRING a, STRING b)',
-				draggable: 'levenshtein()',
-        description: 'Returns the Levenshtein distance between two strings (as of Hive 1.2.0). For example, levenshtein(\'kitten\', \'sitting\') results in 3.'
-      },
-      lcase: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'lcase(STRING a)',
-				draggable: 'lcase()',
-        description: 'Returns the string resulting from converting all characters of B to lower case. For example, lcase(\'fOoBaR\') results in \'foobar\'.'
-      },
-      locate: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'locate(STRING substr, STRING str [, INT pos])',
-				draggable: 'locate()',
-        description: 'Returns the position of the first occurrence of substr in str after position pos.'
-      },
-      lower: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'lower(STRING a)',
-				draggable: 'lower()',
-        description: 'Returns the string resulting from converting all characters of B to lower case. For example, lower(\'fOoBaR\') results in \'foobar\'.'
-      },
-      lpad: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'STRING'}]],
-        signature: 'lpad(STRING str, INT len, STRING pad)',
-				draggable: 'lpad()',
-        description: 'Returns str, left-padded with pad to a length of len.'
-      },
-      ltrim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'ltrim(STRING a)',
-				draggable: 'ltrim()',
-        description: 'Returns the string resulting from trimming spaces from the beginning(left hand side) of A. For example, ltrim(\' foobar \') results in \'foobar \'.'
-      },
-      ngrams: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'ARRAY'}], [{type: 'INT'}], [{type: 'INT'}], [{type: 'INT'}]],
-        signature: 'array<struct<STRING, DOUBLE>> ngrams(Array<Array<STRING>> a, INT n, INT k, INT pf)',
-				draggable: 'array<struct<STRING, DOUBLE>> ngrams()',
-        description: 'Returns the top-k N-grams from a set of tokenized sentences, such as those returned by the sentences() UDAF.'
-      },
-      octet_length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'octet_length(STRING a)',
-        draggable: 'octet_length()',
-        description: 'Returns the number of octets required to hold the string str in UTF-8 encoding (since Hive 2.2.0). Note that octet_length(str) can be larger than character_length(str).'
-      },
-      parse_url: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'parse_url(STRING urlString, STRING partToExtract [, STRING keyToExtract])',
-				draggable: 'parse_url()',
-        description: 'Returns the specified part from the URL. Valid values for partToExtract include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and USERINFO. For example, parse_url(\'http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1\', \'HOST\') returns \'facebook.com\'. Also a value of a particular key in QUERY can be extracted by providing the key as the third argument, for example, parse_url(\'http://facebook.com/path1/p.php?k1=v1&k2=v2#Ref1\', \'QUERY\', \'k1\') returns \'v1\'.'
-      },
-      printf: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'T', multiple: true}]],
-        signature: 'printf(STRING format, Obj... args)',
-				draggable: 'printf()',
-        description: 'Returns the input formatted according do printf-style format strings (as of Hive 0.9.0).'
-      },
-      regexp_extract: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'regexp_extract(STRING subject, STRING pattern, INT index)',
-				draggable: 'regexp_extract()',
-        description: 'Returns the string extracted using the pattern. For example, regexp_extract(\'foothebar\', \'foo(.*?)(bar)\', 2) returns \'bar.\' Note that some care is necessary in using predefined character classes: using \'\\s\' as the second argument will match the letter s; \'\\\\s\' is necessary to match whitespace, etc. The \'index\' parameter is the Java regex Matcher group() method index.'
-      },
-      regexp_replace: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'regexp_replace(STRING initial_string, STRING pattern, STRING replacement)',
-				draggable: 'regexp_replace()',
-        description: 'Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns \'fb.\' Note that some care is necessary in using predefined character classes: using \'\\s\' as the second argument will match the letter s; \'\\\\s\' is necessary to match whitespace, etc.'
-      },
-      repeat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'repeat(STRING str, INT n)',
-				draggable: 'repeat()',
-        description: 'Repeats str n times.'
-      },
-      replace: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'replace(STRING a, STRING old, STRING new)',
-        draggable: 'replace()',
-        description: 'Returns the string a with all non-overlapping occurrences of old replaced with new (as of Hive 1.3.0 and 2.1.0). Example: select replace("ababab", "abab", "Z"); returns "Zab".'
-      },
-      reverse: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'reverse(STRING a)',
-				draggable: 'reverse()',
-        description: 'Returns the reversed string.'
-      },
-      rpad: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'STRING'}]],
-        signature: 'rpad(STRING str, INT len, STRING pad)',
-				draggable: 'rpad()',
-        description: 'Returns str, right-padded with pad to a length of len.'
-      },
-      rtrim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'rtrim(STRING a)',
-				draggable: 'rtrim()',
-        description: 'Returns the string resulting from trimming spaces from the end(right hand side) of A. For example, rtrim(\' foobar \') results in \' foobar\'.'
-      },
-      sentences: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'array<array<STRING>> sentences(STRING str, STRING lang, STRING locale)',
-				draggable: 'array<array<STRING>> sentences()',
-        description: 'Tokenizes a string of natural language text into words and sentences, where each sentence is broken at the appropriate sentence boundary and returned as an array of words. The \'lang\' and \'locale\' are optional arguments. For example, sentences(\'Hello there! How are you?\') returns ( ("Hello", "there"), ("How", "are", "you") ).'
-      },
-      soundex: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'soundex(STRING a)',
-				draggable: 'soundex()',
-        description: 'Returns soundex code of the string (as of Hive 1.2.0). For example, soundex(\'Miller\') results in M460.'
-      },
-      space: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'space(INT n)',
-				draggable: 'space()',
-        description: 'Returns a string of n spaces.'
-      },
-      split: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'array<STRING> split(STRING str, STRING pat)',
-				draggable: 'array<STRING> split()',
-        description: 'Splits str around pat (pat is a regular expression).'
-      },
-      str_to_map: {
-        returnTypes: ['MAP'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}], [{type: 'STRING', optional: true}]],
-        signature: 'map<STRING,STRING> str_to_map(STRING [, STRING delimiter1, STRING delimiter2])',
-				draggable: 'map<STRING,STRING> str_to_map()',
-        description: 'Splits text into key-value pairs using two delimiters. Delimiter1 separates text into K-V pairs, and Delimiter2 splits each K-V pair. Default delimiters are \',\' for delimiter1 and \'=\' for delimiter2.'
-      },
-      substr: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}], [{type: 'INT'}], [{type: 'INT', optional: true}]],
-        signature: 'substr(STRING|BINARY A, INT start [, INT len]) ',
-        draggable: 'substr()',
-        description: 'Returns the substring or slice of the byte array of A starting from start position till the end of string A or with optional length len. For example, substr(\'foobar\', 4) results in \'bar\''
-      },
-      substring: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}], [{type: 'INT'}], [{type: 'INT', optional: true}]],
-        signature: 'substring(STRING|BINARY a, INT start [, INT len])',
-				draggable: 'substring()',
-        description: 'Returns the substring or slice of the byte array of A starting from start position till the end of string A or with optional length len. For example, substr(\'foobar\', 4) results in \'bar\''
-      },
-      substring_index: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'substring_index(STRING a, STRING delim, INT count)',
-				draggable: 'substring_index()',
-        description: 'Returns the substring from string A before count occurrences of the delimiter delim (as of Hive 1.3.0). If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. Substring_index performs a case-sensitive match when searching for delim. Example: substring_index(\'www.apache.org\', \'.\', 2) = \'www.apache\'.'
-      },
-      translate: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'CHAR'}, {type: 'VARCHAR'}], [{type: 'STRING'}, {type: 'CHAR'}, {type: 'VARCHAR'}], [{type: 'STRING'}, {type: 'CHAR'}, {type: 'VARCHAR'}]],
-        signature: 'translate(STRING|CHAR|VARCHAR input, STRING|CHAR|VARCHAR from, STRING|CHAR|VARCHAR to)',
-				draggable: 'translate()',
-        description: 'Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string. This is similar to the translate function in PostgreSQL. If any of the parameters to this UDF are NULL, the result is NULL as well. (Available as of Hive 0.10.0, for string types) Char/varchar support added as of Hive 0.14.0.'
-      },
-      trim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'trim(STRING a)',
-				draggable: 'trim()',
-        description: 'Returns the string resulting from trimming spaces from both ends of A. For example, trim(\' foobar \') results in \'foobar\''
-      },
-      ucase: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'ucase(STRING a)',
-				draggable: 'ucase()',
-        description: 'Returns the string resulting from converting all characters of A to upper case. For example, ucase(\'fOoBaR\') results in \'FOOBAR\'.'
-      },
-      unbase64: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'unbase64(STRING a)',
-				draggable: 'unbase64()',
-        description: 'Converts the argument from a base 64 string to BINARY. (As of Hive 0.12.0.)'
-      },
-      upper: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'upper(STRING a)',
-				draggable: 'upper()',
-        description: 'Returns the string resulting from converting all characters of A to upper case. For example, upper(\'fOoBaR\') results in \'FOOBAR\'.'
-      }
-    },
-    impala: {
-      ascii: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'ascii(STRING str)',
-				draggable: 'ascii()',
-        description: 'Returns the numeric ASCII code of the first character of the argument.'
-      },
-      base64decode: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'base64decode(STRING str)',
-        draggable: 'base64decode()',
-        description: 'Decodes the given string from Base64, an ACSII string format. It\'s typically used in combination with base64encode(), to store data in an Impala table string that is problematic to store or transmit'
-      },
-      base64encode: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'base64encode(STRING str)',
-        draggable: 'base64encode()',
-        description: 'Encodes the given string to Base64, an ACSII string format. It\'s typically used in combination with base64decode(), to store data in an Impala table string that is problematic to store or transmit'
-      },
-      btrim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'btrim(STRING str [, STRING chars_to_trim])',
-        draggable: 'btrim()',
-        description: 'Removes all instances of one or more characters from the start and end of a STRING value. By default, removes only spaces. If a non-NULL optional second argument is specified, the function removes all occurrences of characters in that second argument from the beginning and end of the string.'
-      },
-      char_length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'char_length(STRING a)',
-				draggable: 'char_length()',
-        description: 'Returns the length in characters of the argument string. Aliases for the length() function.'
-      },
-      character_length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'character_length(STRING a)',
-				draggable: 'character_length()',
-        description: 'Returns the length in characters of the argument string. Aliases for the length() function.'
-      },
-      chr: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'chr(INT character_code)',
-        draggable: 'chr()',
-        description: 'Returns a character specified by a decimal code point value. The interpretation and display of the resulting character depends on your system locale. Because consistent processing of Impala string values is only guaranteed for values within the ASCII range, only use this function for values corresponding to ASCII characters. In particular, parameter values greater than 255 return an empty string.'
-      },
-      concat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', multiple: true}]],
-        signature: 'concat(STRING a, STRING b...)',
-				draggable: 'concat()',
-        description: 'Returns a single string representing all the argument values joined together.'
-      },
-      concat_ws: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING', multiple: true}]],
-        signature: 'concat_ws(STRING sep, STRING a, STRING b...)',
-				draggable: 'concat_ws()',
-        description: 'Returns a single string representing the second and following argument values joined together, delimited by a specified separator.'
-      },
-      find_in_set: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'find_in_set(STRING str, STRING strList)',
-				draggable: 'find_in_set()',
-        description: 'Returns the position (starting from 1) of the first occurrence of a specified string within a comma-separated string. Returns NULL if either argument is NULL, 0 if the search string is not found, or 0 if the search string contains a comma.'
-      },
-      group_concat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'group_concat(STRING s [, STRING sep])',
-				draggable: 'group_concat()',
-        description: 'Returns a single string representing the argument value concatenated together for each row of the result set. If the optional separator string is specified, the separator is added between each pair of concatenated values.'
-      },
-      initcap: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'initcap(STRING str)',
-				draggable: 'initcap()',
-        description: 'Returns the input string with the first letter capitalized.'
-      },
-      instr: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{ type: 'BIGINT', optional: true}], [{ type: 'BIGINT', optional: true}]],
-        signature: 'instr(STRING str, STRING substr [, BIGINT position [, BIGINT occurrence]])',
-				draggable: 'instr()',
-        description: 'Returns the position (starting from 1) of the first occurrence of a substring within a longer string. The optional third and fourth arguments let you find instances of the substring other than the first instance starting from the left.'
-      },
-      left: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'left(STRING a, INT num_chars)',
-        draggable: 'left()',
-        description: 'Returns the leftmost characters of the string. Same as strleft().'
-      },
-      length: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'length(STRING a)',
-				draggable: 'length()',
-        description: 'Returns the length in characters of the argument string.'
-      },
-      levenshtein: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'levenshtein(STRING a, STRING b)',
-        draggable: 'levenshtein()',
-        description: 'Returns the Levenshtein distance between two strings. For example, levenshtein(\'kitten\', \'sitting\') results in 3.'
-      },
-      locate: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'locate(STRING substr, STRING str[, INT pos])',
-				draggable: 'locate()',
-        description: 'Returns the position (starting from 1) of the first occurrence of a substring within a longer string, optionally after a particular position.'
-      },
-      lower: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'lower(STRING a)',
-				draggable: 'lower()',
-        description: 'Returns the argument string converted to all-lowercase.'
-      },
-      lcase: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'lcase(STRING a)',
-				draggable: 'lcase()',
-        description: 'Returns the argument string converted to all-lowercase.'
-      },
-      lpad: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'STRING'}]],
-        signature: 'lpad(STRING str, INT len, STRING pad)',
-				draggable: 'lpad()',
-        description: 'Returns a string of a specified length, based on the first argument string. If the specified string is too short, it is padded on the left with a repeating sequence of the characters from the pad string. If the specified string is too long, it is truncated on the right.'
-      },
-      ltrim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'ltrim(STRING a [, STRING charsToTrim])',
-				draggable: 'ltrim()',
-        description: 'Returns the argument string with all occurrences of characters specified by the second argument removed from the left side. Removes spaces if the second argument is not specified.'
-      },
-      parse_url: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'parse_url(STRING urlString, STRING partToExtract [, STRING keyToExtract])',
-				draggable: 'parse_url()',
-        description: 'Returns the portion of a URL corresponding to a specified part. The part argument can be \'PROTOCOL\', \'HOST\', \'PATH\', \'REF\', \'AUTHORITY\', \'FILE\', \'USERINFO\', or \'QUERY\'. Uppercase is required for these literal values. When requesting the QUERY portion of the URL, you can optionally specify a key to retrieve just the associated value from the key-value pairs in the query string.'
-      },
-      regexp_escape: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'regexp_escape(STRING source)',
-        draggable: 'regexp_escape()',
-        description: 'The regexp_escape function returns a string escaped for the special character in RE2 library so that the special characters are interpreted literally rather than as special characters. The following special characters are escaped by the function: .\\+*?[^]$(){}=!<>|:-'
-      },
-      regexp_extract: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'regexp_extract(STRING subject, STRING pattern, INT index)',
-				draggable: 'regexp_extract()',
-        description: 'Returns the specified () group from a string based on a regular expression pattern. Group 0 refers to the entire extracted string, while group 1, 2, and so on refers to the first, second, and so on (...) portion.'
-      },
-      regexp_like: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'regexp_like(STRING source, STRING pattern [, STRING options])',
-        draggable: 'regexp_like()',
-        description: 'Returns true or false to indicate whether the source string contains anywhere inside it the regular expression given by the pattern. The optional third argument consists of letter flags that change how the match is performed, such as i for case-insensitive matching.'
-      },
-      regexp_replace: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'regexp_replace(STRING initial, STRING pattern, STRING replacement)',
-				draggable: 'regexp_replace()',
-        description: 'Returns the initial argument with the regular expression pattern replaced by the final argument string.'
-      },
-      repeat: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'repeat(STRING str, INT n)',
-				draggable: 'repeat()',
-        description: 'Returns the argument string repeated a specified number of times.'
-      },
-      replace: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'replace(STRING initial, STRING target, STRING replacement)',
-        draggable: 'replace()',
-        description: 'Returns the initial argument with all occurrences of the target string replaced by the replacement string.'
-      },
-      reverse: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'reverse(STRING a)',
-				draggable: 'reverse()',
-        description: 'Returns the argument string with characters in reversed order.'
-      },
-      right: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'right(STRING a, INT num_chars)',
-        draggable: 'right()',
-        description: 'Returns the rightmost characters of the string. Same as strright().'
-      },
-      rpad: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'STRING'}]],
-        signature: 'rpad(STRING str, INT len, STRING pad)',
-				draggable: 'rpad()',
-        description: 'Returns a string of a specified length, based on the first argument string. If the specified string is too short, it is padded on the right with a repeating sequence of the characters from the pad string. If the specified string is too long, it is truncated on the right.'
-      },
-      rtrim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}]],
-        signature: 'rtrim(STRING a [, STRING charsToTrim])',
-				draggable: 'rtrim()',
-        description: 'Returns the argument string with all occurrences of characters specified by the second argument removed from the right side. Removes spaces if the second argument is not specified.'
-      },
-      space: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'space(INT n)',
-				draggable: 'space()',
-        description: 'Returns a concatenated string of the specified number of spaces. Shorthand for repeat(\' \', n).'
-      },
-      split_part: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'BIGINT'}]],
-        signature: 'split_part(STRING source, STRING delimiter, BIGINT n)',
-        draggable: 'split_part()',
-        description: 'Returns the nth field within a delimited string. The fields are numbered starting from 1. The delimiter can consist of multiple characters, not just a single character. All matching of the delimiter is done exactly, not using any regular expression patterns.'
-      },
-      strleft: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'strleft(STRING a, INT num_chars)',
-				draggable: 'strleft()',
-        description: 'Returns the leftmost characters of the string. Shorthand for a call to substr() with 2 arguments.'
-      },
-      strright: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}]],
-        signature: 'strright(STRING a, INT num_chars)',
-				draggable: 'strright()',
-        description: 'Returns the rightmost characters of the string. Shorthand for a call to substr() with 2 arguments.'
-      },
-      substr: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'INT', optional: true}]],
-        signature: 'substr(STRING a, INT start [, INT len])',
-				draggable: 'substr()',
-        description: 'Returns the portion of the string starting at a specified point, optionally with a specified maximum length. The characters in the string are indexed starting at 1.'
-      },
-      substring: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT'}], [{type: 'INT', optional: true}]],
-        signature: 'substring(STRING a, INT start [, INT len])',
-				draggable: 'substring()',
-        description: 'Returns the portion of the string starting at a specified point, optionally with a specified maximum length. The characters in the string are indexed starting at 1.'
-      },
-      translate: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'translate(STRING input, STRING from, STRING to)',
-				draggable: 'translate()',
-        description: 'Returns the input string with a set of characters replaced by another set of characters.'
-      },
-      trim: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'trim(STRING a)',
-				draggable: 'trim()',
-        description: 'Returns the input string with both leading and trailing spaces removed. The same as passing the string through both ltrim() and rtrim().'
-      },
-      upper: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'upper(STRING a)',
-				draggable: 'upper()',
-        description: 'Returns the argument string converted to all-uppercase.'
-      },
-      ucase: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}]],
-        signature: 'ucase(STRING a)',
-				draggable: 'ucase()',
-        description: 'Returns the argument string converted to all-uppercase.'
-      }
-    }
-  };
-
-  var DATA_MASKING_FUNCTIONS = {
-    hive: {
-      mask: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', optional: true}], [{type: 'STRING', optional: true}], [{type: 'STRING', optional: true}]],
-        signature: 'mask(STRING str [, STRING upper [, STRING lower [, STRING number]]])',
-        draggable: 'mask()',
-        description: 'Returns a masked version of str (as of Hive 2.1.0). By default, upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example mask("abcd-EFGH-8765-4321") results in xxxx-XXXX-nnnn-nnnn. You can override the characters used in the mask by supplying additional arguments: the second argument controls the mask character for upper case letters, the third argument for lower case letters and the fourth argument for numbers. For example, mask("abcd-EFGH-8765-4321", "U", "l", "#") results in llll-UUUU-####-####.'
-      },
-      mask_first_n: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'mask_first_n(STRING str [, INT n])',
-        draggable: 'mask_first_n()',
-        description: 'Returns a masked version of str with the first n values masked (as of Hive 2.1.0). Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_first_n("1234-5678-8765-4321", 4) results in nnnn-5678-8765-4321.'
-      },
-      mask_last_n: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'mask_last_n(STRING str [, INT n])',
-        draggable: 'mask_last_n()',
-        description: 'Returns a masked version of str with the last n values masked (as of Hive 2.1.0). Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_last_n("1234-5678-8765-4321", 4) results in 1234-5678-8765-nnnn.'
-      },
-      mask_show_first_n: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'mask_show_first_n(STRING str [, INT n])',
-        draggable: 'mask_show_first_n()',
-        description: 'Returns a masked version of str, showing the first n characters unmasked (as of Hive 2.1.0). Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_show_first_n("1234-5678-8765-4321", 4) results in 1234-nnnn-nnnn-nnnn.'
-      },
-      mask_show_last_n: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'INT', optional: true}]],
-        signature: 'mask_show_last_n(STRING str [, INT n])',
-        draggable: 'mask_show_last_n()',
-        description: 'Returns a masked version of str, showing the last n characters unmasked (as of Hive 2.1.0). Upper case letters are converted to "X", lower case letters are converted to "x" and numbers are converted to "n". For example, mask_show_last_n("1234-5678-8765-4321", 4) results in nnnn-nnnn-nnnn-4321.'
-      },
-      mask_hash: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'CHAR'}, {type: 'VARCHAR'}]],
-        signature: 'mask_hash(STRING|CHAR|VARCHAR str)',
-        draggable: 'mask_hash()',
-        description: 'Returns a hashed value based on str (as of Hive 2.1.0). The hash is consistent and can be used to join masked values together across tables. This function returns null for non-string types.'
-      },
-    },
-    impala: {}
-  };
-
-  var TABLE_GENERATING_FUNCTIONS = {
-    hive: {
-      explode: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'ARRAY'}, {type: 'MAP'}]],
-        signature: 'explode(Array|Array<T>|Map a)',
-				draggable: 'explode()',
-        description: ''
-      },
-      inline: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'ARRAY'}]],
-        signature: 'inline(Array<Struct [, Struct]> a)',
-				draggable: 'inline()',
-        description: 'Explodes an array of structs into a table. (As of Hive 0.10.)'
-      },
-      json_tuple: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', multiple: true}]],
-        signature: 'json_tuple(STRING jsonStr, STRING k1, STRING k2, ...)',
-				draggable: 'json_tuple()',
-        description: 'A new json_tuple() UDTF is introduced in Hive 0.7. It takes a set of names (keys) and a JSON string, and returns a tuple of values using one function. This is much more efficient than calling GET_JSON_OBJECT to retrieve more than one key from a single JSON string.'
-      },
-      parse_url_tuple: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING', multiple: true}]],
-        signature: 'parse_url_tuple(STRING url, STRING p1, STRING p2, ...)',
-				draggable: 'parse_url_tuple()',
-        description: 'The parse_url_tuple() UDTF is similar to parse_url(), but can extract multiple parts of a given URL, returning the data in a tuple. Values for a particular key in QUERY can be extracted by appending a colon and the key to the partToExtract argument.'
-      },
-      posexplode: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'ARRAY'}]],
-        signature: 'posexplode(ARRAY)',
-        draggable: 'posexplode()',
-        description: 'posexplode() is similar to explode but instead of just returning the elements of the array it returns the element as well as its position  in the original array.'
-      },
-      stack: {
-        returnTypes: ['table'],
-        arguments: [[{type: 'INT'}], [{type: 'T', multiple: true}]],
-        signature: 'stack(INT n, v1, v2, ..., vk)',
-				draggable: 'stack()',
-        description: 'Breaks up v1, v2, ..., vk into n rows. Each row will have k/n columns. n must be constant.'
-      }
-    },
-    impala: {}
-  };
-
-  var MISC_FUNCTIONS = {
-    hive: {
-      aes_decrypt: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'BINARY'}], [{type: 'BINARY'}, {type: 'STRING'}]],
-        signature: 'aes_decrypt(BINARY input, STRING|BINARY key)',
-				draggable: 'aes_decrypt()',
-        description: 'Decrypt input using AES (as of Hive 1.3.0). Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: aes_decrypt(unbase64(\'y6Ss+zCYObpCbgfWfyNWTw==\'), \'1234567890123456\') = \'ABC\'.'
-      },
-      aes_encrypt: {
-        returnTypes: ['BINARY'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}], [{type: 'STRING'}, {type: 'BINARY'}]],
-        signature: 'aes_encrypt(STRING|BINARY input, STRING|BINARY key)',
-				draggable: 'aes_encrypt()',
-        description: 'Encrypt input using AES (as of Hive 1.3.0). Key lengths of 128, 192 or 256 bits can be used. 192 and 256 bits keys can be used if Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files are installed. If either argument is NULL or the key length is not one of the permitted values, the return value is NULL. Example: base64(aes_encrypt(\'ABC\', \'1234567890123456\')) = \'y6Ss+zCYObpCbgfWfyNWTw==\'.'
-      },
-      crc32: {
-        returnTypes: ['BIGINT'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}]],
-        signature: 'crc32(STRING|BINARY a)',
-				draggable: 'crc32()',
-        description: 'Computes a cyclic redundancy check value for string or binary argument and returns bigint value (as of Hive 1.3.0). Example: crc32(\'ABC\') = 2743272264.'
-      },
-      current_database: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'current_database()',
-				draggable: 'current_database()',
-        description: 'Returns current database name (as of Hive 0.13.0).'
-      },
-      current_user: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'current_user()',
-				draggable: 'current_user()',
-        description: 'Returns current user name (as of Hive 1.2.0).'
-      },
-      get_json_object: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'get_json_object(STRING json, STRING jsonPath)',
-				draggable: 'get_json_object()',
-        description: 'A limited version of JSONPath is supported ($ : Root object, . : Child operator, [] : Subscript operator for array, * : Wildcard for []'
-      },
-      hash: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'T', multiple: true}]],
-        signature: 'hash(a1[, a2...])',
-				draggable: 'hash()',
-        description: 'Returns a hash value of the arguments. (As of Hive 0.4.)'
-      },
-      java_method: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'T', multiple: true, optional: true}]],
-        signature: 'java_method(class, method[, arg1[, arg2..]])',
-				draggable: 'java_method()',
-        description: 'Calls a Java method by matching the argument signature, using reflection. (As of Hive 0.9.0.)'
-      },
-      logged_in_user: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'logged_in_user()',
-        draggable: 'logged_in_user()',
-        description: 'Returns current user name from the session state (as of Hive 2.2.0). This is the username provided when connecting to Hive.'
-      },
-      md5: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}]],
-        signature: 'md5(STRING|BINARY a)',
-        draggable: 'md5()',
-        description: 'Calculates an MD5 128-bit checksum for the string or binary (as of Hive 1.3.0). The value is returned as a string of 32 hex digits, or NULL if the argument was NULL. Example: md5(\'ABC\') = \'902fbdd2b1df0c4f70b4a5d23525e932\'.'
-      },
-      reflect: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}], [{type: 'T', multiple: true, optional: true}]],
-        signature: 'reflect(class, method[, arg1[, arg2..]])',
-				draggable: 'reflect()',
-        description: 'Calls a Java method by matching the argument signature, using reflection. (As of Hive 0.7.0.)'
-      },
-      sha: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}]],
-        signature: 'sha(STRING|BINARY a)',
-				draggable: 'sha()',
-        description: 'Calculates the SHA-1 digest for string or binary and returns the value as a hex string (as of Hive 1.3.0). Example: sha1(\'ABC\') = \'3c01bdbb26f358bab27f267924aa2c9a03fcfdb8\'.'
-      },
-      sha1: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}]],
-        signature: 'sha1(STRING|BINARY a)',
-				draggable: 'sha1()',
-        description: 'Calculates the SHA-1 digest for string or binary and returns the value as a hex string (as of Hive 1.3.0). Example: sha1(\'ABC\') = \'3c01bdbb26f358bab27f267924aa2c9a03fcfdb8\'.'
-      },
-      sha2: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}], [{type: 'INT'}]],
-        signature: 'sha2(STRING|BINARY a, INT b)',
-				draggable: 'sha2()',
-        description: 'Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512) (as of Hive 1.3.0). The first argument is the string or binary to be hashed. The second argument indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). SHA-224 is supported starting from Java 8. If either argument is NULL or the hash length is not one of the permitted values, the return value is NULL. Example: sha2(\'ABC\', 256) = \'b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78\'.'
-      },
-      version: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'version()',
-        draggable: 'version()',
-        description: 'Returns the Hive version (as of Hive 2.1.0). The string contains 2 fields, the first being a build number and the second being a build hash. Example: "select version();" might return "2.1.0.2.5.0.0-1245 r027527b9c5ce1a3d7d0b6d2e6de2378fb0c39232". Actual results will depend on your build.'
-      },
-      xpath: {
-        returnTypes: ['ARRAY'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'array<STRING> xpath(STRING xml, STRING xpath)',
-				draggable: 'array<STRING> xpath()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_boolean: {
-        returnTypes: ['BOOLEAN'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_boolean(STRING xml, STRING xpath)',
-				draggable: 'xpath_boolean()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_double: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_double(STRING xml, STRING xpath)',
-				draggable: 'xpath_double()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_float: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_float(STRING xml, STRING xpath)',
-				draggable: 'xpath_float()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_int: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_int(STRING xml, STRING xpath)',
-				draggable: 'xpath_int()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_long: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_long(STRING xml, STRING xpath)',
-				draggable: 'xpath_long()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_number: {
-        returnTypes: ['DOUBLE'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_number(STRING xml, STRING xpath)',
-				draggable: 'xpath_number()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_short: {
-        returnTypes: ['INT'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_short(STRING xml, STRING xpath)',
-				draggable: 'xpath_short()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      },
-      xpath_string: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}], [{type: 'STRING'}]],
-        signature: 'xpath_string(STRING xml, STRING xpath)',
-				draggable: 'xpath_string()',
-        description: 'The xpath family of UDFs are wrappers around the Java XPath library javax.xml.xpath provided by the JDK. The library is based on the XPath 1.0 specification.'
-      }
-    },
-    impala: {
-      coordinator: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'coordinator()',
-        draggable: 'coordinator()',
-        description: 'Returns the name of the host which is running the impalad daemon that is acting as the coordinator for the current query.'
-      },
-      current_database: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'current_database()',
-				draggable: 'current_database()',
-        description: 'Returns the database that the session is currently using, either default if no database has been selected, or whatever database the session switched to through a USE statement or the impalad - d option'
-      },
-      effective_user: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'effective_user()',
-        draggable: 'effective_user()',
-        description: 'Typically returns the same value as user(), except if delegation is enabled, in which case it returns the ID of the delegated user.'
-      },
-      logged_in_user: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'logged_in_user()',
-        draggable: 'logged_in_user()',
-        description: 'Purpose: Typically returns the same value as USER(). If delegation is enabled, it returns the ID of the delegated user. LOGGED_IN_USER() is an alias of EFFECTIVE_USER().'
-      },
-      pid: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'pid()',
-				draggable: 'pid()',
-        description: 'Returns the process ID of the impalad daemon that the session is connected to.You can use it during low - level debugging, to issue Linux commands that trace, show the arguments, and so on the impalad process.'
-      },
-      sleep: {
-        returnTypes: ['STRING'],
-        arguments: [[{type: 'INT'}]],
-        signature: 'sleep(INT ms)',
-        draggable: 'sleep()',
-        description: 'Pauses the query for a specified number of milliseconds. For slowing down queries with small result sets enough to monitor runtime execution, memory usage, or other factors that otherwise would be difficult to capture during the brief interval of query execution.'
-      },
-      user: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'user()',
-				draggable: 'user()',
-        description: 'Returns the username of the Linux user who is connected to the impalad daemon.Typically called a single time, in a query without any FROM clause, to understand how authorization settings apply in a security context; once you know the logged - in user name, you can check which groups that user belongs to, and from the list of groups you can check which roles are available to those groups through the authorization policy file.In Impala 2.0 and later, user() returns the the full Kerberos principal string, such as user@example.com, in a Kerberized environment.'
-      },
-      uuid: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'uuid()',
-        draggable: 'uuid()',
-        description: 'Returns a universal unique identifier, a 128-bit value encoded as a string with groups of hexadecimal digits separated by dashes.'
-      },
-      version: {
-        returnTypes: ['STRING'],
-        arguments: [],
-        signature: 'version()',
-				draggable: 'version()',
-        description: 'Returns information such as the precise version number and build date for the impalad daemon that you are currently connected to.Typically used to confirm that you are connected to the expected level of Impala to use a particular feature, or to connect to several nodes and confirm they are all running the same level of impalad.'
-      }
-    }
-  };
-
-  var ANALYTIC_FUNCTIONS = {
-    hive: {
-      cume_dist: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true, optional: true }]],
-        signature: 'cume_dist()',
-				draggable: 'cume_dist()',
-        description: ''
-      },
-      dense_rank: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'dense_rank() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'dense_rank() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. The output sequence produces duplicate integers for duplicate values of the ORDER BY expressions.'
-      },
-      first_value: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'first_value(expr) OVER([partition_by_clause] order_by_clause [window_clause])',
-        draggable: 'first_value() OVER()',
-        description: 'Returns the expression value from the first row in the window. The return value is NULL if the input expression is NULL.'
-      },
-      lag: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'INT', optional: true}], [{type: 'T', optional: true}]],
-        signature: 'lag(expr [, offset] [, default]) OVER ([partition_by_clause] order_by_clause)',
-        draggable: 'lag() OVER()',
-        description: 'This function returns the value of an expression using column values from a preceding row. You specify an integer offset, which designates a row position some number of rows previous to the current row. Any column references in the expression argument refer to column values from that prior row.'
-      },
-      last_value: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'last_value(expr) OVER([partition_by_clause] order_by_clause [window_clause])',
-        draggable: 'last_value() OVER()',
-        description: 'Returns the expression value from the last row in the window. The return value is NULL if the input expression is NULL.'
-      },
-      lead: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'INT', optional: true}], [{type: 'T', optional: true}]],
-        signature: 'lead(expr [, offset] [, default]) OVER([partition_by_clause] order_by_clause)',
-        draggable: 'lead() OVER()',
-        description: 'This function returns the value of an expression using column values from a following row. You specify an integer offset, which designates a row position some number of rows after to the current row. Any column references in the expression argument refer to column values from that later row.'
-      },
-      ntile: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true, optional: true }]],
-        signature: 'ntile()',
-				draggable: 'ntile()',
-        description: ''
-      },
-      percent_rank: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T', multiple: true, optional: true }]],
-        signature: 'percent_rank()',
-				draggable: 'percent_rank()',
-        description: ''
-      },
-      rank: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'rank() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'rank() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. The output sequence produces duplicate integers for duplicate values of the ORDER BY expressions. After generating duplicate output values for the "tied" input values, the function increments the sequence by the number of tied values.'
-      },
-      row_number: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'row_number() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'row_number() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. Starts the sequence over for each group produced by the PARTITIONED BY clause. The output sequence includes different values for duplicate input values. Therefore, the sequence never contains any duplicates or gaps, regardless of duplicate input values.'
-      }
-    },
-    impala: {
-      cume_dist: {
-        returnTypes: ['T'],
-        arguments: [{type: 'T'}],
-        signature: 'cume_dist(T expr) OVER([partition_by_clause] order_by_clause)',
-        draggable: 'cume_dist() OVER()',
-        description: 'Returns the cumulative distribution of a value. The value for each row in the result set is greater than 0 and less than or equal to 1.'
-      },
-      dense_rank: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'dense_rank() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'dense_rank() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. The output sequence produces duplicate integers for duplicate values of the ORDER BY expressions.'
-      },
-      first_value: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'first_value(expr) OVER([partition_by_clause] order_by_clause [window_clause])',
-        draggable: 'first_value() OVER()',
-        description: 'Returns the expression value from the first row in the window. The return value is NULL if the input expression is NULL.'
-      },
-      lag: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'INT', optional: true}], [{type: 'T', optional: true}]],
-        signature: 'lag(expr [, offset] [, default]) OVER ([partition_by_clause] order_by_clause)',
-        draggable: 'lag() OVER()',
-        description: 'This function returns the value of an expression using column values from a preceding row. You specify an integer offset, which designates a row position some number of rows previous to the current row. Any column references in the expression argument refer to column values from that prior row.'
-      },
-      last_value: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'last_value(expr) OVER([partition_by_clause] order_by_clause [window_clause])',
-        draggable: 'last_value() OVER()',
-        description: 'Returns the expression value from the last row in the window. The return value is NULL if the input expression is NULL.'
-      },
-      lead: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}], [{type: 'INT', optional: true}], [{type: 'T', optional: true}]],
-        signature: 'lead(expr [, offset] [, default]) OVER ([partition_by_clause] order_by_clause)',
-        draggable: 'lead() OVER()',
-        description: 'This function returns the value of an expression using column values from a following row. You specify an integer offset, which designates a row position some number of rows after to the current row. Any column references in the expression argument refer to column values from that later row.'
-      },
-      ntile: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T' }], [{type: 'T', multiple: true, optional: true}]],
-        signature: 'ntile(T expr [, T offset ...])',
-        draggable: 'ntile()',
-        description: 'Returns the "bucket number" associated with each row, between 1 and the value of an expression. For example, creating 100 buckets puts the lowest 1% of values in the first bucket, while creating 10 buckets puts the lowest 10% of values in the first bucket. Each partition can have a different number of buckets.'
-      },
-      percent_rank: {
-        returnTypes: ['T'],
-        arguments: [[{type: 'T'}]],
-        signature: 'percent_rank(T expr) OVER ([partition_by_clause] order_by_clause)',
-        draggable: 'percent_rank() OVER()',
-        description: 'Calculates the rank, expressed as a percentage, of each row within a group of rows. If rank is the value for that same row from the RANK() function (from 1 to the total number of rows in the partition group), then the PERCENT_RANK() value is calculated as (rank - 1) / (rows_in_group - 1) . If there is only a single item in the partition group, its PERCENT_RANK() value is 0. The ORDER BY clause is required. The PARTITION BY clause is optional. The window clause is not allowed.'
-      },
-      rank: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'rank() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'rank() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. The output sequence produces duplicate integers for duplicate values of the ORDER BY expressions. After generating duplicate output values for the "tied" input values, the function increments the sequence by the number of tied values.'
-      },
-      row_number: {
-        returnTypes: ['INT'],
-        arguments: [],
-        signature: 'row_number() OVER([partition_by_clause] order_by_clause)',
-        draggable: 'row_number() OVER()',
-        description: 'Returns an ascending sequence of integers, starting with 1. Starts the sequence over for each group produced by the PARTITIONED BY clause. The output sequence includes different values for duplicate input values. Therefore, the sequence never contains any duplicates or gaps, regardless of duplicate input values.'
-      }
-    }
-  };
-
-  var BIT_FUNCTIONS = {
-    hive: {},
-    impala: {
-      bitand: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'T' }]],
-        signature: 'bitand(T<integer_type> a, T<integer_type> b)',
-        draggable: 'bitand()',
-        description: 'Returns an integer value representing the bits that are set to 1 in both of the arguments. If the arguments are of different sizes, the smaller is promoted to the type of the larger.'
-      },
-      bitnot: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }]],
-        signature: 'bitnot(T<integer_type> a)',
-        draggable: 'bitnot()',
-        description: 'Inverts all the bits of the input argument.'
-      },
-      bitor: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'T' }]],
-        signature: 'bitor(T<integer_type> a, T<integer_type> b)',
-        draggable: 'bitor()',
-        description: 'Returns an integer value representing the bits that are set to 1 in either of the arguments. If the arguments are of different sizes, the smaller is promoted to the type of the larger.'
-      },
-      bitxor: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'T' }]],
-        signature: 'bitxor(T<integer_type> a, T<integer_type> b)',
-        draggable: 'bitxor()',
-        description: 'Returns an integer value representing the bits that are set to 1 in one but not both of the arguments. If the arguments are of different sizes, the smaller is promoted to the type of the larger.'
-      },
-      countset: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT', optional: true }]],
-        signature: 'countset(T<integer_type> a [, INT b])',
-        draggable: 'countset()',
-        description: 'By default, returns the number of 1 bits in the specified integer value. If the optional second argument is set to zero, it returns the number of 0 bits instead.'
-      },
-      getbit: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }]],
-        signature: 'getbit(T<integer_type> a, INT b)',
-        draggable: 'getbit()',
-        description: 'Returns a 0 or 1 representing the bit at a specified position. The positions are numbered right to left, starting at zero. The position argument (b) cannot be negative.'
-      },
-      rotateleft: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }]],
-        signature: 'rotateleft(T<integer_type> a, INT b)',
-        draggable: 'rotateleft()',
-        description: 'Rotates an integer value left by a specified number of bits. As the most significant bit is taken out of the original value, if it is a 1 bit, it is "rotated" back to the least significant bit. Therefore, the final value has the same number of 1 bits as the original value, just in different positions. In computer science terms, this operation is a "circular shift".'
-      },
-      rotateright: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }]],
-        signature: 'rotateright(T<integer_type> a, INT b)',
-        draggable: 'rotateright()',
-        description: 'Rotates an integer value right by a specified number of bits. As the least significant bit is taken out of the original value, if it is a 1 bit, it is "rotated" back to the most significant bit. Therefore, the final value has the same number of 1 bits as the original value, just in different positions. In computer science terms, this operation is a "circular shift".'
-      },
-      setbit: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }], [{ type: 'INT', optional: true }]],
-        signature: 'setbit(T<integer_type> a, INT b [, INT c])',
-        draggable: 'setbit()',
-        description: 'By default, changes a bit at a specified position (b) to a 1, if it is not already. If the optional third argument is set to zero, the specified bit is set to 0 instead.'
-      },
-      shiftleft: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }]],
-        signature: 'shiftleft(T<integer_type> a, INT b)',
-        draggable: 'shiftleft()',
-        description: 'Shifts an integer value left by a specified number of bits. As the most significant bit is taken out of the original value, it is discarded and the least significant bit becomes 0. In computer science terms, this operation is a "logical shift".'
-      },
-      shiftright: {
-        returnTypes: ['T'],
-        arguments: [[{ type: 'T' }], [{ type: 'INT' }]],
-        signature: 'shiftright(T<integer_type> a, INT b)',
-        draggable: 'shiftright()',
-        description: 'Shifts an integer value right by a specified number of bits. As the least significant bit is taken out of the original value, it is discarded and the most significant bit becomes 0. In computer science terms, this operation is a "logical shift".'
-      }
-    }
-  };
-
-  var CATEGORIZED_FUNCTIONS = {
-    hive: [
-      { name: 'Aggregate', functions: AGGREGATE_FUNCTIONS['hive'] },
-      { name: 'Analytic', functions: ANALYTIC_FUNCTIONS['hive'] },
-      { name: 'Collection', functions: COLLECTION_FUNCTIONS['hive'] },
-      { name: 'Complex Type', functions: COMPLEX_TYPE_CONSTRUCTS['hive'] },
-      { name: 'Conditional', functions: CONDITIONAL_FUNCTIONS['hive'] },
-      { name: 'Date', functions: DATE_FUNCTIONS['hive'] },
-      { name: 'Mathematical', functions: MATHEMATICAL_FUNCTIONS['hive'] },
-      { name: 'Misc', functions: MISC_FUNCTIONS['hive'] },
-      { name: 'String', functions: STRING_FUNCTIONS['hive'] },
-      { name: 'Data Masking', functions: DATA_MASKING_FUNCTIONS['hive'] },
-      { name: 'Table Generating', functions: TABLE_GENERATING_FUNCTIONS['hive'] },
-      { name: 'Type Conversion', functions: TYPE_CONVERSION_FUNCTIONS['hive'] }
-    ],
-    impala: [
-      { name: 'Aggregate', functions: AGGREGATE_FUNCTIONS['impala'] },
-      { name: 'Analytic', functions: ANALYTIC_FUNCTIONS['impala'] },
-      { name: 'Bit', functions: BIT_FUNCTIONS['impala'] },
-      { name: 'Conditional', functions: CONDITIONAL_FUNCTIONS['impala'] },
-      { name: 'Date', functions: DATE_FUNCTIONS['impala'] },
-      { name: 'Mathematical', functions: MATHEMATICAL_FUNCTIONS['impala'] },
-      { name: 'Misc', functions: MISC_FUNCTIONS['impala'] },
-      { name: 'String', functions: STRING_FUNCTIONS['impala'] },
-      { name: 'Type Conversion', functions: TYPE_CONVERSION_FUNCTIONS['impala'] }
-    ]
-  };
-
-  var typeImplicitConversion = {
-    hive: {
-      BOOLEAN: {
-        BOOLEAN: true, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: false, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      TIMESTAMP: {
-        BOOLEAN: false, TIMESTAMP: true, DATE: false, BINARY: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: false, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      DATE: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: true, BINARY: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: false, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      BINARY: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: true, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: false, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      TINYINT: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: false, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: true, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      SMALLINT: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: false, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: true, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      INT: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: false, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: true, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      BIGINT: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: false, DOUBLE: false, DECIMAL: false, NUMBER: true, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      FLOAT: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: false, DECIMAL: false, NUMBER: true, STRING: false, CHAR: false, VARCHAR: false, T: true
-      },
-      DOUBLE: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: false, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      DECIMAL: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      NUMBER: {
-        BOOLEAN: false, TIMESTAMP: false, DATE: false, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      STRING: {
-        BOOLEAN: false, TIMESTAMP: true, DATE: true, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      CHAR: {
-        BOOLEAN: false, TIMESTAMP: true, DATE: true, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      VARCHAR: {
-        BOOLEAN: false, TIMESTAMP: true, DATE: true, BINARY: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      },
-      T: {
-        BOOLEAN: true, TIMESTAMP: true, DATE: true, BINARY: true, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, FLOAT: true, DOUBLE: true, DECIMAL: true, NUMBER: true, STRING: true, CHAR: true, VARCHAR: true, T: true
-      }
-    },
-    impala: {
-      BOOLEAN: {
-        BOOLEAN: true, TIMESTAMP: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: false, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      TIMESTAMP :{
-        BOOLEAN: false, TIMESTAMP: true, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: false, CHAR: false, VARCHAR: false, STRING: true, T: true
-      },
-      TINYINT: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      SMALLINT: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      INT: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      BIGINT: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      DOUBLE: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: true, REAL: true, DECIMAL: false, FLOAT: true, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      REAL: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: true, REAL: true, DECIMAL: false, FLOAT: true, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      DECIMAL: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: true, REAL: true, DECIMAL: true, FLOAT: true, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      FLOAT: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: true, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      NUMBER: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: true, REAL: true, DECIMAL: true, FLOAT: true, NUMBER: true, CHAR: false, VARCHAR: false, STRING: false, T: true
-      },
-      CHAR: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: false, CHAR: true, VARCHAR: false, STRING: false, T: true
-      },
-      VARCHAR: {
-        BOOLEAN: false, TIMESTAMP: false, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: false, CHAR: true, VARCHAR: true, STRING: false, T: true
-      },
-      STRING: {
-        BOOLEAN: false, TIMESTAMP: true, TINYINT: false, SMALLINT: false, INT: false, BIGINT: false, DOUBLE: false, REAL: false, DECIMAL: false, FLOAT: false, NUMBER: false, CHAR: true, VARCHAR: false, STRING: true, T: true
-      },
-      T: {
-        BOOLEAN: true, TIMESTAMP: true, TINYINT: true, SMALLINT: true, INT: true, BIGINT: true, DOUBLE: true, REAL: true, DECIMAL: true, FLOAT: true, NUMBER: true, CHAR: true, VARCHAR: true, STRING: true, T: true
-      }
-    }
-  };
-
-  var createDocHtml = function (funcDesc) {
-    var html = '<div class="fn-details"><p><span class="fn-sig">' + funcDesc.signature + '</span></p>';
-    if (funcDesc.description) {
-      html += '<p>' + funcDesc.description.replace(/[<]/g, "&lt;").replace(/[>]/g, "&gt;") + '</p>';
-    }
-    html += '<div>';
-    return html;
-  };
-
-  var stripPrecision = function (types) {
-    var result = [];
-    types.forEach(function (type) {
-      if (type.indexOf('(') > -1) {
-        result.push(type.substring(0, type.indexOf('(')))
-      } else {
-        result.push(type);
-      }
-    });
-    return result;
-  };
-
-  /**
-   * Matches types based on implicit conversion i.e. if you expect a BIGINT then INT is ok but not BOOLEAN etc.
-   *
-   * @param dialect
-   * @param expectedTypes
-   * @param actualTypes
-   * @returns {boolean}
-   */
-  var matchesType = function (dialect, expectedTypes, actualRawTypes) {
-    if (dialect !== 'hive') {
-      dialect = 'impala';
-    }
-    if (expectedTypes.length === 1 && expectedTypes[0] === 'T') {
-      return true;
-    }
-    var actualTypes = stripPrecision(actualRawTypes);
-    if (actualTypes.indexOf('ARRAY') !== -1 || actualTypes.indexOf('MAP') !== -1 || actualTypes.indexOf('STRUCT') !== -1) {
-      return true;
-    }
-    for (var i = 0; i < expectedTypes.length; i++) {
-      for (var j = 0; j < actualTypes.length; j++) {
-        // To support future unknown types
-        if (typeof typeImplicitConversion[dialect][expectedTypes[i]] === 'undefined' || typeof typeImplicitConversion[dialect][expectedTypes[i]][actualTypes[j]] == 'undefined') {
-          return true;
-        }
-        if (typeImplicitConversion[dialect][expectedTypes[i]] && typeImplicitConversion[dialect][expectedTypes[i]][actualTypes[j]]) {
-          return true;
-        }
-      }
-    }
-    return false;
-  };
-
-  var addFunctions = function (functionIndex, dialect, returnTypes, result) {
-    var indexForDialect = functionIndex[dialect || 'generic'];
-    if (indexForDialect) {
-      Object.keys(indexForDialect).forEach(function (funcName) {
-        var func = indexForDialect[funcName];
-        if (typeof returnTypes === 'undefined' || matchesType(dialect, returnTypes, func.returnTypes)) {
-          result[funcName] = func;
-        }
-      });
-    }
-    if (functionIndex.shared) {
-      Object.keys(functionIndex.shared).forEach(function (funcName) {
-        var func = functionIndex.shared[funcName];
-        if (typeof returnTypes === 'undefined' || matchesType(dialect, returnTypes, func.returnTypes)) {
-          result[funcName] = func;
-        }
-      });
-    }
-  };
-
-  var getFunctionsWithReturnTypes = function (dialect, returnTypes, includeAggregate, includeAnalytic) {
-    var result = {};
-    addFunctions(BIT_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(COLLECTION_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(CONDITIONAL_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(COMPLEX_TYPE_CONSTRUCTS, dialect, returnTypes, result);
-    addFunctions(DATE_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(MATHEMATICAL_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(TYPE_CONVERSION_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(STRING_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(DATA_MASKING_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(MISC_FUNCTIONS, dialect, returnTypes, result);
-    addFunctions(TABLE_GENERATING_FUNCTIONS, dialect, returnTypes, result);
-    if (includeAggregate) {
-      addFunctions(AGGREGATE_FUNCTIONS, dialect, returnTypes, result);
-    }
-    if (includeAnalytic) {
-      addFunctions(ANALYTIC_FUNCTIONS, dialect, returnTypes, result);
-    }
-    return result;
-  };
-
-  var suggestFunctions = function (dialect, returnTypes, includeAggregate, includeAnalytic, completions, weight) {
-    var functionsToSuggest = getFunctionsWithReturnTypes(dialect, returnTypes, includeAggregate, includeAnalytic);
-    Object.keys(functionsToSuggest).forEach(function (name) {
-      completions.push({
-        value: name + '()',
-        meta: functionsToSuggest[name].returnTypes.join('|'),
-        weight: returnTypes.filter(function (type) {
-          return functionsToSuggest[name].returnTypes.filter(
-              function (otherType) {
-                return otherType === type;
-              }).length > 0
-        }).length > 0 ? weight + 1 : weight,
-        docHTML: createDocHtml(functionsToSuggest[name])
-      })
-    });
-  };
-
-  var findFunction = function (dialect, functionName) {
-    return BIT_FUNCTIONS[dialect][functionName] ||
-      COLLECTION_FUNCTIONS[dialect][functionName] ||
-      CONDITIONAL_FUNCTIONS[dialect][functionName] ||
-      COMPLEX_TYPE_CONSTRUCTS[dialect][functionName] ||
-      DATE_FUNCTIONS[dialect][functionName] ||
-      MATHEMATICAL_FUNCTIONS[dialect][functionName] ||
-      TYPE_CONVERSION_FUNCTIONS[dialect][functionName] ||
-      STRING_FUNCTIONS[dialect][functionName] ||
-      DATA_MASKING_FUNCTIONS[dialect][functionName] ||
-      MISC_FUNCTIONS[dialect][functionName] ||
-      TABLE_GENERATING_FUNCTIONS[dialect][functionName] ||
-      AGGREGATE_FUNCTIONS[dialect][functionName] ||
-      ANALYTIC_FUNCTIONS[dialect][functionName];
-  };
-
-  var getArgumentTypes = function (dialect, functionName, argumentPosition) {
-    if (dialect !== 'hive' && dialect !== 'impala') {
-      return ['T'];
-    }
-    var foundFunction = findFunction(dialect, functionName);
-    if (!foundFunction) {
-      return ['T'];
-    }
-    var arguments = foundFunction.arguments;
-    if (argumentPosition > arguments.length) {
-      var multiples = arguments[arguments.length - 1].filter(function (type) {
-        return type.multiple;
-      });
-      if (multiples.length > 0) {
-        return multiples.map(function (argument) {
-          return argument.type;
-        }).sort();
-      }
-      return [];
-    }
-    return arguments[argumentPosition - 1].map(function (argument) {
-      return argument.type;
-    }).sort();
-  };
-
-  var getReturnTypes = function (dialect, functionName) {
-    if (dialect !== 'hive' && dialect !== 'impala') {
-      return ['T'];
-    }
-    var foundFunction = findFunction(dialect, functionName);
-    if (!foundFunction) {
-      return ['T'];
-    }
-    return foundFunction.returnTypes;
-  };
-
-  return {
-    suggestFunctions: suggestFunctions,
-    getArgumentTypes: getArgumentTypes,
-    CATEGORIZED_FUNCTIONS: CATEGORIZED_FUNCTIONS,
-    getFunctionsWithReturnTypes: getFunctionsWithReturnTypes,
-    getReturnTypes: getReturnTypes,
-    matchesType: matchesType,
-    findFunction: findFunction
-  };
-})();

+ 0 - 167
desktop/core/src/desktop/static/desktop/spec/hdfsAutocompleterSpec.js

@@ -1,167 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-(function () {
-  describe("hdfsAutocompleter.js", function() {
-    var subject;
-
-    var ajaxHelper = {
-      responseForUrls: {}
-    };
-
-    var apiHelper = window.apiHelper;
-
-    var snippet = {
-      type: ko.observable(),
-      database: ko.observable("database_one"),
-      isSqlDialect: function () { return true; },
-      getContext: function () { return ko.mapping.fromJS(null) },
-      getApiHelper: function () { return apiHelper }
-    };
-
-
-    beforeAll(function() {
-      jasmine.addMatchers(SqlTestUtils.autocompleteMatcher);
-      $.totalStorage = function(key, value) {
-        return null;
-      };
-
-      spyOn($, "ajax").and.callFake(function(options) {
-        var firstUrlPart = options.url.split("?")[0];
-        var response;
-        expect(ajaxHelper.responseForUrls[firstUrlPart]).toBeDefined("fake response for url " + firstUrlPart + " not found");
-        response = ajaxHelper.responseForUrls[firstUrlPart];
-        response.called = true;
-        response.status = 0;
-        options.success(response);
-        return({
-          fail: function() {
-            return {
-              always: $.noop
-            }
-          }
-        })
-      });
-    });
-
-    afterEach(function() {
-      $.each(ajaxHelper.responseForUrls, function(key, value) {
-        expect(value.called).toEqual(true, key + " was never called");
-      })
-    });
-
-    beforeEach(function() {
-      subject = new HdfsAutocompleter({
-        user: "testUser",
-        snippet: snippet
-      });
-      ajaxHelper.responseForUrls = {};
-    });
-
-    var createCallbackSpyForValues = function(values, name) {
-      return jasmine.createSpy(name ? name : 'callback', function (value) {
-        expect(value).toEqualAutocompleteValues(values)
-      }).and.callThrough();
-    };
-
-    var assertAutoComplete = function(testDefinition) {
-      ajaxHelper.responseForUrls = testDefinition.serverResponses;
-      var callback = createCallbackSpyForValues(testDefinition.expectedSuggestions);
-      subject.autocomplete(testDefinition.beforeCursor, testDefinition.afterCursor, callback);
-      expect(callback).toHaveBeenCalled();
-    };
-
-    it("should return empty suggestions for empty statement", function() {
-      assertAutoComplete({
-        serverResponses: {},
-        beforeCursor: "",
-        afterCursor: "",
-        expectedSuggestions: []
-      });
-    });
-
-    it("should return empty suggestions for bogus statements", function() {
-      assertAutoComplete({
-        serverResponses: {},
-        beforeCursor: "qwerqwer'asdf/",
-        afterCursor: "",
-        expectedSuggestions: []
-      });
-    });
-
-    it("should return empty suggestions for URIs with schemes ", function() {
-      assertAutoComplete({
-        serverResponses: {},
-        beforeCursor: "://blabla",
-        afterCursor: "",
-        expectedSuggestions: []
-      });
-    });
-
-    it("should return suggestions for root with '", function() {
-      assertAutoComplete({
-        serverResponses: {
-          "/filebrowser/view=/" : {
-            files: [
-              { name: ".", type: "dir" },
-              { name: "..", type: "dir" },
-              { name: "var", type: "dir" },
-              { name: "tmp_file", type: "file" }
-            ]
-          }
-        },
-        beforeCursor: "'/",
-        afterCursor: "",
-        expectedSuggestions: ["tmp_file", "var"]
-      });
-    });
-
-    it("should return suggestions for root with \"", function() {
-      assertAutoComplete({
-        serverResponses: {
-          "/filebrowser/view=/" : {
-            files: [
-              { name: ".", type: "dir" },
-              { name: "..", type: "dir" },
-              { name: "var", type: "dir" },
-              { name: "tmp_file", type: "file" }
-            ]
-          }
-        },
-        beforeCursor: "\"/",
-        afterCursor: "",
-        expectedSuggestions: ["tmp_file", "var"]
-      });
-    });
-
-    it("should return suggestions for non-root", function() {
-      assertAutoComplete({
-        serverResponses: {
-          "/filebrowser/view=/foo/bar" : {
-            files: [
-              { name: ".", type: "dir" },
-              { name: "..", type: "dir" },
-              { name: "var", type: "dir" },
-              { name: "tmp_file", type: "file" }
-            ]
-          }
-        },
-        beforeCursor: "'/foo/bar/",
-        afterCursor: "",
-        expectedSuggestions: ["tmp_file", "var"]
-      });
-    });
-  });
-})();

+ 0 - 491
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleter3Spec.js

@@ -1,491 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-(function () {
-  describe('sqlAutocompleter3.js', function () {
-
-    describe('AutocompleteResults', function () {
-
-      var subject = new AutocompleteResults({
-        snippet: {
-          autocompleteSettings: {
-            temporaryOnly: false
-          },
-          type: function () {
-            return 'hive';
-          },
-          database: function () {
-            return 'default';
-          },
-          namespace: function () {
-            return { id: 'defaultNamespace' }
-          },
-          compute: function () {
-            return { id: 'defaultCompute' }
-          },
-          whenContextSet: function () {
-            return $.Deferred().resolve();
-          }
-        },
-        editor: function () {
-          return {
-            getTextBeforeCursor: function () {
-              return "foo";
-            },
-            getTextAfterCursor: function () {
-              return "bar";
-            }
-          }
-        }
-      });
-
-      describe('Test a whole lot of different parse results', function () {
-
-        beforeEach(function() {
-          dataCatalog.disableCache();
-          AUTOCOMPLETE_TIMEOUT = 1;
-          jasmine.Ajax.install();
-
-          var failResponse = {
-            status: 500
-          };
-
-          jasmine.Ajax.stubRequest(
-            /.*\/notebook\/api\/autocomplete\/$/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'application/json',
-            responseText: '{"status": 0, "databases": ["default"]}'
-          });
-
-          jasmine.Ajax.stubRequest(
-            /.*\/notebook\/api\/autocomplete\/[^/]+$/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'application/json',
-            responseText: '{"status": 0, "tables_meta": [' +
-                '{"comment": "comment", "type": "Table", "name": "foo"}, ' +
-                '{"comment": null, "type": "View", "name": "bar_view"}, ' +
-                '{"comment": null, "type": "Table", "name": "bar"}]}'
-          });
-
-          jasmine.Ajax.stubRequest(
-            /.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+$/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'application/json',
-            responseText: '{"status": 0, "support_updates": false, "hdfs_link": "/filebrowser/view=/user/hive/warehouse/customers", "extended_columns": [{"comment": "", "type": "int", "name": "id"}, {"comment": "", "type": "string", "name": "name"}, {"comment": "", "type": "struct<email_format:string,frequency:string,categories:struct<promos:boolean,surveys:boolean>>", "name": "email_preferences"}, {"comment": "", "type": "map<string,struct<street_1:string,street_2:string,city:string,state:string,zip_code:string>>", "name": "addresses"}, {"comment": "", "type": "array<struct<order_id:string,order_date:string,items:array<struct<product_id:int,sku:string,name:string,price:double,qty:int>>>>", "name": "orders"}], "columns": ["id", "name", "email_preferences", "addresses", "orders"], "partition_keys": []}'
-          });
-
-          jasmine.Ajax.stubRequest(
-            /.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+\/[^/]+$/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'application/json',
-            responseText: '{"status": 0, "comment": "", "type": "struct", "name": "email_preferences", "fields": [{"type": "string", "name": "email_format"}, {"type": "string", "name": "frequency"}, {"fields": [{"type": "boolean", "name": "promos"}, {"type": "boolean", "name": "surveys"}], "type": "struct", "name": "categories"}]}'
-          });
-
-          jasmine.Ajax.stubRequest(
-            /.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+\/[^/]+\/.*$/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'application/json',
-            responseText: '{"status": 0, "fields": [{"type": "boolean", "name": "promos"}, {"type": "boolean", "name": "surveys"}], "type": "struct", "name": "categories"}'
-          });
-
-          jasmine.Ajax.stubRequest(
-            /.*\/filebrowser\/view.*/
-          ).andReturn(Math.random() < 0.5 ? failResponse : {
-            status: 200,
-            statusText: 'HTTP/1.1 200 OK',
-            contentType: 'text/javascript',
-            response: {
-              "superuser": "hdfs",
-              "current_request_path": "/filebrowser/view=///var",
-              "current_dir_path": "///var",
-              "show_download_button": true,
-              "cwd_set": true,
-              "breadcrumbs": [
-                {
-                  "url": "/",
-                  "label": "/"
-                },
-                {
-                  "url": "/var",
-                  "label": "var"
-                }
-              ],
-              "apps": [
-                "help",
-                "sqoop",
-                "pig",
-                "hbase",
-                "rdbms",
-                "indexer",
-                "metastore",
-                "beeswax",
-                "jobsub",
-                "metadata",
-                "zookeeper",
-                "search",
-                "useradmin",
-                "notebook",
-                "proxy",
-                "oozie",
-                "spark",
-                "filebrowser",
-                "about",
-                "jobbrowser",
-                "dashboard",
-                "security",
-                "impala"
-              ],
-              "show_upload_button": true,
-              "files": [
-                {
-                  "humansize": "0\u00a0bytes",
-                  "url": "/filebrowser/view=/",
-                  "stats": {
-                    "size": 0,
-                    "group": "supergroup",
-                    "blockSize": 0,
-                    "replication": 0,
-                    "user": "hdfs",
-                    "mtime": 1476970119,
-                    "path": "///var/..",
-                    "atime": 0,
-                    "mode": 16877
-                  },
-                  "name": "..",
-                  "mtime": "October 20, 2016 06:28 AM",
-                  "rwx": "drwxr-xr-x",
-                  "path": "/",
-                  "is_sentry_managed": false,
-                  "type": "dir",
-                  "mode": "40755"
-                },
-                {
-                  "humansize": "0\u00a0bytes",
-                  "url": "/filebrowser/view=/var",
-                  "stats": {
-                    "size": 0,
-                    "group": "supergroup",
-                    "blockSize": 0,
-                    "replication": 0,
-                    "user": "hdfs",
-                    "mtime": 1470887321,
-                    "path": "///var",
-                    "atime": 0,
-                    "mode": 16877
-                  },
-                  "name": ".",
-                  "mtime": "August 10, 2016 08:48 PM",
-                  "rwx": "drwxr-xr-x",
-                  "path": "/var",
-                  "is_sentry_managed": false,
-                  "type": "dir",
-                  "mode": "40755"
-                },
-                {
-                  "humansize": "0\u00a0bytes",
-                  "url": "/filebrowser/view=/var/lib",
-                  "stats": {
-                    "size": 0,
-                    "group": "supergroup",
-                    "blockSize": 0,
-                    "replication": 0,
-                    "user": "hdfs",
-                    "mtime": 1470887321,
-                    "path": "/var/lib",
-                    "atime": 0,
-                    "mode": 16877
-                  },
-                  "name": "lib",
-                  "mtime": "August 10, 2016 08:48 PM",
-                  "rwx": "drwxr-xr-x",
-                  "path": "/var/lib",
-                  "is_sentry_managed": false,
-                  "type": "dir",
-                  "mode": "40755"
-                },
-                {
-                  "humansize": "0\u00a0bytes",
-                  "url": "/filebrowser/view=/var/log",
-                  "stats": {
-                    "size": 0,
-                    "group": "mapred",
-                    "blockSize": 0,
-                    "replication": 0,
-                    "user": "yarn",
-                    "mtime": 1470887196,
-                    "path": "/var/log",
-                    "atime": 0,
-                    "mode": 17405
-                  },
-                  "name": "log",
-                  "mtime": "August 10, 2016 08:46 PM",
-                  "rwx": "drwxrwxr-xt",
-                  "path": "/var/log",
-                  "is_sentry_managed": false,
-                  "type": "dir",
-                  "mode": "41775"
-                }
-              ],
-              "users": [],
-              "is_embeddable": false,
-              "supergroup": "supergroup",
-              "descending": "false",
-              "groups": [],
-              "is_trash_enabled": true,
-              "pagesize": 50,
-              "file_filter": "any",
-              "is_fs_superuser": false,
-              "is_sentry_managed": false,
-              "home_directory": "/user/admin",
-              "path": "///var",
-              "page": {
-                "num_pages": 1,
-                "total_count": 2,
-                "next_page_number": 1,
-                "end_index": 2,
-                "number": 1,
-                "previous_page_number": 1,
-                "start_index": 1
-              }
-            }
-          });
-
-          window.apiHelper;
-          huePubSub.publish('assist.clear.all.caches');
-        });
-
-        afterEach(function() {
-          AUTOCOMPLETE_TIMEOUT = 0;
-          dataCatalog.enableCache();
-          jasmine.Ajax.uninstall();
-        });
-
-        SqlTestUtils.LOTS_OF_PARSE_RESULTS.forEach(function (parseResult) {
-          // if (parseResult.index == 382) {
-            it('should handle parse result no. ' + parseResult.index, function () {
-              if (parseResult.suggestKeywords) {
-                var cleanedKeywords = [];
-                parseResult.suggestKeywords.forEach(function (keyword) {
-                  if (!keyword.value) {
-                    cleanedKeywords.push({ value: keyword });
-                  } else {
-                    cleanedKeywords.push(keyword);
-                  }
-                });
-                parseResult.suggestKeywords = cleanedKeywords;
-              }
-              try {
-                subject.update(parseResult);
-              } catch (e) {
-                fail('Got exception');
-                console.error(e);
-              }
-              if (subject.loading()) {
-                for (var i = 0; i < jasmine.Ajax.requests.count(); i++) {
-                  console.log(jasmine.Ajax.requests.at(i));
-                }
-                fail('Still loading, missing ajax spec?')
-              }
-              expect(subject.loading()).toBeFalsy();
-            });
-          // }
-        });
-      });
-
-      it('should handle parse results with keywords', function () {
-        subject.entries([]);
-        expect(subject.filtered().length).toBe(0);
-        subject.update({
-          lowerCase: true,
-          suggestKeywords: [{ value: 'BAR', weight: 1 }, { value: 'FOO', weight: 2 }]
-        });
-        expect(subject.filtered().length).toBe(2);
-        // Sorted by weight, case adjusted
-        expect(subject.filtered()[0].meta).toBe(HUE_I18n.autocomplete.meta.keyword);
-        expect(subject.filtered()[0].value).toBe('foo');
-        expect(subject.filtered()[1].meta).toBe(HUE_I18n.autocomplete.meta.keyword);
-        expect(subject.filtered()[1].value).toBe('bar');
-      });
-
-      it('should handle parse results with identifiers', function () {
-        subject.entries([]);
-        expect(subject.filtered().length).toBe(0);
-        subject.update({
-          lowerCase: false,
-          suggestIdentifiers: [{ name: 'foo', type: 'alias' }, { name: 'bar', type: 'table' }]
-        });
-        expect(subject.filtered().length).toBe(2);
-        // Sorted by name, no case adjust
-        expect(subject.filtered()[0].meta).toBe('table');
-        expect(subject.filtered()[0].value).toBe('bar');
-        expect(subject.filtered()[1].meta).toBe('alias');
-        expect(subject.filtered()[1].value).toBe('foo');
-      });
-
-      it('should handle parse results with functions', function () {
-        subject.entries([]);
-        expect(subject.filtered().length).toBe(0);
-        subject.update({
-          lowerCase: false,
-          suggestFunctions: {}
-        });
-        expect(subject.filtered().length).toBeGreaterThan(0);
-        expect(subject.filtered()[0].details.arguments).toBeDefined();
-        expect(subject.filtered()[0].details.signature).toBeDefined();
-        expect(subject.filtered()[0].details.description).toBeDefined();
-      });
-    });
-
-    describe('SqlAutocomplete3', function () {
-
-      var subject;
-
-      beforeEach(function() {
-        dataCatalog.disableCache();
-        AUTOCOMPLETE_TIMEOUT = 1;
-        jasmine.Ajax.install();
-
-        jasmine.Ajax.stubRequest(
-          /.*\/notebook\/api\/autocomplete\/$/
-        ).andReturn({
-          status: 200,
-          statusText: 'HTTP/1.1 200 OK',
-          contentType: 'application/json',
-          responseText: '{"status": 0, "databases": ["default"]}'
-        });
-
-        jasmine.Ajax.stubRequest(
-          /.*\/notebook\/api\/autocomplete\/[^/]+$/
-        ).andReturn({
-          status: 200,
-          statusText: 'HTTP/1.1 200 OK',
-          contentType: 'application/json',
-          responseText: '{"status": 0, "tables_meta": [' +
-          '{"comment": "comment", "type": "Table", "name": "foo"}, ' +
-          '{"comment": null, "type": "View", "name": "bar_view"}, ' +
-          '{"comment": null, "type": "Table", "name": "bar"}]}'
-        });
-
-        jasmine.Ajax.stubRequest(
-          /.*\/notebook\/api\/autocomplete\/[^/]+\/[^/]+$/
-        ).andReturn({
-          status: 200,
-          statusText: 'HTTP/1.1 200 OK',
-          contentType: 'application/json',
-          responseText: '{"status": 0, "support_updates": false, "hdfs_link": "/filebrowser/view=/user/hive/warehouse/customers", "extended_columns": [{"comment": "", "type": "int", "name": "id"}, {"comment": "", "type": "string", "name": "name"}, {"comment": "", "type": "struct<email_format:string,frequency:string,categories:struct<promos:boolean,surveys:boolean>>", "name": "email_preferences"}, {"comment": "", "type": "map<string,struct<street_1:string,street_2:string,city:string,state:string,zip_code:string>>", "name": "addresses"}, {"comment": "", "type": "array<struct<order_id:string,order_date:string,items:array<struct<product_id:int,sku:string,name:string,price:double,qty:int>>>>", "name": "orders"}], "columns": ["id", "name", "email_preferences", "addresses", "orders"], "partition_keys": []}'
-        });
-      });
-
-      afterEach(function() {
-        if (subject.suggestions.loading()) {
-          for (var i = 0; i < jasmine.Ajax.requests.count(); i++) {
-            console.log(jasmine.Ajax.requests.at(i));
-          }
-          fail('Still loading, missing ajax spec?')
-        }
-        AUTOCOMPLETE_TIMEOUT = 0;
-        dataCatalog.enableCache();
-        jasmine.Ajax.uninstall();
-      });
-
-      var createSubject = function (dialect, textBeforeCursor, textAfterCursor, positionStatement) {
-        var editor = ace.edit();
-        editor.setValue(textBeforeCursor);
-        var actualCursorPosition = editor.getCursorPosition();
-        editor.setValue(textBeforeCursor + textAfterCursor);
-        editor.moveCursorToPosition(actualCursorPosition);
-
-        return new SqlAutocompleter3({
-          snippet: {
-            autocompleteSettings: {
-              temporaryOnly: false
-            },
-            type: function () {
-              return dialect;
-            },
-            database: function () {
-              return 'default';
-            },
-            namespace: function () {
-              return { id: 'defaultNamespace' }
-            },
-            compute: function () {
-              return { id: 'defaultCompute' }
-            },
-            whenContextSet: function () {
-              return $.Deferred().resolve();
-            },
-            positionStatement: ko.observable(positionStatement)
-          },
-          editor: function () {
-            return editor
-          }
-        })
-      };
-
-      it('should create suggestions for Hive', function () {
-        subject = createSubject('hive', '', '');
-        expect(subject.suggestions.filtered().length).toBe(0);
-        subject.autocomplete();
-        expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
-      });
-
-      it('should create suggestions for Impala', function () {
-        subject = createSubject('impala', '', '');
-        expect(subject.suggestions.filtered().length).toBe(0);
-        subject.autocomplete();
-        expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
-      });
-
-      it('should fallback to the active query when there are surrounding errors', function () {
-        subject = createSubject('hive', 'SELECT FROMzzz bla LIMIT 1; SELECT ', ' FROM bla', { location: { first_line: 1, last_line: 1, first_column: 27, last_column: 52 }});
-        expect(subject.suggestions.filtered().length).toBe(0);
-        subject.autocomplete();
-        expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
-      });
-
-      it('should only fallback to the active query when there are surrounding errors if there\'s an active query', function () {
-        subject = createSubject('hive', 'SELECT FROMzzz bla LIMIT 1; SELECT ', ' FROM bla');
-        expect(subject.suggestions.filtered().length).toBe(0);
-        subject.autocomplete();
-        expect(subject.suggestions.filtered().length).toBe(0);
-      });
-
-      it('should suggest columns from subqueries', function () {
-        subject = createSubject('hive', 'SELECT ', ' FROM customers, (SELECT app FROM web_logs) AS subQ;');
-        expect(subject.suggestions.filtered().length).toBe(0);
-        subject.autocomplete();
-        expect(subject.suggestions.filtered().length).toBeGreaterThan(0);
-
-
-        var appFound = subject.suggestions.filtered().some(function (suggestion) {
-          return suggestion.category.id === 'column' && suggestion.value === 'app';
-        });
-
-        expect(appFound).toBeTruthy();
-      })
-    });
-  });
-})();

+ 0 - 1
desktop/core/src/desktop/templates/common_header.mako

@@ -145,7 +145,6 @@ if USE_NEW_EDITOR.get():
   <script src="${ static('desktop/js/bootstrap-tooltip.js') }"></script>
   <script src="${ static('desktop/js/bootstrap-typeahead-touchscreen.js') }"></script>
   <script src="${ static('desktop/ext/js/bootstrap-better-typeahead.min.js') }"></script>
-  <script src="${ static('desktop/js/hue.colors.js') }"></script>
   <script src="${ static('desktop/js/popover-extra-placements.js') }"></script>
   <script src="${ static('desktop/ext/js/moment-with-locales.min.js') }"></script>
   <script src="${ static('desktop/ext/js/moment-timezone-with-data.min.js') }" type="text/javascript" charset="utf-8"></script>

+ 0 - 1
desktop/core/src/desktop/templates/common_header_m.mako

@@ -172,7 +172,6 @@ if USE_NEW_EDITOR.get():
   <script src="${ static('desktop/ext/js/tzdetect.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/d3.v3.js') }"></script>
   <script src="${ static('desktop/ext/js/d3.v4.js') }"></script>
-  <script src="${ static('desktop/js/hue.colors.js') }"></script>
   <script src="${ static('desktop/js/ace/ace.js') }"></script>
   <script src="${ static('desktop/js/ace/mode-impala.js') }"></script>
   <script src="${ static('desktop/js/ace/mode-hive.js') }"></script>

+ 0 - 5
desktop/core/src/desktop/templates/hue.mako

@@ -470,12 +470,7 @@ ${ render_bundle('hue') | n,unicode }
 <script src="${ static('desktop/js/ace.extended.js') }"></script>
 <script>ace.config.set("basePath", "/static/desktop/js/ace");</script>
 
-<script src="${ static('desktop/js/hue.colors.js') }"></script>
-
 <script src="${ static('desktop/js/share2.vm.js') }"></script>
-<script src="${ static('desktop/js/sqlAutocompleter3.js') }"></script>
-<script src="${ static('desktop/js/hdfsAutocompleter.js') }"></script>
-<script src="${ static('desktop/js/autocompleter.js') }"></script>
 <script src="${ static('metastore/js/metastore.model.js') }"></script>
 
 <script>

+ 1 - 1
desktop/core/src/desktop/templates/hue_ace_autocompleter.mako

@@ -387,7 +387,7 @@ from desktop.views import _ko
         self.snippet = params.snippet || {};
         self.foreachVisible = ko.observable();
 
-        self.autocompleter = params.autocompleter || new SqlAutocompleter3(params);
+        self.autocompleter = params.autocompleter || new SqlAutocompleter(params);
         self.suggestions = self.autocompleter.suggestions;
 
         self.active = ko.observable(false).extend({ rateLimit: 10 }); // to prevent flickering on empty result

+ 4 - 4
desktop/core/src/desktop/templates/ko_components/ko_simple_ace_editor.mako

@@ -774,10 +774,10 @@ from desktop.views import _ko
       var AVAILABLE_AUTOCOMPLETERS = {
         'solrFormula': SolrFormulaAutocompleter,
         'solrQuery':  SolrQueryAutocompleter,
-        'impalaQuery': SqlAutocompleter3,
-        'hiveQuery': SqlAutocompleter3,
-        'impala': SqlAutocompleter3,
-        'hive': SqlAutocompleter3
+        'impalaQuery': SqlAutocompleter,
+        'hiveQuery': SqlAutocompleter,
+        'impala': SqlAutocompleter,
+        'hive': SqlAutocompleter
       };
 
       var SimpleAceEditor = function (params, element) {

+ 5 - 9
docs/sdk/sdk.md

@@ -1248,9 +1248,7 @@ Or just some parts of the tests, e.g.:
 
 Jasmine tests:
 
-Requires Chrome to be installed
-
-    npm run test 
+    npm run test
 
 
 ## Longer story
@@ -1311,13 +1309,11 @@ Run all the tests once with:
 
     npm run test
 
-Run all the tests during development with:
+Optionally to use Karma and headless chrome for the tests you can run
+
+    npm run test-karma
 
-    npm run test-dev
-    
-In this mode it will watch the files and run tests when changes are detected.
-    
-See ```karma.config.js``` for various options
+See ```desktop/core/src/desktop/js/spec/karma.config.js``` for various options
 
 
 ### Special environment variables

+ 11 - 1
ext/thirdparty/README.md

@@ -114,6 +114,7 @@ Frontend third party dependencies (some checked in and some via npm)
 |Babel eslint|10.0.1|MIT|https://www.npmjs.com/package/babel-eslint|
 |Babel jscs|3.0.0-beta1|MIT|https://www.npmjs.com/package/babel-jscs|
 |Babel loader|8.0.5|MIT|https://www.npmjs.com/package/babel-loader|
+|Babel Plugin Module Resolver|3.2.0|MIT|https://www.npmjs.com/package/babel-plugin-module-resolver|
 |Babel preset-env|7.3.1|MIT|https://www.npmjs.com/package/@babel/preset-env|
 |Bootstrap|2.3.2|Apache|https://github.com/twbs/bootstrap|
 |bootstrap slider|?|Apache|https://github.com/seiyria/bootstrap-slider|
@@ -144,7 +145,8 @@ Frontend third party dependencies (some checked in and some via npm)
 |Grunt contrib less|2.0.0|MIT|https://www.npmjs.com/package/grunt-contrib-less|
 |Grunt contrib uglify|4.0.0|MIT|https://www.npmjs.com/package/grunt-contrib-uglify|
 |Grunt contrib watch|1.1.0|MIT|https://www.npmjs.com/package/grunt-contrib-watch|
-|Jasmine|2.3.4|MIT|https://github.com/jasmine/jasmine|
+|Jasmine|3.3.0,3.3.1|MIT|https://github.com/jasmine/jasmine|
+|Jasmine types|3.3.9|MIT|https://www.npmjs.com/package/@types/jasmine|
 |jqCron|?|MIT|https://github.com/arnapou/jqcron|
 |jQuery|2.2.4+3.3.1|MIT|https://github.com/jquery/jquery|
 |jQuery Basic Table|?|MIT|https://github.com/jerrylow/basictable|
@@ -158,6 +160,14 @@ Frontend third party dependencies (some checked in and some via npm)
 |jQuery Hotkeys Plugin|0.2.0|MIT|https://github.com/jeresig/jquery.hotkeys|
 |jQuery UI|1.10.4+1.12.1|MIT|https://github.com/jquery/jquery-ui|
 |jQuery visible|?|MIT|https://github.com/customd/jquery-visible|
+|JSDom|13.2.0|MIT|https://www.npmjs.com/package/jsdom|
+|JSON Loader|0.5.7|MIT|https://www.npmjs.com/package/json-loader|
+|Karma|4.0.1|MIT|https://www.npmjs.com/package/karma|
+|Karma Chrome Launcher|2.2.0|MIT|https://www.npmjs.com/package/karma-chrome-launcher|
+|Karma Jasmine|2.0.1|MIT|https://www.npmjs.com/package/karma-jasmine|
+|Karma Jasmine Ajax|0.1.13|MIT|https://www.npmjs.com/package/karma-jasmine-ajax|
+|Karma Mocha Reporter|2.2.5|MIT|https://www.npmjs.com/package/karma-mocha-reporter|
+|Karma Webpack|3.0.5|MIT|https://www.npmjs.com/package/karma-webpack|
 |Knockout Mapping|2.4.3|MIT|https://www.npmjs.com/package/knockout.mapping|
 |Knockout Sortable|1.1.0|MIT|https://www.npmjs.com/package/knockout-sortable|
 |Knockout Switch/Case|2.0.1|MIT|https://github.com/mbest/knockout-switch-case|

+ 98 - 106
package-lock.json

@@ -1591,12 +1591,6 @@
       "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
       "dev": true
     },
-    "array-slice": {
-      "version": "0.2.3",
-      "resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz",
-      "integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=",
-      "dev": true
-    },
     "array-union": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz",
@@ -2622,15 +2616,6 @@
       "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=",
       "dev": true
     },
-    "combine-lists": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/combine-lists/-/combine-lists-1.0.1.tgz",
-      "integrity": "sha1-RYwH4J4NkA/Ci3Cj/sLazR0st/Y=",
-      "dev": true,
-      "requires": {
-        "lodash": "^4.5.0"
-      }
-    },
     "combined-stream": {
       "version": "1.0.7",
       "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz",
@@ -2937,9 +2922,9 @@
       }
     },
     "date-format": {
-      "version": "1.2.0",
-      "resolved": "https://registry.npmjs.org/date-format/-/date-format-1.2.0.tgz",
-      "integrity": "sha1-YV6CjiM90aubua4JUODOzPpuytg=",
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/date-format/-/date-format-2.0.0.tgz",
+      "integrity": "sha512-M6UqVvZVgFYqZL1SfHsRGIQSz3ZL+qgbsV5Lp1Vj61LZVYuEwcMXYay7DRDtYs2HQQBK5hQtQ0fD9aEJ89V0LA==",
       "dev": true
     },
     "date-now": {
@@ -3733,34 +3718,6 @@
       "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=",
       "dev": true
     },
-    "expand-braces": {
-      "version": "0.1.2",
-      "resolved": "https://registry.npmjs.org/expand-braces/-/expand-braces-0.1.2.tgz",
-      "integrity": "sha1-SIsdHSRRyz06axks/AMPRMWFX+o=",
-      "dev": true,
-      "requires": {
-        "array-slice": "^0.2.3",
-        "array-unique": "^0.2.1",
-        "braces": "^0.1.2"
-      },
-      "dependencies": {
-        "array-unique": {
-          "version": "0.2.1",
-          "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz",
-          "integrity": "sha1-odl8yvy8JiXMcPrc6zalDFiwGlM=",
-          "dev": true
-        },
-        "braces": {
-          "version": "0.1.5",
-          "resolved": "https://registry.npmjs.org/braces/-/braces-0.1.5.tgz",
-          "integrity": "sha1-wIVxEIUpHYt1/ddOqw+FlygHEeY=",
-          "dev": true,
-          "requires": {
-            "expand-range": "^0.1.0"
-          }
-        }
-      }
-    },
     "expand-brackets": {
       "version": "2.1.4",
       "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-2.1.4.tgz",
@@ -3796,30 +3753,6 @@
         }
       }
     },
-    "expand-range": {
-      "version": "0.1.1",
-      "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-0.1.1.tgz",
-      "integrity": "sha1-TLjtoJk8pW+k9B/ELzy7TMrf8EQ=",
-      "dev": true,
-      "requires": {
-        "is-number": "^0.1.1",
-        "repeat-string": "^0.2.2"
-      },
-      "dependencies": {
-        "is-number": {
-          "version": "0.1.1",
-          "resolved": "https://registry.npmjs.org/is-number/-/is-number-0.1.1.tgz",
-          "integrity": "sha1-aaevEWlj1HIG7JvZtIoUIW8eOAY=",
-          "dev": true
-        },
-        "repeat-string": {
-          "version": "0.2.2",
-          "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-0.2.2.tgz",
-          "integrity": "sha1-x6jTI2BoNiBZp+RlH8aITosftK4=",
-          "dev": true
-        }
-      }
-    },
     "expand-tilde": {
       "version": "2.0.2",
       "resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz",
@@ -4257,6 +4190,17 @@
         "null-check": "^1.0.0"
       }
     },
+    "fs-extra": {
+      "version": "7.0.1",
+      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz",
+      "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==",
+      "dev": true,
+      "requires": {
+        "graceful-fs": "^4.1.2",
+        "jsonfile": "^4.0.0",
+        "universalify": "^0.1.0"
+      }
+    },
     "fs-write-stream-atomic": {
       "version": "1.0.10",
       "resolved": "https://registry.npmjs.org/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz",
@@ -5951,11 +5895,26 @@
       "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
       "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
     },
+    "jasmine": {
+      "version": "3.3.1",
+      "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.3.1.tgz",
+      "integrity": "sha512-/vU3/H7U56XsxIXHwgEuWpCgQ0bRi2iiZeUpx7Nqo8n1TpoDHfZhkPIc7CO8I4pnMzYsi3XaSZEiy8cnTfujng==",
+      "dev": true,
+      "requires": {
+        "glob": "^7.0.6",
+        "jasmine-core": "~3.3.0"
+      }
+    },
+    "jasmine-ajax": {
+      "version": "3.4.0",
+      "resolved": "https://registry.npmjs.org/jasmine-ajax/-/jasmine-ajax-3.4.0.tgz",
+      "integrity": "sha512-LIVNVCmx5ou+IG6wgX7j73YYzvE2e3aqFWMjOhvAHWTnLICOYSobIH+PG/gOwtP20X0u2SkD3NXT/j5X8rMGOA==",
+      "dev": true
+    },
     "jasmine-core": {
       "version": "3.3.0",
       "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.3.0.tgz",
-      "integrity": "sha512-3/xSmG/d35hf80BEN66Y6g9Ca5l/Isdeg/j6zvbTYlTzeKinzmaTM4p9am5kYqOmE05D7s1t8FGjzdSnbUbceA==",
-      "dev": true
+      "integrity": "sha512-3/xSmG/d35hf80BEN66Y6g9Ca5l/Isdeg/j6zvbTYlTzeKinzmaTM4p9am5kYqOmE05D7s1t8FGjzdSnbUbceA=="
     },
     "jquery": {
       "version": "3.3.1",
@@ -6053,6 +6012,12 @@
         }
       }
     },
+    "json-loader": {
+      "version": "0.5.7",
+      "resolved": "https://registry.npmjs.org/json-loader/-/json-loader-0.5.7.tgz",
+      "integrity": "sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w==",
+      "dev": true
+    },
     "json-parse-better-errors": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
@@ -6086,6 +6051,15 @@
       "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=",
       "dev": true
     },
+    "jsonfile": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
+      "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
+      "dev": true,
+      "requires": {
+        "graceful-fs": "^4.1.6"
+      }
+    },
     "jsprim": {
       "version": "1.4.1",
       "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@@ -6098,28 +6072,27 @@
       }
     },
     "karma": {
-      "version": "4.0.0",
-      "resolved": "https://registry.npmjs.org/karma/-/karma-4.0.0.tgz",
-      "integrity": "sha512-EFoFs3F6G0BcUGPNOn/YloGOb3h09hzTguyXlg6loHlKY76qbJikkcyPk43m2kfRF65TUGda/mig29QQtyhm1g==",
+      "version": "4.0.1",
+      "resolved": "https://registry.npmjs.org/karma/-/karma-4.0.1.tgz",
+      "integrity": "sha512-ind+4s03BqIXas7ZmraV3/kc5+mnqwCd+VDX1FndS6jxbt03kQKX2vXrWxNLuCjVYmhMwOZosAEKMM0a2q7w7A==",
       "dev": true,
       "requires": {
         "bluebird": "^3.3.0",
         "body-parser": "^1.16.1",
+        "braces": "^2.3.2",
         "chokidar": "^2.0.3",
         "colors": "^1.1.0",
-        "combine-lists": "^1.0.0",
         "connect": "^3.6.0",
         "core-js": "^2.2.0",
         "di": "^0.0.1",
         "dom-serialize": "^2.2.0",
-        "expand-braces": "^0.1.1",
         "flatted": "^2.0.0",
         "glob": "^7.1.1",
         "graceful-fs": "^4.1.2",
         "http-proxy": "^1.13.0",
         "isbinaryfile": "^3.0.0",
-        "lodash": "^4.17.5",
-        "log4js": "^3.0.0",
+        "lodash": "^4.17.11",
+        "log4js": "^4.0.0",
         "mime": "^2.3.1",
         "minimatch": "^3.0.2",
         "optimist": "^0.6.1",
@@ -6169,17 +6142,17 @@
       "version": "2.0.1",
       "resolved": "https://registry.npmjs.org/karma-jasmine/-/karma-jasmine-2.0.1.tgz",
       "integrity": "sha512-iuC0hmr9b+SNn1DaUD2QEYtUxkS1J+bSJSn7ejdEexs7P8EYvA1CWkEdrDQ+8jVH3AgWlCNwjYsT1chjcNW9lA==",
-      "dev": true,
       "requires": {
         "jasmine-core": "^3.3"
-      },
-      "dependencies": {
-        "jasmine-core": {
-          "version": "3.3.0",
-          "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.3.0.tgz",
-          "integrity": "sha512-3/xSmG/d35hf80BEN66Y6g9Ca5l/Isdeg/j6zvbTYlTzeKinzmaTM4p9am5kYqOmE05D7s1t8FGjzdSnbUbceA==",
-          "dev": true
-        }
+      }
+    },
+    "karma-jasmine-ajax": {
+      "version": "0.1.13",
+      "resolved": "https://registry.npmjs.org/karma-jasmine-ajax/-/karma-jasmine-ajax-0.1.13.tgz",
+      "integrity": "sha1-eLuS2Jb+MqJaGACYxHci4dlgW/w=",
+      "dev": true,
+      "requires": {
+        "jasmine-ajax": "^3.0.0"
       }
     },
     "karma-mocha-reporter": {
@@ -6239,6 +6212,15 @@
         }
       }
     },
+    "karma-spec-reporter": {
+      "version": "0.0.32",
+      "resolved": "https://registry.npmjs.org/karma-spec-reporter/-/karma-spec-reporter-0.0.32.tgz",
+      "integrity": "sha1-LpxyB+pyZ3EmAln4K+y1QyCeRAo=",
+      "dev": true,
+      "requires": {
+        "colors": "^1.1.2"
+      }
+    },
     "karma-webpack": {
       "version": "4.0.0-rc.6",
       "resolved": "https://registry.npmjs.org/karma-webpack/-/karma-webpack-4.0.0-rc.6.tgz",
@@ -6586,24 +6568,18 @@
       }
     },
     "log4js": {
-      "version": "3.0.6",
-      "resolved": "https://registry.npmjs.org/log4js/-/log4js-3.0.6.tgz",
-      "integrity": "sha512-ezXZk6oPJCWL483zj64pNkMuY/NcRX5MPiB0zE6tjZM137aeusrOnW1ecxgF9cmwMWkBMhjteQxBPoZBh9FDxQ==",
+      "version": "4.0.2",
+      "resolved": "https://registry.npmjs.org/log4js/-/log4js-4.0.2.tgz",
+      "integrity": "sha512-KE7HjiieVDPPdveA3bJZSuu0n8chMkFl8mIoisBFxwEJ9FmXe4YzNuiqSwYUiR1K8q8/5/8Yd6AClENY1RA9ww==",
       "dev": true,
       "requires": {
-        "circular-json": "^0.5.5",
-        "date-format": "^1.2.0",
+        "date-format": "^2.0.0",
         "debug": "^3.1.0",
+        "flatted": "^2.0.0",
         "rfdc": "^1.1.2",
-        "streamroller": "0.7.0"
+        "streamroller": "^1.0.1"
       },
       "dependencies": {
-        "circular-json": {
-          "version": "0.5.9",
-          "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz",
-          "integrity": "sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ==",
-          "dev": true
-        },
         "debug": {
           "version": "3.2.6",
           "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
@@ -9032,17 +9008,27 @@
       "dev": true
     },
     "streamroller": {
-      "version": "0.7.0",
-      "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-0.7.0.tgz",
-      "integrity": "sha512-WREzfy0r0zUqp3lGO096wRuUp7ho1X6uo/7DJfTlEi0Iv/4gT7YHqXDjKC2ioVGBZtE8QzsQD9nx1nIuoZ57jQ==",
+      "version": "1.0.3",
+      "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-1.0.3.tgz",
+      "integrity": "sha512-P7z9NwP51EltdZ81otaGAN3ob+/F88USJE546joNq7bqRNTe6jc74fTBDyynxP4qpIfKlt/CesEYicuMzI0yJg==",
       "dev": true,
       "requires": {
-        "date-format": "^1.2.0",
+        "async": "^2.6.1",
+        "date-format": "^2.0.0",
         "debug": "^3.1.0",
-        "mkdirp": "^0.5.1",
-        "readable-stream": "^2.3.0"
+        "fs-extra": "^7.0.0",
+        "lodash": "^4.17.10"
       },
       "dependencies": {
+        "async": {
+          "version": "2.6.2",
+          "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz",
+          "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==",
+          "dev": true,
+          "requires": {
+            "lodash": "^4.17.11"
+          }
+        },
         "debug": {
           "version": "3.2.6",
           "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
@@ -9577,6 +9563,12 @@
         "imurmurhash": "^0.1.4"
       }
     },
+    "universalify": {
+      "version": "0.1.2",
+      "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
+      "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
+      "dev": true
+    },
     "unpipe": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

+ 7 - 4
package.json

@@ -66,12 +66,15 @@
     "grunt-contrib-less": "2.0.0",
     "grunt-contrib-uglify": "4.0.0",
     "grunt-contrib-watch": "1.1.0",
-    "jasmine-core": "3.3.0",
+    "jasmine": "^3.3.1",
     "jsdom": "13.2.0",
+    "json-loader": "0.5.7",
     "karma": "^4.0.0",
     "karma-chrome-launcher": "^2.2.0",
+    "karma-jasmine": "",
+    "karma-jasmine-ajax": "^0.1.13",
     "karma-mocha-reporter": "^2.2.5",
-    "karma-jasmine": "^2.0.1",
+    "karma-spec-reporter": "0.0.32",
     "karma-webpack": "4.0.0-rc.6",
     "load-grunt-tasks": "4.0.0",
     "prettier": "1.16.1",
@@ -90,8 +93,8 @@
     "lint": "eslint desktop/core/src/desktop/js",
     "lint-debug": "npm run lint -- --debug",
     "lint-fix": "npm run lint -- --fix",
-    "test": "karma start karma.config.js --single-run",
-    "test-dev": "karma start karma.config.js"
+    "test": "babel-node desktop/core/src/desktop/js/spec/run.js",
+    "test-karma": "karma start desktop/core/src/desktop/js/spec/karma.config.js --single-run"
   },
   "files": []
 }

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác