소스 검색

[core] Fix whitespace issues with autocomplete

Johan Ahlen 10 년 전
부모
커밋
678a965
2개의 변경된 파일10개의 추가작업 그리고 10개의 파일을 삭제
  1. 3 3
      desktop/core/src/desktop/static/desktop/js/autocomplete.js
  2. 7 7
      desktop/core/src/desktop/static/desktop/spec/autocompleteSpec.js

+ 3 - 3
desktop/core/src/desktop/static/desktop/js/autocomplete.js

@@ -60,7 +60,7 @@ Autocompleter.prototype.getFromReferenceIndex = function (statement) {
     refs.sort();
     $.each(refs, function(index, tableRefRaw) {
       if (tableRefRaw.indexOf('(') == -1) {
-        var refMatch = tableRefRaw.match(/ *([^ ]*) ?([^ ]*)? */);
+        var refMatch = tableRefRaw.match(/\s*(\S+)\s*(\S+)?\s*/);
 
         var refParts = refMatch[1].split('.');
         if (refMatch[2]) {
@@ -94,7 +94,7 @@ Autocompleter.prototype.getViewReferenceIndex = function (statement) {
   //           map key reference (if group 5 is exists)
   // group 5 = array value (if posexplode)
   //           map value reference (if ! posexplode)
-  var lateralViewRegex = /LATERAL\s+VIEW\s+(pos)?explode\(([^\)]+)\)\s+(?:(\S+)\s+)?AS \(?([^ ,\)]*)(?:\s*,\s*([^ ,]*)\))?/gi;
+  var lateralViewRegex = /LATERAL\s+VIEW\s+(pos)?explode\(([^\)]+)\)\s+(?:(\S+)\s+)?AS\s+\(?([^\s,\)]*)(?:\s*,\s*([^\s,]*)\))?/gi;
   var lateralViewMatch;
 
   while (lateralViewMatch = lateralViewRegex.exec(statement)) {
@@ -282,7 +282,7 @@ Autocompleter.prototype.autocomplete = function(beforeCursor, afterCursor, callb
       callback(self.extractFields(data, fromKeyword));
     }, onFailure );
   } else if ((selectBefore && fromAfter) || fieldTermBefore || impalaFieldRef) {
-    var partialTermsMatch = beforeCursor.match(/([^ \(\-\+\<\>\,]*)$/);
+    var partialTermsMatch = beforeCursor.match(/([^\s\(\-\+\<\>\,]*)$/);
     var parts = partialTermsMatch ? partialTermsMatch[0].split(".") : [];
 
     // Drop the last part, empty or not. If it's not empty it's the start of a

+ 7 - 7
desktop/core/src/desktop/static/desktop/spec/autocompleteSpec.js

@@ -180,7 +180,7 @@ describe("autocomplete.js", function() {
       assertAutoComplete({
         serverResponses: {},
         beforeCursor: "SELECT ",
-        afterCursor: " FROM testTableA tta, testTableB",
+        afterCursor: " FROM testTableA   tta, testTableB",
         expectedSuggestions: ["testTableB.", "tta."]
       });
     });
@@ -373,10 +373,10 @@ describe("autocomplete.js", function() {
               type: "struct"
             }
           },
-          beforeCursor: "SELECT testItemB.",
-          afterCursor: " FROM testTable1, testTable2 tt2" +
-          " LATERAL VIEW explode(tt2.testArrayA) explodedTableA AS testItemA" +
-          " LATERAL VIEW explode(tt2.testArrayB) explodedTableB AS testItemB",
+          beforeCursor: "SELECT\n testItemA,\n testItemB.",
+          afterCursor: "\n\tFROM\n\t testTable2 tt2\n" +
+          "\t LATERAL VIEW EXPLODE(tt2.testArrayA) explodedTableA AS testItemA\n" +
+          "\t LATERAL VIEW EXPLODE(tt2.testArrayB) explodedTableB AS testItemB",
           expectedSuggestions: ["fieldA", "fieldB"]
         });
       });
@@ -395,8 +395,8 @@ describe("autocomplete.js", function() {
           beforeCursor: "SELECT ta2_exp.",
           afterCursor: " FROM " +
           "   testTable tt" +
-          " LATERAL VIEW explode(tt.testArray1) ta1 AS ta1_exp " +
-          " LATERAL VIEW explode(ta1_exp.testArray2) ta2 AS ta2_exp",
+          " LATERAL VIEW explode(tt.testArray1) ta1 AS ta1_exp\n" +
+          "   LATERAL VIEW explode(ta1_exp.testArray2)    ta2   AS  ta2_exp",
           expectedSuggestions: ["fieldA", "fieldB"]
         });
       });