Ver código fonte

[core] Add HDFS autocomplete to Impala statements

Johan Ahlen 10 anos atrás
pai
commit
de708b8c83

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

@@ -22,7 +22,7 @@
   }
 }(this, function () {
 
-  var SQL_TERMS = /\b(FROM|TABLE|STATS|REFRESH|METADATA|DESCRIBE|ORDER BY|JOIN|ON|WHERE|SELECT|LIMIT|GROUP BY|SORT|USE|LOCATION)\b/g;
+  var SQL_TERMS = /\b(FROM|TABLE|STATS|REFRESH|METADATA|DESCRIBE|ORDER BY|JOIN|ON|WHERE|SELECT|LIMIT|GROUP BY|SORT|USE|LOCATION|INPATH)\b/g;
 
   /**
    * @param options {object}
@@ -369,8 +369,8 @@
       return;
     }
 
-    if (keywordBeforeCursor === "LOCATION") {
-      var pathMatch = beforeCursor.match(/.*location\s+('[^']*)$/i);
+    if (keywordBeforeCursor === "LOCATION" || keywordBeforeCursor === "INPATH") {
+      var pathMatch = beforeCursor.match(/.*(?:inpath|location)\s+('[^']*)$/i);
       if (pathMatch) {
         var existingPath = pathMatch[1].length == 1 ? pathMatch[1] + "/" : pathMatch[1];
         self.hdfsAutocompleter.autocomplete(existingPath, "", function (hdfsSuggestions) {

+ 60 - 17
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleterSpec.js

@@ -325,8 +325,6 @@ define([
         });
 
         it("should autocomplete hdfs paths in location references without initial /", function () {
-          var beforeCursor = "create external table foo (id int) location '";
-          var afterCursor = "";
           assertAutoComplete({
             serverResponses: {},
             beforeCursor: "CREATE EXTERNAL TABLE foo (id int) LOCATION '",
@@ -336,11 +334,6 @@ define([
         });
 
         it("should autocomplete hdfs paths in location references from root", function () {
-          var beforeCursor = "create external table foo (id int) location '";
-          var afterCursor = "";
-          subject.autocomplete(beforeCursor, afterCursor, function () {
-
-          });
           assertAutoComplete({
             serverResponses: {},
             beforeCursor: "CREATE EXTERNAL TABLE foo (id int) LOCATION '/",
@@ -350,11 +343,6 @@ define([
         });
 
         it("should autocomplete hdfs paths and suggest trailing apostrophe if empty after cursor", function () {
-          var beforeCursor = "create external table foo (id int) location '";
-          var afterCursor = "";
-          subject.autocomplete(beforeCursor, afterCursor, function () {
-
-          });
           assertAutoComplete({
             serverResponses: {},
             beforeCursor: "CREATE EXTERNAL TABLE foo (id int) LOCATION '/",
@@ -364,11 +352,6 @@ define([
         });
 
         it("should autocomplete hdfs paths in location references from inside a path", function () {
-          var beforeCursor = "create external table foo (id int) location '";
-          var afterCursor = "";
-          subject.autocomplete(beforeCursor, afterCursor, function () {
-
-          });
           assertAutoComplete({
             serverResponses: {},
             beforeCursor: "CREATE EXTERNAL TABLE foo (id int) LOCATION '/",
@@ -658,6 +641,66 @@ define([
         ajaxHelper.responseForUrls = {};
       });
 
+      describe("HDFS autocompletion", function () {
+        beforeEach(function() {
+          subject = new SqlAutocompleter({
+            hdfsAutocompleter: {
+              autocomplete: function(before, after, callback) {
+                callback([
+                  {
+                    meta: "file",
+                    score: 1000,
+                    value: "file_one"
+                  },
+                  {
+                    meta: "dir",
+                    score: 999,
+                    value: "folder_one"
+                  }
+                ])
+              }
+            },
+            snippet: snippet
+          });
+        });
+
+        it("should autocomplete hdfs paths in location references without initial /", function () {
+          assertAutoComplete({
+            serverResponses: {},
+            beforeCursor: "LOAD DATA INPATH '",
+            afterCursor: "'",
+            expectedSuggestions: ["/file_one", "/folder_one/"]
+          });
+        });
+
+        it("should autocomplete hdfs paths in location references from root", function () {
+          assertAutoComplete({
+            serverResponses: {},
+            beforeCursor: "LOAD DATA INPATH '/",
+            afterCursor: "'",
+            expectedSuggestions: ["file_one", "folder_one/"]
+          });
+        });
+
+        it("should autocomplete hdfs paths and suggest trailing apostrophe if empty after cursor", function () {
+          assertAutoComplete({
+            serverResponses: {},
+            beforeCursor: "LOAD DATA INPATH '/",
+            afterCursor: "",
+            expectedSuggestions: ["file_one'", "folder_one/"]
+          });
+        });
+
+        it("should autocomplete hdfs paths in location references from inside a path", function () {
+          assertAutoComplete({
+            serverResponses: {},
+            beforeCursor: "LOAD DATA INPATH '/",
+            afterCursor: "/bar' INTO TABLE foo",
+            expectedSuggestions: ["file_one", "folder_one"]
+          });
+        });
+      });
+
       it("should not suggest struct from map values with hive style syntax", function() {
         assertAutoComplete({
           serverResponses: {