Browse Source

HUE-1204 [beeswax] autocomplete delivers obscure error when completing "From"

Fixed a bug that prevented the keyword FROM to be autocompleted
Enrico Berti 12 years ago
parent
commit
71d5d82

+ 38 - 31
apps/beeswax/src/beeswax/templates/execute.mako

@@ -726,30 +726,35 @@ ${layout.menubar(section='query')}
             }
             CodeMirror.possibleSoloField = false;
             if (_before.toUpperCase().indexOf("SELECT ") > -1 && _before.toUpperCase().indexOf(" FROM ") == -1 && !CodeMirror.fromDot) {
-              CodeMirror.possibleSoloField = true;
-              try {
-                var _possibleTables = $.trim(codeMirror.getValue().substr(codeMirror.getValue().toUpperCase().indexOf("FROM") + 4)).split(" ");
-                var _foundTable = "";
-                for (var i = 0; i < _possibleTables.length; i++) {
-                  if ($.trim(_possibleTables[i]) != "" && _foundTable == "") {
-                    _foundTable = _possibleTables[i];
+              if (codeMirror.getValue().toUpperCase().indexOf("FROM") > -1) {
+                CodeMirror.possibleSoloField = true;
+                try {
+                  var _possibleTables = $.trim(codeMirror.getValue().substr(codeMirror.getValue().toUpperCase().indexOf("FROM") + 4)).split(" ");
+                  var _foundTable = "";
+                  for (var i = 0; i < _possibleTables.length; i++) {
+                    if ($.trim(_possibleTables[i]) != "" && _foundTable == "") {
+                      _foundTable = _possibleTables[i];
+                    }
                   }
-                }
-                if (_foundTable != "") {
-                  if (tableHasAlias(_foundTable)) {
-                    CodeMirror.possibleSoloField = false;
-                    CodeMirror.showHint(cm, CodeMirror.hiveQLHint);
-                  }
-                  else {
-                    getTableColumns(_foundTable,
-                            function (columns) {
-                              CodeMirror.catalogFields = columns;
-                              CodeMirror.showHint(cm, CodeMirror.hiveQLHint);
-                            });
+                  if (_foundTable != "") {
+                    if (tableHasAlias(_foundTable)) {
+                      CodeMirror.possibleSoloField = false;
+                      CodeMirror.showHint(cm, CodeMirror.hiveQLHint);
+                    }
+                    else {
+                      getTableColumns(_foundTable,
+                              function (columns) {
+                                CodeMirror.catalogFields = columns;
+                                CodeMirror.showHint(cm, CodeMirror.hiveQLHint);
+                              });
+                    }
                   }
                 }
+                catch (e) {
+                }
               }
-              catch (e) {
+              else {
+                CodeMirror.showHint(cm, CodeMirror.hiveQLHint);
               }
             }
             else {
@@ -783,17 +788,19 @@ ${layout.menubar(section='query')}
               var _line = codeMirror.getLine(codeMirror.getCursor().line);
               var _partial = _line.substring(0, codeMirror.getCursor().ch);
               var _table = _partial.substring(_partial.lastIndexOf(" ") + 1, _partial.length - 1);
-              getTableColumns(_table, function (columns) {
-                var _cols = columns.split(" ");
-                for (var col in _cols){
-                  _cols[col] = "." + _cols[col];
-                }
-                CodeMirror.catalogFields = _cols.join(" ");
-                CodeMirror.fromDot = true;
-                window.setTimeout(function () {
-                  codeMirror.execCommand("autocomplete");
-                }, 100);  // timeout for IE8
-              });
+              if (codeMirror.getValue().toUpperCase().indexOf("FROM") > -1) {
+                getTableColumns(_table, function (columns) {
+                  var _cols = columns.split(" ");
+                  for (var col in _cols){
+                    _cols[col] = "." + _cols[col];
+                  }
+                  CodeMirror.catalogFields = _cols.join(" ");
+                  CodeMirror.fromDot = true;
+                  window.setTimeout(function () {
+                    codeMirror.execCommand("autocomplete");
+                  }, 100);  // timeout for IE8
+                });
+              }
             }
           }
         }

+ 12 - 2
desktop/core/static/js/Source/jHue/codemirror-hql-hint.js

@@ -71,6 +71,10 @@
   var hiveQLKeywordsU = hiveQLKeywords.split(" ");
   var hiveQLKeywordsL = hiveQLKeywords.toLowerCase().split(" ");
 
+  var hiveQLKeywordsAfterTables = "JOIN ON WHERE";
+  var hiveQLKeywordsAfterTablesU = hiveQLKeywordsAfterTables.split(" ");
+  var hiveQLKeywordsAfterTablesL = hiveQLKeywordsAfterTables.toLowerCase().split(" ");
+
   var hiveQLTypes = "TINYINT SMALLINT INT BIGINT BOOLEAN FLOAT DOUBLE STRING BINARY TIMESTAMP DECIMAL ARRAY MAP STRUCT UNIONTYPE DELIMITED SERDE SEQUENCEFILE TEXTFILE RCFILE INPUTFORMAT OUTPUTFORMAT";
   var hiveQLTypesU = hiveQLTypes.split(" ");
   var hiveQLTypesL = hiveQLTypes.toLowerCase().split(" ");
@@ -108,8 +112,14 @@
           forEach(hiveQLTypesL, maybeAdd);
           forEach(hiveQLKeywordsU, maybeAdd);
           forEach(hiveQLKeywordsL, maybeAdd);
+
         }
-        forEach(catalogTablesL, maybeAdd);
+        else {
+          forEach(catalogTablesL, maybeAddToExtra);
+          forEach(hiveQLKeywordsAfterTablesU, maybeAdd);
+          forEach(hiveQLKeywordsAfterTablesL, maybeAdd);
+        }
+
       }
     }
 
@@ -123,6 +133,6 @@
         base = base[context.pop().string];
       if (base != null) gatherCompletions(base);
     }
-    return extraFound.concat(found.sort());
+    return extraFound.sort().concat(found.sort());
   }
 })();