Browse Source

HUE-3550 [editor] Autocomplete conflicts with certain table names

Johan Ahlen 9 years ago
parent
commit
1249169541

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter.js

@@ -88,7 +88,7 @@
     var fromMatch = statement.match(/\s*from\s*([^;]*).*$/i);
     if (fromMatch) {
       var refsRaw = fromMatch[1];
-      var upToMatch = refsRaw.match(/\bLATERAL|VIEW|EXPLODE|POSEXPLODE|ON|LIMIT|WHERE|GROUP BY|SORT|ORDER BY\b/i);
+      var upToMatch = refsRaw.match(/\s+(LATERAL|VIEW|EXPLODE|POSEXPLODE|ON|LIMIT|WHERE|GROUP BY|SORT|ORDER BY)\s+/i);
       if (upToMatch) {
         refsRaw = $.trim(refsRaw.substring(0, upToMatch.index));
       }

+ 26 - 0
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleterSpec.js

@@ -1102,6 +1102,32 @@ define([
         });
       });
 
+      it("should suggest columns for tables with where keyword in name", function() {
+        assertAutoComplete({
+          serverResponses: {
+            "/notebook/api/autocomplete/database_one/testwhere" : {
+              columns: ["testTableColumn1", "testTableColumn2"]
+            }
+          },
+          beforeCursor: "SELECT ",
+          afterCursor: " FROM testwhere",
+          expectedSuggestions: ["*", "testTableColumn1", "testTableColumn2"]
+        });
+      });
+
+      it("should suggest columns for tables with on keyword in name", function() {
+        assertAutoComplete({
+          serverResponses: {
+            "/notebook/api/autocomplete/database_one/teston" : {
+              columns: ["testTableColumn1", "testTableColumn2"]
+            }
+          },
+          beforeCursor: "SELECT ",
+          afterCursor: " FROM teston",
+          expectedSuggestions: ["*", "testTableColumn1", "testTableColumn2"]
+        });
+      });
+
       it("should suggest columns for table with database prefix", function() {
         assertAutoComplete({
           serverResponses: {